response_base.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**交易所返回数据处理之后,同意保存格式,为了内部其他接口调用*/
  2. #[derive(Debug, Clone)]
  3. pub struct ResponseData {
  4. pub label: String,
  5. pub code: String,
  6. pub message: String,
  7. pub channel: String,
  8. pub data: String,
  9. pub time: i64, //数据接受的时间
  10. pub reach_time: i64, //远程数据时间 弃用
  11. pub data_type: String // 數據類型, 例如 bybit 深度信息:snapshot(全量),delta(增量)
  12. }
  13. impl ResponseData {
  14. pub fn new(label: String, code: String, message: String, data: String) -> ResponseData {
  15. ResponseData { label, code, message, data, channel: "".to_string(), time: 0, reach_time: 0 , data_type: String::new()}
  16. }
  17. pub fn error(label: String, message: String) -> ResponseData {
  18. ResponseData {
  19. label,
  20. code: "-1".to_string(),
  21. message: format!("{}", &message),
  22. data: "".to_string(),
  23. channel: "".to_string(),
  24. time: 0,
  25. reach_time: 0,
  26. data_type: String::new()
  27. }
  28. }
  29. pub fn to_string(&self) -> String {
  30. format!("{:?}", self)
  31. }
  32. }