| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- use serde_json::Value;
- use tokio::time::Instant;
- /**交易所返回数据处理之后,同意保存格式,为了内部其他接口调用*/
- #[derive(Debug, Clone)]
- pub struct ResponseData {
- pub label: String,
- pub code: i16,
- pub message: String,
- pub channel: String,
- pub data: Value,
- pub ins: Instant, // 数据接收的ins
- pub time: i64, // 数据接受的时间
- pub reach_time: i64, // 远程数据时间 弃用
- pub data_type: String // 數據類型, 例如 bybit 深度信息:snapshot(全量),delta(增量)
- }
- impl ResponseData {
- pub fn new(label: String, code: i16, message: String, data: Value) -> ResponseData {
- ResponseData {
- label,
- code,
- message,
- data,
- channel: "".to_string(),
- time: 0,
- reach_time: 0,
- data_type: String::new(),
- ins: Instant::now(),
- }
- }
- pub fn error(label: String, message: String) -> ResponseData {
- ResponseData {
- label,
- code: -1,
- message: format!("{}", &message),
- data: Value::Null,
- channel: "".to_string(),
- time: 0,
- reach_time: 0,
- data_type: String::new(),
- ins: Instant::now(),
- }
- }
- pub fn to_string(&self) -> String {
- format!("{:?}", self)
- }
- }
|