Fix string to number deserialization
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -1672,6 +1672,7 @@ dependencies = [
|
|||||||
"reqwest",
|
"reqwest",
|
||||||
"rust-bert",
|
"rust-bert",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde-aux",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_repr",
|
"serde_repr",
|
||||||
"time",
|
"time",
|
||||||
@@ -2008,6 +2009,17 @@ dependencies = [
|
|||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde-aux"
|
||||||
|
version = "4.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a86348501c129f3ad50c2f4635a01971f76974cd8a3f335988a0f1581c082765"
|
||||||
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde-value"
|
name = "serde-value"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
@@ -27,6 +27,7 @@ log4rs = "1.2.0"
|
|||||||
serde = "1.0.188"
|
serde = "1.0.188"
|
||||||
serde_json = "1.0.105"
|
serde_json = "1.0.105"
|
||||||
serde_repr = "0.1.18"
|
serde_repr = "0.1.18"
|
||||||
|
serde-aux = "4.4.0"
|
||||||
futures-util = "0.3.28"
|
futures-util = "0.3.28"
|
||||||
reqwest = { version = "0.11.20", features = [
|
reqwest = { version = "0.11.20", features = [
|
||||||
"json",
|
"json",
|
||||||
|
@@ -48,7 +48,7 @@ pub async fn check_account(config: &Arc<Config>) {
|
|||||||
|
|
||||||
warn!(
|
warn!(
|
||||||
"qrust active with {}{}, avoid transferring funds without shutting down.",
|
"qrust active with {}{}, avoid transferring funds without shutting down.",
|
||||||
account.currency, account.cash
|
account.cash, account.currency
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,6 +2,9 @@ use backoff::{future::retry_notify, ExponentialBackoff};
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
use reqwest::Error;
|
use reqwest::Error;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde_aux::field_attributes::{
|
||||||
|
deserialize_number_from_string, deserialize_option_number_from_string,
|
||||||
|
};
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@@ -25,15 +28,23 @@ pub enum Status {
|
|||||||
pub struct Account {
|
pub struct Account {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
#[serde(rename = "account_number")]
|
#[serde(rename = "account_number")]
|
||||||
pub number: i64,
|
pub number: String,
|
||||||
pub status: Status,
|
pub status: Status,
|
||||||
pub currency: String,
|
pub currency: String,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub cash: f64,
|
pub cash: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub non_marginable_buying_power: f64,
|
pub non_marginable_buying_power: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub accrued_fees: f64,
|
pub accrued_fees: f64,
|
||||||
pub pending_transfer_in: f64,
|
#[serde(default)]
|
||||||
pub pending_transfer_out: f64,
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
|
pub pending_transfer_in: Option<f64>,
|
||||||
|
#[serde(default)]
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
|
pub pending_transfer_out: Option<f64>,
|
||||||
pub pattern_day_trader: bool,
|
pub pattern_day_trader: bool,
|
||||||
|
#[serde(default)]
|
||||||
pub trade_suspend_by_user: bool,
|
pub trade_suspend_by_user: bool,
|
||||||
pub trading_blocked: bool,
|
pub trading_blocked: bool,
|
||||||
pub transfers_blocked: bool,
|
pub transfers_blocked: bool,
|
||||||
@@ -42,18 +53,30 @@ pub struct Account {
|
|||||||
#[serde(with = "time::serde::rfc3339")]
|
#[serde(with = "time::serde::rfc3339")]
|
||||||
pub created_at: OffsetDateTime,
|
pub created_at: OffsetDateTime,
|
||||||
pub shorting_enabled: bool,
|
pub shorting_enabled: bool,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub long_market_value: f64,
|
pub long_market_value: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub short_market_value: f64,
|
pub short_market_value: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub equity: f64,
|
pub equity: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub last_equity: f64,
|
pub last_equity: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub multiplier: i8,
|
pub multiplier: i8,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub buying_power: f64,
|
pub buying_power: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub initial_margin: f64,
|
pub initial_margin: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub maintenance_margin: f64,
|
pub maintenance_margin: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub sma: f64,
|
pub sma: f64,
|
||||||
pub daytrade_count: i64,
|
pub daytrade_count: i64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub last_maintenance_margin: f64,
|
pub last_maintenance_margin: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub daytrading_buying_power: f64,
|
pub daytrading_buying_power: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub regt_buying_power: f64,
|
pub regt_buying_power: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,7 @@ use backoff::{future::retry_notify, ExponentialBackoff};
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
use reqwest::Error;
|
use reqwest::Error;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde_aux::field_attributes::deserialize_option_number_from_string;
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ pub struct Asset {
|
|||||||
pub shortable: bool,
|
pub shortable: bool,
|
||||||
pub easy_to_borrow: bool,
|
pub easy_to_borrow: bool,
|
||||||
pub fractionable: bool,
|
pub fractionable: bool,
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
pub maintenance_margin_requirement: Option<f32>,
|
pub maintenance_margin_requirement: Option<f32>,
|
||||||
pub attributes: Option<Vec<String>>,
|
pub attributes: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ use crate::{
|
|||||||
use backoff::{future::retry_notify, ExponentialBackoff};
|
use backoff::{future::retry_notify, ExponentialBackoff};
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde_aux::field_attributes::deserialize_number_from_string;
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@@ -35,18 +36,30 @@ pub struct Position {
|
|||||||
pub symbol: String,
|
pub symbol: String,
|
||||||
pub exchange: Exchange,
|
pub exchange: Exchange,
|
||||||
pub asset_class: Class,
|
pub asset_class: Class,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub avg_entry_price: f64,
|
pub avg_entry_price: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub qty: f64,
|
pub qty: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub qty_available: f64,
|
pub qty_available: f64,
|
||||||
pub side: Side,
|
pub side: Side,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub market_value: f64,
|
pub market_value: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub cost_basis: f64,
|
pub cost_basis: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub unrealized_pl: f64,
|
pub unrealized_pl: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub unrealized_plpc: f64,
|
pub unrealized_plpc: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub unrealized_intraday_pl: f64,
|
pub unrealized_intraday_pl: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub unrealized_intraday_plpc: f64,
|
pub unrealized_intraday_plpc: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub current_price: f64,
|
pub current_price: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub lastday_price: f64,
|
pub lastday_price: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub change_today: f64,
|
pub change_today: f64,
|
||||||
pub asset_marginable: bool,
|
pub asset_marginable: bool,
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
use crate::{impl_from_enum, types};
|
use crate::{impl_from_enum, types};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_aux::field_attributes::{
|
||||||
|
deserialize_number_from_string, deserialize_option_number_from_string,
|
||||||
|
};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@@ -136,21 +139,29 @@ pub struct Order {
|
|||||||
pub asset_id: Uuid,
|
pub asset_id: Uuid,
|
||||||
pub symbol: String,
|
pub symbol: String,
|
||||||
pub asset_class: super::asset::Class,
|
pub asset_class: super::asset::Class,
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
pub notional: Option<f64>,
|
pub notional: Option<f64>,
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
pub qty: Option<f64>,
|
pub qty: Option<f64>,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
pub filled_qty: f64,
|
pub filled_qty: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
pub filled_avg_price: Option<f64>,
|
pub filled_avg_price: Option<f64>,
|
||||||
pub order_class: Class,
|
pub order_class: Class,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub order_type: Type,
|
pub order_type: Type,
|
||||||
pub side: Side,
|
pub side: Side,
|
||||||
pub time_in_force: TimeInForce,
|
pub time_in_force: TimeInForce,
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
pub limit_price: Option<f64>,
|
pub limit_price: Option<f64>,
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
pub stop_price: Option<f64>,
|
pub stop_price: Option<f64>,
|
||||||
pub status: Status,
|
pub status: Status,
|
||||||
pub extended_hours: bool,
|
pub extended_hours: bool,
|
||||||
pub legs: Option<Vec<Order>>,
|
pub legs: Option<Vec<Order>>,
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
pub trail_percent: Option<f64>,
|
pub trail_percent: Option<f64>,
|
||||||
|
#[serde(deserialize_with = "deserialize_option_number_from_string")]
|
||||||
pub trail_price: Option<f64>,
|
pub trail_price: Option<f64>,
|
||||||
pub hwm: Option<f64>,
|
pub hwm: Option<f64>,
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
use crate::types::alpaca::shared;
|
use crate::types::alpaca::shared;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde_aux::prelude::deserialize_number_from_string;
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@@ -12,12 +13,16 @@ pub enum Event {
|
|||||||
New,
|
New,
|
||||||
Fill {
|
Fill {
|
||||||
timestamp: OffsetDateTime,
|
timestamp: OffsetDateTime,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
position_qty: f64,
|
position_qty: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
price: f64,
|
price: f64,
|
||||||
},
|
},
|
||||||
PartialFill {
|
PartialFill {
|
||||||
timestamp: OffsetDateTime,
|
timestamp: OffsetDateTime,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
position_qty: f64,
|
position_qty: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
||||||
price: f64,
|
price: f64,
|
||||||
},
|
},
|
||||||
Canceled {
|
Canceled {
|
||||||
|
Reference in New Issue
Block a user