Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds some updates to OrderTradeEvent struct #126

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions src/model.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Clone)]
pub struct Empty { }
pub struct Empty {}

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -223,10 +223,7 @@ pub struct Bids {

impl Bids {
pub fn new(price: f64, qty: f64) -> Bids {
Bids {
price,
qty,
}
Bids { price, qty }
}
}

Expand Down Expand Up @@ -389,7 +386,7 @@ pub struct OrderTradeEvent {
pub symbol: String,

#[serde(rename = "c")]
pub new_client_order_id: String,
pub client_order_id: String,

#[serde(rename = "S")]
pub side: String,
Expand All @@ -400,11 +397,11 @@ pub struct OrderTradeEvent {
#[serde(rename = "f")]
pub time_in_force: String,

#[serde(rename = "q")]
pub qty: String,
#[serde(rename = "q", with = "string_or_float")]
pub qty: f64,

#[serde(rename = "p")]
pub price: String,
#[serde(rename = "p", with = "string_or_float")]
pub price: f64,

#[serde(skip, rename = "P")]
pub p_ignore: String,
Expand All @@ -430,20 +427,23 @@ pub struct OrderTradeEvent {
#[serde(rename = "i")]
pub order_id: u64,

#[serde(rename = "l")]
pub qty_last_filled_trade: String,
#[serde(rename = "l", with = "string_or_float")]
pub qty_last_filled_trade: f64,

#[serde(rename = "z")]
pub accumulated_qty_filled_trades: String,
#[serde(rename = "z", with = "string_or_float")]
pub cumulative_filled_qty: f64,

#[serde(rename = "L")]
pub price_last_filled_trade: String,
#[serde(rename = "Z", with = "string_or_float")]
pub cumulative_quote_transacted_qty: f64,

#[serde(rename = "n")]
pub commission: String,
#[serde(rename = "L", with = "string_or_float")]
pub price_last_filled_trade: f64,

#[serde(skip, rename = "N")]
pub asset_commisioned: Option<String>,
#[serde(rename = "n", with = "string_or_float")]
pub commission: f64,

#[serde(rename = "N")]
pub commission_asset: Option<String>,

#[serde(rename = "T")]
pub trade_order_time: u64,
Expand Down Expand Up @@ -566,7 +566,6 @@ pub struct IndexPriceEvent {

#[serde(rename = "p")]
pub price: String,

}
// https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream
// https://binance-docs.github.io/apidocs/delivery/en/#mark-price-stream
Expand Down Expand Up @@ -598,7 +597,6 @@ pub struct MarkPriceEvent {
pub symbol: String,
}


// Object({"E": Number(1626118018407), "e": String("forceOrder"), "o": Object({"S": String("SELL"), "T": Number(1626118018404), "X": String("FILLED"), "ap": String("33028.07"), "f": String("IOC"), "l": String("0.010"), "o": String("LIMIT"), "p": String("32896.00"), "q": String("0.010"), "s": String("BTCUSDT"), "z": String("0.010")})})
// https://binance-docs.github.io/apidocs/futures/en/#liquidation-order-streams

Expand All @@ -613,7 +611,6 @@ pub struct LiquidationEvent {

#[serde(rename = "o")]
pub liquidation_order: LiquidationOrder,

}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -779,7 +776,6 @@ pub struct MiniTickerEvent {
pub quote_volume: String,
}


#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct KlineEvent {
Expand Down Expand Up @@ -817,7 +813,6 @@ pub struct ContinuousKlineEvent {
pub kline: ContinuousKline,
}


// https://binance-docs.github.io/apidocs/delivery/en/#index-kline-candlestick-streams

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -869,7 +864,7 @@ pub struct Kline {

#[serde(rename = "T")]
pub end_time: i64,

#[serde(rename = "s")]
pub symbol: String,

Expand Down Expand Up @@ -1165,7 +1160,7 @@ pub(crate) mod string_or_float {
} else {
s.parse().map_err(de::Error::custom)
}
},
}
StringOrFloat::Float(i) => Ok(i),
}
}
Expand All @@ -1183,7 +1178,7 @@ pub(crate) mod string_or_float_opt {
{
match value {
Some(v) => crate::model::string_or_float::serialize(v, serializer),
None => serializer.serialize_none()
None => serializer.serialize_none(),
}
}

Expand All @@ -1198,7 +1193,9 @@ pub(crate) mod string_or_float_opt {
Float(f64),
}

Ok(Some(crate::model::string_or_float::deserialize(deserializer)?))
Ok(Some(crate::model::string_or_float::deserialize(
deserializer,
)?))
}
}

Expand All @@ -1208,16 +1205,16 @@ pub(crate) mod string_or_bool {
use serde::{de, Serializer, Deserialize, Deserializer};

pub fn serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: fmt::Display,
S: Serializer,
where
T: fmt::Display,
S: Serializer,
{
serializer.collect_str(value)
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<bool, D::Error>
where
D: Deserializer<'de>,
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(untagged)]
Expand Down