|
@@ -102,7 +102,6 @@ impl Bot {
|
|
|
if q < 1.0 {
|
|
if q < 1.0 {
|
|
|
q = 1.0;
|
|
q = 1.0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// 5.计算gamma值
|
|
// 5.计算gamma值
|
|
|
let gamma = calc_gamma(max_spread, q, last_std);
|
|
let gamma = calc_gamma(max_spread, q, last_std);
|
|
|
|
|
|
|
@@ -114,16 +113,16 @@ impl Bot {
|
|
|
let dd = calc_deviation_range(self.rl_end, &self.spread_list, *i);
|
|
let dd = calc_deviation_range(self.rl_end, &self.spread_list, *i);
|
|
|
// 8.获取Reservation price 预定价格
|
|
// 8.获取Reservation price 预定价格
|
|
|
let rp = calc_rp(self.mid_price, q, *i, gamma, last_std);
|
|
let rp = calc_rp(self.mid_price, q, *i, gamma, last_std);
|
|
|
- // eprintln!("rp {}, dd {}, ask {}, bid {}", rp, dd, ask, bid);
|
|
|
|
|
|
|
+
|
|
|
if (rp + 0.5 * dd) < self.ask || (rp - 0.5 * dd) > self.bid {
|
|
if (rp + 0.5 * dd) < self.ask || (rp - 0.5 * dd) > self.bid {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
// 9.获取dk,用于计算e的dk次方
|
|
// 9.获取dk,用于计算e的dk次方
|
|
|
let dk = calc_dk(dd, gamma, last_std, *i);
|
|
let dk = calc_dk(dd, gamma, last_std, *i);
|
|
|
- // eprintln!("dk {}", dk);
|
|
|
|
|
|
|
+
|
|
|
// 10.获取kappa
|
|
// 10.获取kappa
|
|
|
let kappa = calc_kappa(gamma, dk, dd, *i);
|
|
let kappa = calc_kappa(gamma, dk, dd, *i);
|
|
|
- // eprintln!("kappa {}", kappa);
|
|
|
|
|
|
|
+
|
|
|
// 11.获取theta
|
|
// 11.获取theta
|
|
|
let cal_theta = calc_theta(gamma, last_std, kappa, *i);
|
|
let cal_theta = calc_theta(gamma, last_std, kappa, *i);
|
|
|
// 交易数量
|
|
// 交易数量
|
|
@@ -214,7 +213,7 @@ impl Bot {
|
|
|
return Err(error);
|
|
return Err(error);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
- println!("info: {:?}", balance_info);
|
|
|
|
|
|
|
+
|
|
|
// 取消超时订单
|
|
// 取消超时订单
|
|
|
self.order_list_deal().await.expect("订单信息处理异常!");
|
|
self.order_list_deal().await.expect("订单信息处理异常!");
|
|
|
|
|
|
|
@@ -261,8 +260,6 @@ impl Bot {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn depth_handler(&mut self, depth: Depth) {
|
|
fn depth_handler(&mut self, depth: Depth) {
|
|
|
- // println!("{:?}", depth)
|
|
|
|
|
-
|
|
|
|
|
let (spread, mid_price, ask, bid) = get_spread(&depth);
|
|
let (spread, mid_price, ask, bid) = get_spread(&depth);
|
|
|
self.mid_price = mid_price;
|
|
self.mid_price = mid_price;
|
|
|
self.ask = ask;
|
|
self.ask = ask;
|
|
@@ -279,6 +276,7 @@ async fn main() {
|
|
|
let spread_list:Vec<f64> = Vec::new();
|
|
let spread_list:Vec<f64> = Vec::new();
|
|
|
// 币对-获取深度信息参数
|
|
// 币对-获取深度信息参数
|
|
|
let symbol:String = "BTC_USDT".to_string();
|
|
let symbol:String = "BTC_USDT".to_string();
|
|
|
|
|
+ let symbol_order:String = "BTC_USDT".to_string();
|
|
|
// 限制数-获取深度信息参数
|
|
// 限制数-获取深度信息参数
|
|
|
let limit = 10;
|
|
let limit = 10;
|
|
|
// 开始
|
|
// 开始
|
|
@@ -313,6 +311,7 @@ async fn main() {
|
|
|
let bot = Bot::new(spread_list, symbol.clone(), limit, short_interval, rl_start, rl_end, quantity_max, amount_decimal_places, order_info_map, last_buy_time, buy_time_limit, cancel_time_limit, price_decimal_places, spread_list_limit, exchange);
|
|
let bot = Bot::new(spread_list, symbol.clone(), limit, short_interval, rl_start, rl_end, quantity_max, amount_decimal_places, order_info_map, last_buy_time, buy_time_limit, cancel_time_limit, price_decimal_places, spread_list_limit, exchange);
|
|
|
let bot_arc = Arc::new(Mutex::new(bot));
|
|
let bot_arc = Arc::new(Mutex::new(bot));
|
|
|
let bot_binance_depth_arc = Arc::clone(&bot_arc);
|
|
let bot_binance_depth_arc = Arc::clone(&bot_arc);
|
|
|
|
|
+ let bot_okx_order_arc = Arc::clone(&bot_arc);
|
|
|
|
|
|
|
|
// bot主线程
|
|
// bot主线程
|
|
|
let bot_arc_thread = tokio::spawn(async move {
|
|
let bot_arc_thread = tokio::spawn(async move {
|
|
@@ -337,12 +336,6 @@ async fn main() {
|
|
|
|
|
|
|
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // loop {
|
|
|
|
|
- // println!("我是bot1111111111111");
|
|
|
|
|
- //
|
|
|
|
|
- // tokio::time::sleep(Duration::from_millis(100)).await;
|
|
|
|
|
- // }
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 各种订阅信息,辅助线程
|
|
// 各种订阅信息,辅助线程
|
|
@@ -351,24 +344,18 @@ async fn main() {
|
|
|
let okx_secret_key_x= env::var("okx_secret_key").unwrap();
|
|
let okx_secret_key_x= env::var("okx_secret_key").unwrap();
|
|
|
let okx_passphrase_x= env::var("okx_passphrase").unwrap();
|
|
let okx_passphrase_x= env::var("okx_passphrase").unwrap();
|
|
|
let exchange_x:Exchange = Exchange::new(okx_access_key_x, okx_secret_key_x, okx_passphrase_x);
|
|
let exchange_x:Exchange = Exchange::new(okx_access_key_x, okx_secret_key_x, okx_passphrase_x);
|
|
|
- exchange_x.get_binance_depth(&symbol, 10, bot_binance_depth_arc).await;
|
|
|
|
|
- // loop {
|
|
|
|
|
- // {
|
|
|
|
|
- // let bot = bot_binance_depth_arc.lock().await;
|
|
|
|
|
- // let callback = bot.depth_handler();
|
|
|
|
|
- //
|
|
|
|
|
- // exchange.get_binance_depth(&symbol, 10, callback).await;
|
|
|
|
|
- // }
|
|
|
|
|
- //
|
|
|
|
|
- // // tokio::time::sleep(Duration::from_millis(100)).await;
|
|
|
|
|
- // }
|
|
|
|
|
-
|
|
|
|
|
- // loop {
|
|
|
|
|
- // println!("我是sub222222222222222方法");
|
|
|
|
|
- //
|
|
|
|
|
- // tokio::time::sleep(Duration::from_millis(1)).await;
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ exchange_x.subscribe_binance_depth(&symbol, 10, bot_binance_depth_arc).await;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 各种订阅信息,辅助线程
|
|
|
|
|
+ let subscribe_order_change_thread = tokio::spawn(async move {
|
|
|
|
|
+ let okx_access_key_y= env::var("okx_access_key").unwrap();
|
|
|
|
|
+ let okx_secret_key_y= env::var("okx_secret_key").unwrap();
|
|
|
|
|
+ let okx_passphrase_y= env::var("okx_passphrase").unwrap();
|
|
|
|
|
+ let exchange_x:Exchange = Exchange::new(okx_access_key_y, okx_secret_key_y, okx_passphrase_y);
|
|
|
|
|
+ exchange_x.subscribe_okx_order(&symbol_order, bot_okx_order_arc).await;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- tokio::try_join!(bot_arc_thread, subscribe_binance_depth_thread).unwrap();
|
|
|
|
|
|
|
+ tokio::try_join!(bot_arc_thread, subscribe_binance_depth_thread, subscribe_order_change_thread).unwrap();
|
|
|
}
|
|
}
|