|
|
@@ -4,13 +4,14 @@ use std::sync::atomic::AtomicBool;
|
|
|
use rust_decimal::Decimal;
|
|
|
use tokio::spawn;
|
|
|
use tokio::sync::Mutex;
|
|
|
-use tracing::info;
|
|
|
+use tracing::{error, info};
|
|
|
use exchanges::bitget_swap_ws::{BitgetSwapLogin, BitgetSwapSubscribeType, BitgetSwapWs, BitgetSwapWsType};
|
|
|
use exchanges::response_base::ResponseData;
|
|
|
use global::trace_stack::TraceStack;
|
|
|
-use standard::exchange::ExchangeEnum::{BitgetSwap, BybitSwap, GateSwap};
|
|
|
+use standard::exchange::ExchangeEnum::{BitgetSwap};
|
|
|
use crate::core::Core;
|
|
|
use crate::exchange_disguise::on_special_depth;
|
|
|
+use crate::model::OrderInfo;
|
|
|
|
|
|
pub async fn bitget_usdt_swap_run(is_shutdown_arc :Arc<AtomicBool>,
|
|
|
is_trade: bool,
|
|
|
@@ -19,37 +20,37 @@ pub async fn bitget_usdt_swap_run(is_shutdown_arc :Arc<AtomicBool>,
|
|
|
symbols: Vec<String>,
|
|
|
is_colo: bool,
|
|
|
exchange_params: BTreeMap<String, String>) {
|
|
|
- // // 开启公共频道
|
|
|
- // let (write_tx_public, write_rx_public) = futures_channel::mpsc::unbounded();
|
|
|
- //
|
|
|
- // // 开启公共连接
|
|
|
- // let is_shutdown_arc_c1 = is_shutdown_arc.clone();
|
|
|
- // let write_tx_am_public = Arc::new(Mutex::new(write_tx_public));
|
|
|
- // let name_clone = name.clone();
|
|
|
- // let core_arc_clone = core_arc.clone();
|
|
|
- // let symbols_clone = symbols.clone();
|
|
|
- // spawn(async move {
|
|
|
- // // 构建链接ws
|
|
|
- // let mut bg_public = BitgetSwapWs::new_label(name_clone.clone(),
|
|
|
- // is_colo,
|
|
|
- // None,
|
|
|
- // BitgetSwapWsType::Public);
|
|
|
- //
|
|
|
- // // 消费数据的函数
|
|
|
- // let mut update_flag_u = Decimal::ZERO;
|
|
|
- // let fun = move |data: ResponseData| {
|
|
|
- // let core_arc_cc = core_arc_clone.clone();
|
|
|
- //
|
|
|
- // async move {
|
|
|
- // on_public_data(core_arc_cc, &mut update_flag_u, data).await
|
|
|
- // }
|
|
|
- // };
|
|
|
- //
|
|
|
- // // 准备链接
|
|
|
- // bg_public.set_subscribe(vec![BitgetSwapSubscribeType::PuBooks1]); // 只用订阅深度数据
|
|
|
- // bg_public.set_symbols(symbols_clone);
|
|
|
- // bg_public.ws_connect_async(is_shutdown_arc_c1, fun, &write_tx_am_public, write_rx_public).await.expect("bitget_usdt_swap 链接有异常")
|
|
|
- // });
|
|
|
+ // 开启公共频道
|
|
|
+ let (write_tx_public, write_rx_public) = futures_channel::mpsc::unbounded();
|
|
|
+
|
|
|
+ // 开启公共连接
|
|
|
+ let is_shutdown_arc_c1 = is_shutdown_arc.clone();
|
|
|
+ let write_tx_am_public = Arc::new(Mutex::new(write_tx_public));
|
|
|
+ let name_clone = name.clone();
|
|
|
+ let core_arc_clone = core_arc.clone();
|
|
|
+ let symbols_clone = symbols.clone();
|
|
|
+ spawn(async move {
|
|
|
+ // 构建链接ws
|
|
|
+ let mut bg_public = BitgetSwapWs::new_label(name_clone.clone(),
|
|
|
+ is_colo,
|
|
|
+ None,
|
|
|
+ BitgetSwapWsType::Public);
|
|
|
+
|
|
|
+ // 消费数据的函数
|
|
|
+ let mut update_flag_u = Decimal::ZERO;
|
|
|
+ let fun = move |data: ResponseData| {
|
|
|
+ let core_arc_cc = core_arc_clone.clone();
|
|
|
+
|
|
|
+ async move {
|
|
|
+ on_public_data(core_arc_cc, &mut update_flag_u, data).await
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 准备链接
|
|
|
+ bg_public.set_subscribe(vec![BitgetSwapSubscribeType::PuBooks1]); // 只用订阅深度数据
|
|
|
+ bg_public.set_symbols(symbols_clone);
|
|
|
+ bg_public.ws_connect_async(is_shutdown_arc_c1, fun, &write_tx_am_public, write_rx_public).await.expect("bitget_usdt_swap 链接有异常")
|
|
|
+ });
|
|
|
|
|
|
// 不需要交易就不用开启私有频道了
|
|
|
if !is_trade {
|
|
|
@@ -99,22 +100,44 @@ async fn on_private_data(core_arc_clone: Arc<Mutex<Core>>,
|
|
|
run_symbol: &String) {
|
|
|
let mut trace_stack = TraceStack::new(response.time, response.ins);
|
|
|
trace_stack.on_after_span_line();
|
|
|
- info!(?response);
|
|
|
|
|
|
// public类型,目前只考虑订单流数据
|
|
|
- // match response.channel.as_str() {
|
|
|
- // "account" => {
|
|
|
- // info!(?response);
|
|
|
- // let account = standard::handle_info::HandleSwapInfo::handle_account_info(BybitSwap, &response, run_symbol);
|
|
|
- // info!(?account);
|
|
|
- // let mut core = core_arc_clone.lock().await;
|
|
|
- // core.update_equity(account).await;
|
|
|
- // }
|
|
|
- // _ => {
|
|
|
- // info!("bitget_usdt_swap 113 未知的订阅数据");
|
|
|
- // info!(?response)
|
|
|
- // }
|
|
|
- // }
|
|
|
+ match response.channel.as_str() {
|
|
|
+ "account" => {
|
|
|
+ let account = standard::handle_info::HandleSwapInfo::handle_account_info(BitgetSwap, &response, run_symbol);
|
|
|
+ let mut core = core_arc_clone.lock().await;
|
|
|
+ core.update_equity(account).await;
|
|
|
+ },
|
|
|
+ "positions" => {
|
|
|
+ let positions = standard::handle_info::HandleSwapInfo::handle_position(BitgetSwap, &response, &ct_val);
|
|
|
+ let mut core = core_arc_clone.lock().await;
|
|
|
+ core.update_position(positions).await;
|
|
|
+ },
|
|
|
+ "orders" => {
|
|
|
+ trace_stack.set_source("gate_swap.orders".to_string());
|
|
|
+ let orders = standard::handle_info::HandleSwapInfo::handle_order(BitgetSwap, response.clone(), ct_val.clone());
|
|
|
+
|
|
|
+ let mut order_infos:Vec<OrderInfo> = Vec::new();
|
|
|
+ for mut order in orders.order {
|
|
|
+ if order.status == "NULL" {
|
|
|
+ error!("bitget_usdt_swap 未识别的订单状态:{:?}", response);
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ let order_info = OrderInfo::parse_order_to_order_info(&mut order);
|
|
|
+ order_infos.push(order_info);
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ let mut core = core_arc_clone.lock().await;
|
|
|
+ core.update_order(order_infos, trace_stack).await;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ _ => {
|
|
|
+ info!("bitget_usdt_swap 113 未知的订阅数据: {:?}", response);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
async fn on_public_data(core_arc_clone: Arc<Mutex<Core>>,
|
|
|
@@ -130,7 +153,7 @@ async fn on_public_data(core_arc_clone: Arc<Mutex<Core>>,
|
|
|
let special_depth = standard::handle_info::HandleSwapInfo::handle_special_depth(BitgetSwap, &response);
|
|
|
trace_stack.on_after_format();
|
|
|
|
|
|
- // on_special_depth(core_arc_clone, update_flag_u, &response.label, &mut trace_stack, &special_depth).await;
|
|
|
+ on_special_depth(core_arc_clone, update_flag_u, &response.label, &mut trace_stack, &special_depth).await;
|
|
|
}
|
|
|
_ => {
|
|
|
info!("bitget_usdt_swap 125 未知的订阅数据");
|