use super::callback::Arg;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct OpResponse<'a> {
pub success: bool,
pub ret_msg: &'a str,
pub conn_id: &'a str,
pub req_id: Option<&'a str>,
pub op: &'a str,
}
#[derive(Deserialize, Debug)]
pub struct OptionPongResponse<'a> {
pub args: [&'a str; 1],
pub op: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct OptionSubscriptionData<'a> {
#[serde(borrow)]
pub fail_topics: Vec<&'a str>,
pub success_topics: Vec<&'a str>,
}
#[derive(Deserialize, Debug)]
pub struct OptionSubscriptionResponse<'a> {
pub success: bool,
pub conn_id: &'a str,
pub data: OptionSubscriptionData<'a>,
#[serde(alias = "type")]
pub type_: &'a str,
}
#[derive(Deserialize, Debug)]
pub struct PrivatePongResponse<'a> {
pub req_id: Option<&'a str>,
pub op: &'a str,
pub args: [&'a str; 1],
pub conn_id: &'a str,
}
#[derive(Deserialize, Debug)]
pub struct BasePublicResponse<'a, Data> {
pub topic: &'a str,
#[serde(alias = "type")]
pub type_: &'a str,
pub ts: u64,
pub data: Data,
}
#[derive(Deserialize, Debug)]
pub struct BaseTickerPublicResponse<'a, Data> {
pub topic: &'a str,
#[serde(alias = "type")]
pub type_: &'a str,
pub cs: u64,
pub ts: u64,
pub data: Data,
}
#[derive(Deserialize, Debug)]
pub struct BaseOptionPublicResponse<'a, Data> {
pub id: &'a str,
pub topic: &'a str,
#[serde(alias = "type")]
pub type_: &'a str,
pub ts: u64,
pub data: Data,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct BasePrivateResponse<'a, Data> {
pub id: &'a str,
pub topic: &'a str,
pub creation_time: u64,
pub data: Data,
}
#[derive(Deserialize, Debug)]
pub struct OrderbookItem<'a>(pub &'a str, pub &'a str);
#[derive(Deserialize, Debug)]
pub struct Orderbook<'a> {
pub s: &'a str,
pub b: Vec<OrderbookItem<'a>>,
pub a: Vec<OrderbookItem<'a>>,
pub u: u64,
pub seq: Option<u64>,
}
#[allow(non_snake_case)]
#[derive(Deserialize, Debug)]
pub struct Trade<'a> {
pub T: u64,
pub s: &'a str,
pub S: &'a str,
pub v: &'a str,
pub p: &'a str,
pub L: Option<&'a str>,
pub i: &'a str,
pub BT: bool,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct SpotTicker<'a> {
pub symbol: &'a str,
pub last_price: &'a str,
pub high_price_24h: &'a str,
pub low_price_24h: &'a str,
pub prev_price_24h: &'a str,
pub volume_24h: &'a str,
pub turnover_24h: &'a str,
pub price_24h_pcnt: &'a str,
pub usd_index_price: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct OptionTicker<'a> {
pub symbol: &'a str,
pub bid_price: &'a str,
pub bid_size: &'a str,
pub bid_iv: &'a str,
pub ask_price: &'a str,
pub ask_size: &'a str,
pub ask_iv: &'a str,
pub last_price: &'a str,
pub high_price_24h: &'a str,
pub low_price_24h: &'a str,
pub mark_price: &'a str,
pub index_price: &'a str,
pub mark_price_iv: &'a str,
pub underlying_price: &'a str,
pub open_interest: &'a str,
pub turnover_24h: &'a str,
pub volume_24h: &'a str,
pub total_volume: &'a str,
pub total_turnover: &'a str,
pub delta: &'a str,
pub gamma: &'a str,
pub vega: &'a str,
pub theta: &'a str,
pub predicted_delivery_price: &'a str,
pub change_24h: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FutureTicker<'a> {
pub symbol: &'a str,
pub tick_direction: Option<&'a str>,
pub price_24h_pcnt: Option<&'a str>,
pub last_price: Option<&'a str>,
pub prev_price_24h: Option<&'a str>,
pub high_price_24h: Option<&'a str>,
pub low_price_24h: Option<&'a str>,
pub prev_price_1h: Option<&'a str>,
pub mark_price: Option<&'a str>,
pub index_price: Option<&'a str>,
pub open_interest: Option<&'a str>,
pub open_interest_value: Option<&'a str>,
pub turnover_24h: Option<&'a str>,
pub volume_24h: Option<&'a str>,
pub next_funding_time: Option<&'a str>,
pub funding_rate: Option<&'a str>,
pub bid1_price: Option<&'a str>,
pub bid1_size: Option<&'a str>,
pub ask1_price: Option<&'a str>,
pub ask1_size: Option<&'a str>,
pub delivery_time: Option<&'a str>,
pub basis_rate: Option<&'a str>,
pub delivery_fee_rate: Option<&'a str>,
pub predicted_delivery_price: Option<&'a str>,
}
#[derive(Deserialize, Debug)]
pub struct Kline<'a> {
pub start: u64,
pub end: u64,
pub interval: &'a str,
pub open: &'a str,
pub close: &'a str,
pub high: &'a str,
pub low: &'a str,
pub volume: Option<&'a str>,
pub turnover: Option<&'a str>,
pub confirm: bool,
pub timestamp: u64,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Liquidation<'a> {
pub updated_time: u64,
pub symbol: &'a str,
pub side: &'a str,
pub size: &'a str,
pub price: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct LtTicker<'a> {
pub symbol: &'a str,
pub price_24h_pcnt: &'a str,
pub last_price: &'a str,
pub prev_price_24h: &'a str,
pub high_price_24h: &'a str,
pub low_price24h: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct LtNav<'a> {
pub time: u64,
pub symbol: &'a str,
pub nav: &'a str,
pub basket_position: &'a str,
pub leverage: &'a str,
pub basket_loan: &'a str,
pub circulation: &'a str,
pub basket: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Position<'a> {
pub category: Option<&'a str>,
pub symbol: &'a str,
pub side: &'a str,
pub size: &'a str,
pub position_idx: u8,
pub trade_mode: u8,
pub position_value: &'a str,
pub risk_id: u16,
pub risk_limit_value: &'a str,
pub entry_price: &'a str,
pub mark_price: &'a str,
pub leverage: &'a str,
pub position_balance: Option<&'a str>,
pub auto_add_margin: Option<u8>,
#[serde(alias = "positionMM")]
pub position_mm: &'a str,
#[serde(alias = "positionIM")]
pub position_im: &'a str,
pub liq_price: &'a str,
pub bust_price: &'a str,
pub tpsl_mode: &'a str,
pub take_profit: &'a str,
pub stop_loss: &'a str,
pub trailing_stop: &'a str,
pub unrealised_pnl: &'a str,
pub cum_realised_pnl: &'a str,
pub position_status: &'a str,
pub created_time: &'a str,
pub updated_time: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Execution<'a> {
pub category: &'a str,
pub symbol: &'a str,
pub is_leverage: &'a str,
pub order_id: &'a str,
pub order_link_id: &'a str,
pub side: &'a str,
pub order_price: &'a str,
pub order_qty: &'a str,
pub leaves_qty: &'a str,
pub order_type: &'a str,
pub stop_order_type: &'a str,
pub exec_fee: &'a str,
pub exec_id: &'a str,
pub exec_price: &'a str,
pub exec_qty: &'a str,
pub exec_type: &'a str,
pub exec_value: &'a str,
pub exec_time: &'a str,
pub is_maker: bool,
pub fee_rate: &'a str,
pub trade_iv: &'a str,
pub mark_iv: &'a str,
pub mark_price: &'a str,
pub index_price: &'a str,
pub underlying_price: &'a str,
pub block_trade_id: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Order<'a> {
pub category: &'a str,
pub order_id: &'a str,
pub order_link_id: &'a str,
pub is_leverage: &'a str,
pub block_trade_id: &'a str,
pub symbol: &'a str,
pub price: &'a str,
pub qty: &'a str,
pub side: &'a str,
pub position_idx: u8,
pub order_status: &'a str,
pub cancel_type: &'a str,
pub reject_reason: &'a str,
pub avg_price: &'a str,
pub leaves_qty: &'a str,
pub leaves_value: &'a str,
pub cum_exec_qty: &'a str,
pub cum_exec_value: &'a str,
pub cum_exec_fee: &'a str,
pub time_in_force: &'a str,
pub order_type: &'a str,
pub stop_order_type: &'a str,
pub order_iv: &'a str,
pub trigger_price: &'a str,
pub take_profit: &'a str,
pub stop_loss: &'a str,
pub tp_trigger_by: &'a str,
pub sl_trigger_by: &'a str,
pub trigger_direction: u8,
pub trigger_by: &'a str,
pub last_price_on_created: &'a str,
pub reduce_only: bool,
pub close_on_trigger: bool,
pub created_time: &'a str,
pub updated_time: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct WalletCoin<'a> {
pub coin: &'a str,
pub equity: &'a str,
pub usd_value: &'a str,
pub wallet_balance: &'a str,
pub borrow_amount: &'a str,
pub available_to_borrow: &'a str,
pub available_to_withdraw: &'a str,
pub accrued_interest: &'a str,
#[serde(alias = "totalOrderIM")]
pub total_order_im: &'a str,
#[serde(alias = "totalPositionIM")]
pub total_position_im: &'a str,
#[serde(alias = "totalPositionMM")]
pub total_position_mm: &'a str,
pub unrealised_pnl: &'a str,
pub cum_realised_pnl: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Wallet<'a> {
pub account_type: &'a str,
#[serde(alias = "accountIMRate")]
pub account_im_rate: &'a str,
#[serde(alias = "accountMMRate")]
pub account_mm_rate: &'a str,
pub total_equity: &'a str,
pub total_wallet_balance: &'a str,
pub total_margin_balance: &'a str,
pub total_available_balance: &'a str,
#[serde(alias = "totalPerpUPL")]
pub total_perp_upl: &'a str,
pub total_initial_margin: &'a str,
pub total_maintenance_margin: &'a str,
pub coin: Vec<WalletCoin<'a>>,
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Greek<'a> {
pub base_coin: &'a str,
pub total_delta: &'a str,
pub total_gamma: &'a str,
pub total_vega: &'a str,
pub total_theta: &'a str,
}
#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum SpotPublicResponse<'a> {
#[serde(borrow)]
Orderbook(BasePublicResponse<'a, Orderbook<'a>>),
Trade(BasePublicResponse<'a, Vec<Trade<'a>>>),
Ticker(BaseTickerPublicResponse<'a, SpotTicker<'a>>),
Kline(BasePublicResponse<'a, Vec<Kline<'a>>>),
LtTicker(BasePublicResponse<'a, LtTicker<'a>>),
LtNav(BasePublicResponse<'a, LtNav<'a>>),
Op(OpResponse<'a>),
}
pub struct SpotPublicResponseArg;
impl Arg for SpotPublicResponseArg {
type ValueType<'a> = SpotPublicResponse<'a>;
}
#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum FuturePublicResponse<'a> {
#[serde(borrow)]
Orderbook(BasePublicResponse<'a, Orderbook<'a>>),
Trade(BasePublicResponse<'a, Vec<Trade<'a>>>),
Ticker(BaseTickerPublicResponse<'a, FutureTicker<'a>>),
Kline(BasePublicResponse<'a, Vec<Kline<'a>>>),
Liquidation(BasePublicResponse<'a, Liquidation<'a>>),
Op(OpResponse<'a>),
}
pub struct FuturePublicResponseArg;
impl Arg for FuturePublicResponseArg {
type ValueType<'a> = FuturePublicResponse<'a>;
}
#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum OptionPublicResponse<'a> {
#[serde(borrow)]
Orderbook(BaseOptionPublicResponse<'a, Orderbook<'a>>),
Trade(BaseOptionPublicResponse<'a, Vec<Trade<'a>>>),
Ticker(BaseOptionPublicResponse<'a, OptionTicker<'a>>),
Pong(OptionPongResponse<'a>),
Subscription(OptionSubscriptionResponse<'a>),
}
pub struct OptionPublicResponseArg;
impl Arg for OptionPublicResponseArg {
type ValueType<'a> = OptionPublicResponse<'a>;
}
#[derive(Deserialize, Debug)]
#[serde(untagged)]
pub enum PrivateResponse<'a> {
#[serde(borrow)]
Position(BasePrivateResponse<'a, Vec<Position<'a>>>),
Execution(BasePrivateResponse<'a, Vec<Execution<'a>>>),
Order(BasePrivateResponse<'a, Vec<Order<'a>>>),
Wallet(BasePrivateResponse<'a, Vec<Wallet<'a>>>),
Greek(BasePrivateResponse<'a, Vec<Greek<'a>>>),
Pong(PrivatePongResponse<'a>),
Op(OpResponse<'a>),
}
pub struct PrivateResponseArg;
impl Arg for PrivateResponseArg {
type ValueType<'a> = PrivateResponse<'a>;
}