|
@@ -3,10 +3,12 @@ use std::sync::Arc;
|
|
|
use chrono::{Utc};
|
|
use chrono::{Utc};
|
|
|
use futures_channel::mpsc::UnboundedSender;
|
|
use futures_channel::mpsc::UnboundedSender;
|
|
|
use futures_util::StreamExt;
|
|
use futures_util::StreamExt;
|
|
|
|
|
+use reqwest::Client;
|
|
|
use rust_decimal::prelude::*;
|
|
use rust_decimal::prelude::*;
|
|
|
use rust_decimal_macros::dec;
|
|
use rust_decimal_macros::dec;
|
|
|
|
|
+use serde_json::{json, Value};
|
|
|
use tokio::sync::{Mutex};
|
|
use tokio::sync::{Mutex};
|
|
|
-use tracing::{info};
|
|
|
|
|
|
|
+use tracing::{error, info};
|
|
|
use global::cci::CentralControlInfo;
|
|
use global::cci::CentralControlInfo;
|
|
|
use global::fixed_time_range_deque::FixedTimeRangeDeque;
|
|
use global::fixed_time_range_deque::FixedTimeRangeDeque;
|
|
|
use global::params::Params;
|
|
use global::params::Params;
|
|
@@ -49,6 +51,7 @@ pub struct Predictor {
|
|
|
pub prev_insert_time: Decimal,
|
|
pub prev_insert_time: Decimal,
|
|
|
pub prev_save_time: Decimal,
|
|
pub prev_save_time: Decimal,
|
|
|
pub init_time: Decimal,
|
|
pub init_time: Decimal,
|
|
|
|
|
+ pub prev_update_open_params_time: Decimal,
|
|
|
|
|
|
|
|
pub params: Params,
|
|
pub params: Params,
|
|
|
|
|
|
|
@@ -146,6 +149,7 @@ impl Predictor {
|
|
|
prev_save_time: Decimal::from(Utc::now().timestamp_millis()),
|
|
prev_save_time: Decimal::from(Utc::now().timestamp_millis()),
|
|
|
init_time: Decimal::from(Utc::now().timestamp_millis()),
|
|
init_time: Decimal::from(Utc::now().timestamp_millis()),
|
|
|
|
|
|
|
|
|
|
+ prev_update_open_params_time: Default::default(),
|
|
|
params,
|
|
params,
|
|
|
|
|
|
|
|
debug_sender: tx,
|
|
debug_sender: tx,
|
|
@@ -267,11 +271,19 @@ impl Predictor {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pub fn update_delta(&mut self) {
|
|
|
|
|
|
|
+ pub async fn update_delta(&mut self) {
|
|
|
if self.mid_price.is_zero() {
|
|
if self.mid_price.is_zero() {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ let now = Decimal::from(Utc::now().timestamp_millis());
|
|
|
|
|
+
|
|
|
|
|
+ if now - self.prev_update_open_params_time > dec!(60_000) {
|
|
|
|
|
+ self.update_open_params().await;
|
|
|
|
|
+
|
|
|
|
|
+ self.prev_update_open_params_time = now;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
for fair_price in &self.fair_price_vec {
|
|
for fair_price in &self.fair_price_vec {
|
|
|
if fair_price.is_zero() {
|
|
if fair_price.is_zero() {
|
|
|
return;
|
|
return;
|
|
@@ -410,4 +422,40 @@ impl Predictor {
|
|
|
pub fn get_ref_price(&mut self, _ref_ticker_map: &BTreeMap<String, Ticker>) -> Vec<Vec<Decimal>> {
|
|
pub fn get_ref_price(&mut self, _ref_ticker_map: &BTreeMap<String, Ticker>) -> Vec<Vec<Decimal>> {
|
|
|
vec![]
|
|
vec![]
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ pub async fn update_open_params(&mut self) {
|
|
|
|
|
+ let url = "http://is.skyfffire.com:18888/ia/get_indicator";
|
|
|
|
|
+ let symbol = self.params.pair.to_lowercase();
|
|
|
|
|
+ let exchange = self.params.exchange.to_lowercase();
|
|
|
|
|
+
|
|
|
|
|
+ let params = json!({
|
|
|
|
|
+ "indicator": "msv",
|
|
|
|
|
+ "query": {
|
|
|
|
|
+ "exchange": exchange,
|
|
|
|
|
+ "symbol": symbol,
|
|
|
|
|
+ "minute_time_range": "10",
|
|
|
|
|
+ "mills_back": "37"
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 创建 HTTP 客户端
|
|
|
|
|
+ let client = Client::new();
|
|
|
|
|
+
|
|
|
|
|
+ // 发送 GET 请求
|
|
|
|
|
+ let response = client.post(url)
|
|
|
|
|
+ .json(¶ms)
|
|
|
|
|
+ .send()
|
|
|
|
|
+ .await
|
|
|
|
|
+ .unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ // 错误处理
|
|
|
|
|
+ if response.status().is_success() {
|
|
|
|
|
+ let response_text = response.text().await.unwrap();
|
|
|
|
|
+ let parsed: Value = serde_json::from_str(response_text.as_str()).unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ info!("parsed={}", parsed.to_string());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ error!("自动参数挂了:{}", response.status());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|