|
|
@@ -1,23 +1,55 @@
|
|
|
-use rust_decimal::Decimal;
|
|
|
+use std::io::{Error, ErrorKind};
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
use crate::robot_data::robot_data_rest::get_robot_info;
|
|
|
+use crate::struct_standard::Trades;
|
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
struct RobotInfo {
|
|
|
+ #[serde(rename = "ref")]
|
|
|
+ ref_price: Vec<RefPrice>,
|
|
|
+ #[serde(rename = "reg")]
|
|
|
+ reg_price: Vec<RegPrice>,
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(Debug, Deserialize, Serialize)]
|
|
|
+#[serde(rename_all = "camelCase")]
|
|
|
+struct RefPrice {
|
|
|
+ id: i64,
|
|
|
+ ref_price: String,
|
|
|
+ num: String,
|
|
|
+ trigger_time: String,
|
|
|
+ robot_name: String,
|
|
|
+ side: String,
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(Debug, Deserialize, Serialize)]
|
|
|
+#[serde(rename_all = "camelCase")]
|
|
|
+struct RegPrice {
|
|
|
id: i64,
|
|
|
- ref_price: Decimal,
|
|
|
- reg_price: Decimal,
|
|
|
- num: Decimal,
|
|
|
- trigger_time: Decimal,
|
|
|
+ reg_price: String,
|
|
|
+ num: String,
|
|
|
+ trigger_time: String,
|
|
|
robot_name: String,
|
|
|
side: String,
|
|
|
}
|
|
|
|
|
|
-pub async fn standard_robot_info(robot_name: &str, start_at: &str, end_at: &str) {
|
|
|
+pub async fn standard_robot_info(robot_name: &str, start_at: &str, end_at: &str) -> Result<Vec<Trades>, Error> {
|
|
|
let res_data = get_robot_info(robot_name, start_at, end_at).await;
|
|
|
if res_data.code == "200" {
|
|
|
- let robot_info: Vec<RobotInfo> = serde_json::from_str(&res_data.data).unwrap();
|
|
|
- println!("{:?}", robot_info);
|
|
|
+ let robot_info: RobotInfo = serde_json::from_str(&res_data.data).unwrap();
|
|
|
+ let result = robot_info.ref_price.iter().map(|item| {
|
|
|
+ Trades {
|
|
|
+ id: item.id.to_string(),
|
|
|
+ data_type: "robot".to_string(),
|
|
|
+ symbol: "".to_string(),
|
|
|
+ create_time: item.trigger_time.clone(),
|
|
|
+ size: item.num.clone(),
|
|
|
+ price: item.ref_price.clone(),
|
|
|
+ }
|
|
|
+ }).collect();
|
|
|
+ Ok(result)
|
|
|
+ } else {
|
|
|
+ Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
}
|
|
|
}
|