|
@@ -1,15 +1,18 @@
|
|
|
use std::cmp::{max, min};
|
|
use std::cmp::{max, min};
|
|
|
use std::collections::HashMap;
|
|
use std::collections::HashMap;
|
|
|
use std::ops::{Div, Mul};
|
|
use std::ops::{Div, Mul};
|
|
|
|
|
+use std::str::FromStr;
|
|
|
use chrono::Utc;
|
|
use chrono::Utc;
|
|
|
use rust_decimal::Decimal;
|
|
use rust_decimal::Decimal;
|
|
|
use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
|
|
use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
|
|
|
use rust_decimal_macros::dec;
|
|
use rust_decimal_macros::dec;
|
|
|
-use crate::model::{LocalPosition, OrderInfo, TraderMsg};
|
|
|
|
|
|
|
+use crate::model::{DealRecord, LocalPosition, OrderInfo, TraderMsg};
|
|
|
use crate::utils;
|
|
use crate::utils;
|
|
|
use tracing::{info, error, warn, instrument};
|
|
use tracing::{info, error, warn, instrument};
|
|
|
|
|
+use reqwest::{Client};
|
|
|
|
|
+use tokio::spawn;
|
|
|
use global::params::Params;
|
|
use global::params::Params;
|
|
|
-use standard::OrderCommand;
|
|
|
|
|
|
|
+use standard::{OrderCommand};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
|
pub struct Strategy {
|
|
pub struct Strategy {
|
|
@@ -1222,10 +1225,71 @@ impl Strategy {
|
|
|
self._refresh_request_limit(); // 刷新频率限制
|
|
self._refresh_request_limit(); // 刷新频率限制
|
|
|
self._update_request_num(&mut command); // 统计刷新频率
|
|
self._update_request_num(&mut command); // 统计刷新频率
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if command.limits_open.len() > 0 || command.limits_close.len() > 0{
|
|
|
|
|
+ let time = chrono::Utc::now().timestamp_millis();
|
|
|
|
|
+ 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 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;
|
|
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());
|
|
|
|
|
+
|
|
|
|
|
+ let response = req.send().await.unwrap();
|
|
|
|
|
+ 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,
|
|
|
|
|
+ regPrice: price,
|
|
|
|
|
+ num: amount,
|
|
|
|
|
+ triggerTime: time,
|
|
|
|
|
+ robotName: robot_name.clone(),
|
|
|
|
|
+ side: side.to_string(),
|
|
|
|
|
+ };
|
|
|
|
|
+ list.push(deal_recode);
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
mod tests {
|
|
|
use rust_decimal::Decimal;
|
|
use rust_decimal::Decimal;
|