|
|
@@ -1,16 +1,16 @@
|
|
|
use std::cmp::{max, min};
|
|
|
use std::collections::HashMap;
|
|
|
use std::ops::{Div, Mul};
|
|
|
-use std::str::FromStr;
|
|
|
+// use std::str::FromStr;
|
|
|
use chrono::Utc;
|
|
|
use rust_decimal::Decimal;
|
|
|
use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
|
|
|
use rust_decimal_macros::dec;
|
|
|
-use crate::model::{DealRecord, LocalPosition, OrderInfo};
|
|
|
+use crate::model::{LocalPosition, OrderInfo};
|
|
|
use crate::utils;
|
|
|
use tracing::{info, error, warn};
|
|
|
-use reqwest::{Client};
|
|
|
-use tokio::spawn;
|
|
|
+// use reqwest::{Client};
|
|
|
+// use tokio::spawn;
|
|
|
use tokio::time::Instant;
|
|
|
use global::params::Params;
|
|
|
use standard::{OrderCommand};
|
|
|
@@ -1280,71 +1280,71 @@ impl Strategy {
|
|
|
self._refresh_request_limit(); // 刷新频率限制
|
|
|
self._update_request_num(&mut command); // 统计刷新频率
|
|
|
|
|
|
- if command.limits_open.len() != 0 || command.limits_close.len() != 0 {
|
|
|
- let name = self.params.account_name.clone();
|
|
|
- // 参考卖价
|
|
|
- let ref_ap = self.ref_ap;
|
|
|
- // 参考买价
|
|
|
- let ref_bp = self.ref_bp;
|
|
|
- let limits_open = command.limits_open.clone();
|
|
|
- let limits_close = command.limits_close.clone();
|
|
|
- spawn(async move {
|
|
|
- let time = chrono::Utc::now().timestamp_millis();
|
|
|
- let param_list = paras_limit_command(name.clone(), time.clone(), ref_ap.clone(), ref_bp.clone(), limits_open, limits_close);
|
|
|
- let param_json_obj = serde_json::to_string(¶m_list).unwrap();
|
|
|
- market_warehouse_request(param_json_obj).await;
|
|
|
- });
|
|
|
- }
|
|
|
+ // if command.limits_open.len() != 0 || command.limits_close.len() != 0 {
|
|
|
+ // let name = self.params.account_name.clone();
|
|
|
+ // // 参考卖价
|
|
|
+ // let ref_ap = self.ref_ap;
|
|
|
+ // // 参考买价
|
|
|
+ // let ref_bp = self.ref_bp;
|
|
|
+ // let limits_open = command.limits_open.clone();
|
|
|
+ // let limits_close = command.limits_close.clone();
|
|
|
+ // spawn(async move {
|
|
|
+ // let time = chrono::Utc::now().timestamp_millis();
|
|
|
+ // let param_list = paras_limit_command(name.clone(), time.clone(), ref_ap.clone(), ref_bp.clone(), limits_open, limits_close);
|
|
|
+ // let param_json_obj = serde_json::to_string(¶m_list).unwrap();
|
|
|
+ // market_warehouse_request(param_json_obj).await;
|
|
|
+ // });
|
|
|
+ // }
|
|
|
|
|
|
return command;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async fn market_warehouse_request(body_params: String) {
|
|
|
- /****请求接口与 地址*/
|
|
|
- let url = "http://as.skyfffire.com:8848/basic/saveDealRecords";
|
|
|
-
|
|
|
- let client = Client::new();
|
|
|
- let req = client.post(url).header("auth", "43626546liangjiang")
|
|
|
- .header("Content-Type", "application/json").body(body_params.clone());
|
|
|
-
|
|
|
- match req.send().await {
|
|
|
- Ok(_) => {}
|
|
|
- Err(_) => {}
|
|
|
- };
|
|
|
- // if !response.status().is_success() {
|
|
|
- // error!("行情数据------仓库挂单数据存储失败--------!{}", response.status());
|
|
|
- // error!(body_params);
|
|
|
- // }
|
|
|
-}
|
|
|
-
|
|
|
-fn paras_limit_command (robot_name: String, time: i64, ref_ap: Decimal, ref_bp: Decimal, limits_open: HashMap<String, Vec<String>>, limits_close: HashMap<String, Vec<String>>) -> Vec<DealRecord>{
|
|
|
- let mut limits = HashMap::new();
|
|
|
- limits.extend(limits_open);
|
|
|
- limits.extend(limits_close);
|
|
|
- let mut list: Vec<DealRecord> = Vec::with_capacity(limits.len());
|
|
|
- for item in limits.keys() {
|
|
|
- let item_clone = item.clone();
|
|
|
- let value = limits[&item_clone].clone();
|
|
|
- let amount = Decimal::from_str(value.get(0).unwrap_or(&"0".to_string())).unwrap();
|
|
|
- let side = value.get(1).unwrap();
|
|
|
- let price = Decimal::from_str(value.get(2).unwrap_or(&"0".to_string())).unwrap();
|
|
|
- let mut ref_price = ref_ap;
|
|
|
- if "kd" == side {
|
|
|
- ref_price = ref_bp;
|
|
|
- }
|
|
|
- let deal_recode = DealRecord {
|
|
|
- refPrice: ref_price.to_string(),
|
|
|
- regPrice: price.to_string(),
|
|
|
- num: amount.to_string(),
|
|
|
- triggerTime: time,
|
|
|
- robotName: robot_name.clone(),
|
|
|
- side: side.to_string(),
|
|
|
- };
|
|
|
- list.push(deal_recode);
|
|
|
- }
|
|
|
- return list;
|
|
|
-}
|
|
|
+// async fn market_warehouse_request(body_params: String) {
|
|
|
+// /****请求接口与 地址*/
|
|
|
+// let url = "http://as.skyfffire.com:8848/basic/saveDealRecords";
|
|
|
+//
|
|
|
+// let client = Client::new();
|
|
|
+// let req = client.post(url).header("auth", "43626546liangjiang")
|
|
|
+// .header("Content-Type", "application/json").body(body_params.clone());
|
|
|
+//
|
|
|
+// match req.send().await {
|
|
|
+// Ok(_) => {}
|
|
|
+// Err(_) => {}
|
|
|
+// };
|
|
|
+// // if !response.status().is_success() {
|
|
|
+// // error!("行情数据------仓库挂单数据存储失败--------!{}", response.status());
|
|
|
+// // error!(body_params);
|
|
|
+// // }
|
|
|
+// }
|
|
|
+//
|
|
|
+// fn paras_limit_command (robot_name: String, time: i64, ref_ap: Decimal, ref_bp: Decimal, limits_open: HashMap<String, Vec<String>>, limits_close: HashMap<String, Vec<String>>) -> Vec<DealRecord>{
|
|
|
+// let mut limits = HashMap::new();
|
|
|
+// limits.extend(limits_open);
|
|
|
+// limits.extend(limits_close);
|
|
|
+// let mut list: Vec<DealRecord> = Vec::with_capacity(limits.len());
|
|
|
+// for item in limits.keys() {
|
|
|
+// let item_clone = item.clone();
|
|
|
+// let value = limits[&item_clone].clone();
|
|
|
+// let amount = Decimal::from_str(value.get(0).unwrap_or(&"0".to_string())).unwrap();
|
|
|
+// let side = value.get(1).unwrap();
|
|
|
+// let price = Decimal::from_str(value.get(2).unwrap_or(&"0".to_string())).unwrap();
|
|
|
+// let mut ref_price = ref_ap;
|
|
|
+// if "kd" == side {
|
|
|
+// ref_price = ref_bp;
|
|
|
+// }
|
|
|
+// let deal_recode = DealRecord {
|
|
|
+// refPrice: ref_price.to_string(),
|
|
|
+// regPrice: price.to_string(),
|
|
|
+// num: amount.to_string(),
|
|
|
+// triggerTime: time,
|
|
|
+// robotName: robot_name.clone(),
|
|
|
+// side: side.to_string(),
|
|
|
+// };
|
|
|
+// list.push(deal_recode);
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|