| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- use rust_decimal::Decimal;
- use rust_decimal_macros::dec;
- use serde_derive::{Deserialize, Serialize};
- use tokio::time::Instant;
- use global::trace_stack::TraceStack;
- use standard::Order;
- pub struct TokenParam {
- // 平台币名称
- pub token: String,
- // 最低持有价值(u)
- pub limit_value: Decimal
- }
- #[derive(Debug, Clone, PartialEq, Eq)]
- pub struct LocalPosition {
- // 做多仓位
- pub long_pos: Decimal,
- // 做空仓位
- pub short_pos: Decimal,
- //
- pub long_avg: Decimal,
- //
- pub short_avg: Decimal
- }
- impl LocalPosition {
- pub fn new() -> LocalPosition {
- LocalPosition{
- long_pos: dec!(0),
- short_pos: dec!(0),
- long_avg: dec!(0),
- short_avg: dec!(0),
- }
- }
- }
- // #[derive(Debug, Clone)]
- // pub struct TraderMsg {
- // pub position: LocalPosition,
- // pub cash: Decimal,
- // pub coin: Decimal,
- // pub orders: HashMap<String, OrderInfo>,
- // pub ref_price: Vec<Vec<Decimal>>,
- // pub market: Vec<Decimal>,
- // pub predict: Decimal,
- // pub side: String,
- // }
- // impl TraderMsg {
- // pub fn new() -> TraderMsg {
- // TraderMsg{
- // position: LocalPosition {
- // long_pos: Default::default(),
- // short_pos: Default::default(),
- // long_avg: Default::default(),
- // short_avg: Default::default(),
- // },
- // cash: Default::default(),
- // coin: Default::default(),
- // orders: Default::default(),
- // ref_price: Default::default(),
- // market: vec![],
- // predict: Default::default(),
- // side: "normal".to_string(),
- // }
- // }
- // }
- #[derive(Debug, Clone)]
- pub struct OrderInfo {
- pub symbol: String,
- pub amount: Decimal,
- // 方向 kd kk
- pub side: String,
- // 价格
- pub price: Decimal,
- // 自定义订单号
- pub client_id: String,
- // 实际价格
- pub filled_price: Decimal,
- //
- pub filled: Decimal,
- // 订单号
- pub order_id: String,
- // 时间
- pub local_time: i64,
- // 时间
- pub create_time: i64,
- pub status: String,
- pub fee: Decimal,
- // 追踪体系
- pub trace_stack: TraceStack
- }
- impl OrderInfo {
- pub fn parse_order_to_order_info(order: &mut Order) -> OrderInfo {
- OrderInfo {
- symbol: "".to_string(),
- amount: order.amount.abs(),
- side: "".to_string(),
- price: order.price,
- client_id: order.custom_id.clone(),
- filled_price: order.avg_price,
- filled: order.deal_amount.abs(),
- order_id: order.id.clone(),
- local_time: 0,
- create_time: 0,
- status: order.status.clone(),
- fee: Default::default(),
- trace_stack: TraceStack::new(0, Instant::now()),
- }
- }
- }
- #[derive(Serialize, Deserialize, Clone, Debug)]
- pub struct OriginalTradeBa {
- // 成交价格
- pub p: Decimal,
- // 成交数量
- pub q: Decimal,
- // 成交时间
- #[serde(rename = "T")]
- pub t: Decimal,
- // 买方是否是做市方。如true,则此次成交是一个主动卖出单,否则是一个主动买入单。
- pub m: bool
- }
- #[derive(Serialize, Deserialize)]
- pub struct OriginalTradeGa {
- pub size: Decimal,
- pub price: Decimal
- }
- #[derive(Serialize, Deserialize)]
- pub struct OriginalTradeBy {
- pub v: Decimal,
- pub p: Decimal
- }
- #[derive(Serialize, Deserialize)]
- pub struct OriginalTradeOK {
- // 数量
- pub sz: Decimal,
- // 价格
- pub px: Decimal
- }
- #[allow(non_snake_case)]
- #[derive(Serialize, Deserialize, Debug)]
- pub struct OriginalTicker {
- // 更新ID
- pub u: i64,
- // 买单最优挂单价格
- pub b: Decimal,
- // 买单最优挂单数量
- pub B: Decimal,
- // 卖单最优挂单价格
- pub a: Decimal,
- // 卖单最优挂单数量
- pub A: Decimal
- }
- #[allow(non_snake_case)]
- #[derive(Serialize, Deserialize, Debug)]
- pub struct DealRecord {
- // 参考价
- pub refPrice: String,
- // 挂单价
- pub regPrice: String,
- // 买单最优挂单数量
- pub num: String,
- // 触发时间
- pub triggerTime: i64,
- // 机器名称
- pub robotName: String,
- // 方向
- pub side: String
- }
|