|
|
@@ -9,6 +9,7 @@ use exchanges::coinex_swap_ws::{CoinexSwapLogin, CoinexSwapSubscribeType, Coinex
|
|
|
use exchanges::response_base::ResponseData;
|
|
|
use global::trace_stack::{TraceStack};
|
|
|
use standard::exchange::ExchangeEnum::{CoinexSwap};
|
|
|
+use standard::{Position, PositionModeEnum};
|
|
|
use crate::model::{OrderInfo};
|
|
|
use crate::core::Core;
|
|
|
use crate::exchange_disguise::on_special_depth;
|
|
|
@@ -98,7 +99,7 @@ async fn on_data(core_arc_clone: Arc<Mutex<Core>>,
|
|
|
}
|
|
|
"order.update" => {
|
|
|
trace_stack.set_source("coinex_swap.orders".to_string());
|
|
|
- info!("coinex_usdt_swap 订单推送:{:?}", response);
|
|
|
+ // info!("coinex_usdt_swap 订单推送:{:?}", response);
|
|
|
let orders = standard::handle_info::HandleSwapInfo::handle_order(CoinexSwap, response.clone(), multiplier.clone());
|
|
|
let mut order_infos:Vec<OrderInfo> = Vec::new();
|
|
|
for mut order in orders.order {
|
|
|
@@ -110,17 +111,62 @@ async fn on_data(core_arc_clone: Arc<Mutex<Core>>,
|
|
|
let order_info = OrderInfo::parse_order_to_order_info(&mut order);
|
|
|
order_infos.push(order_info);
|
|
|
}
|
|
|
- info!(?order_infos);
|
|
|
+
|
|
|
if !order_infos.is_empty(){
|
|
|
let mut core = core_arc_clone.lock().await;
|
|
|
core.update_order(order_infos, trace_stack).await;
|
|
|
}
|
|
|
}
|
|
|
"position.update" => {
|
|
|
- // info!("coinex_usdt_swap 仓位推送:{:?}", response.data);
|
|
|
+ info!("coinex_usdt_swap 仓位推送:{:?}", response.data);
|
|
|
let positions = standard::handle_info::HandleSwapInfo::handle_position(CoinexSwap, &response, multiplier);
|
|
|
let mut core = core_arc_clone.lock().await;
|
|
|
- core.update_position(positions).await;
|
|
|
+ let local_position_by_orders = &core.local_position_by_orders;
|
|
|
+ let position = positions[0].clone();
|
|
|
+ let mut result_position = vec![];
|
|
|
+ info!("本地仓位推算:{:?}", local_position_by_orders);
|
|
|
+ let position_num = local_position_by_orders.long_pos - local_position_by_orders.short_pos;
|
|
|
+ let mut long_pos = Position::new();
|
|
|
+ let mut short_pos = Position::new();
|
|
|
+ if position_num == position.amount {
|
|
|
+ long_pos.amount = local_position_by_orders.long_pos;
|
|
|
+ long_pos.price = position.price;
|
|
|
+ long_pos.position_mode = PositionModeEnum::Long;
|
|
|
+ short_pos.amount = local_position_by_orders.short_pos;
|
|
|
+ short_pos.price = local_position_by_orders.short_avg;
|
|
|
+ short_pos.position_mode = PositionModeEnum::Short;
|
|
|
+ } else {
|
|
|
+ match position.position_mode {
|
|
|
+ PositionModeEnum::Long => {
|
|
|
+ long_pos.amount = position.amount;
|
|
|
+ long_pos.price = position.price;
|
|
|
+ long_pos.position_mode = PositionModeEnum::Long;
|
|
|
+ short_pos.amount = local_position_by_orders.short_pos;
|
|
|
+ short_pos.price = local_position_by_orders.short_avg;
|
|
|
+ short_pos.position_mode = PositionModeEnum::Short;
|
|
|
+ },
|
|
|
+ PositionModeEnum::Short => {
|
|
|
+ short_pos.amount = position.amount;
|
|
|
+ short_pos.price = position.price;
|
|
|
+ short_pos.position_mode = PositionModeEnum::Short;
|
|
|
+ long_pos.amount = local_position_by_orders.long_pos;
|
|
|
+ long_pos.price = local_position_by_orders.long_avg;
|
|
|
+ long_pos.position_mode = PositionModeEnum::Long;
|
|
|
+ },
|
|
|
+ _ => {
|
|
|
+ error!("coinex_usdt_swap 仓位推送错误:{:?}", response.data);
|
|
|
+ short_pos.amount = Decimal::ZERO;
|
|
|
+ short_pos.price = Decimal::ZERO;
|
|
|
+ short_pos.position_mode = PositionModeEnum::Short;
|
|
|
+ long_pos.amount = Decimal::ZERO;
|
|
|
+ long_pos.price = Decimal::ZERO;
|
|
|
+ long_pos.position_mode = PositionModeEnum::Long;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result_position.push(long_pos);
|
|
|
+ result_position.push(short_pos);
|
|
|
+ core.update_position(result_position).await;
|
|
|
}
|
|
|
"deals.update" => {
|
|
|
// let mut core = core_arc_clone.lock().await;
|