|
|
@@ -1334,66 +1334,103 @@ impl Quant {
|
|
|
}
|
|
|
length = length + 1;
|
|
|
info!(" 仓位:{:?}", position);
|
|
|
- match self.platform_rest.get_ticker_symbol(position.symbol.clone()).await {
|
|
|
- Ok(ticker) => {
|
|
|
- let ap = ticker.sell;
|
|
|
- let bp = ticker.buy;
|
|
|
- let mp = (ap + bp) / Decimal::TWO;
|
|
|
- let price;
|
|
|
- let side;
|
|
|
- let market_info;
|
|
|
- // 获取market
|
|
|
- match self.platform_rest.get_market_symbol(position.symbol.clone()).await {
|
|
|
- Ok(market) => {
|
|
|
- market_info = market;
|
|
|
- }
|
|
|
- Err(err) => {
|
|
|
- error!(" {} 获取当前market异常: {}", position.symbol.clone(), err);
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- info!(?position);
|
|
|
- match position.position_mode {
|
|
|
- PositionModeEnum::Long => {
|
|
|
- // pd
|
|
|
- price = (mp * dec!(0.9985) / market_info.tick_size).floor() * market_info.tick_size;
|
|
|
- side = "pd";
|
|
|
- }
|
|
|
- PositionModeEnum::Short => {
|
|
|
- // pk
|
|
|
- price = (mp * dec!(1.0015) / market_info.tick_size).floor() * market_info.tick_size;
|
|
|
- side = "pk";
|
|
|
- }
|
|
|
- _ => {
|
|
|
- error!(" 仓位position_mode匹配失败,不做操作!");
|
|
|
- // 执行完当前币对 结束循环
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- // 发起清仓订单
|
|
|
- info!(?ticker);
|
|
|
- let mut ts = TraceStack::default();
|
|
|
- ts.on_before_send();
|
|
|
- match self.platform_rest.take_order_symbol(position.symbol.clone(), Decimal::ONE, utils::generate_client_id(None).as_str(), side, price, position.amount.abs()).await {
|
|
|
- Ok(order) => {
|
|
|
- ts.on_after_send();
|
|
|
- info!(" {}仓位清除下单成功 {:?}, {}", position.symbol.clone(), order, ts.to_string());
|
|
|
- // 执行完当前币对 结束循环
|
|
|
- continue;
|
|
|
- }
|
|
|
- Err(error) => {
|
|
|
- ts.on_after_send();
|
|
|
- error!(" {}仓位清除下单异常 {}, {}", position.symbol.clone(), error, ts.to_string());
|
|
|
- // 执行完当前币对 结束循环
|
|
|
- continue;
|
|
|
- }
|
|
|
- };
|
|
|
+ let price = Decimal::ZERO;
|
|
|
+ let side;
|
|
|
+ info!(?position);
|
|
|
+ match position.position_mode {
|
|
|
+ PositionModeEnum::Long => {
|
|
|
+ // pd
|
|
|
+ side = "pd";
|
|
|
+ }
|
|
|
+ PositionModeEnum::Short => {
|
|
|
+ // pk
|
|
|
+ side = "pk";
|
|
|
}
|
|
|
- Err(err) => {
|
|
|
- error!(" {} 获取当前ticker异常: {}", position.symbol.clone(), err)
|
|
|
+ _ => {
|
|
|
+ error!(" 仓位position_mode匹配失败,不做操作!");
|
|
|
+ // 执行完当前币对 结束循环
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
+ // 发起清仓订单
|
|
|
+ let mut ts = TraceStack::default();
|
|
|
+ ts.on_before_send();
|
|
|
+ // 市价单
|
|
|
+ match self.platform_rest.take_order_symbol(position.symbol.clone(), Decimal::ONE, utils::generate_client_id(None).as_str(), side, price, position.amount.abs()).await {
|
|
|
+ Ok(order) => {
|
|
|
+ ts.on_after_send();
|
|
|
+ info!(" {}仓位清除市价下单成功 {:?}, {}", position.symbol.clone(), order, ts.to_string());
|
|
|
+ // 执行完当前币对 结束循环
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Err(error) => {
|
|
|
+ ts.on_after_send();
|
|
|
+ error!(" {}仓位清除市价下单异常 {}, {}", position.symbol.clone(), error, ts.to_string());
|
|
|
+ // 执行完当前币对 结束循环
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ };
|
|
|
}
|
|
|
+ // match self.platform_rest.get_ticker_symbol(position.symbol.clone()).await {
|
|
|
+ // Ok(ticker) => {
|
|
|
+ // let ap = ticker.sell;
|
|
|
+ // let bp = ticker.buy;
|
|
|
+ // let mp = (ap + bp) / Decimal::TWO;
|
|
|
+ // let price;
|
|
|
+ // let side;
|
|
|
+ // let market_info;
|
|
|
+ // // 获取market
|
|
|
+ // match self.platform_rest.get_market_symbol(position.symbol.clone()).await {
|
|
|
+ // Ok(market) => {
|
|
|
+ // market_info = market;
|
|
|
+ // }
|
|
|
+ // Err(err) => {
|
|
|
+ // error!(" {} 获取当前market异常: {}", position.symbol.clone(), err);
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // info!(?position);
|
|
|
+ // match position.position_mode {
|
|
|
+ // PositionModeEnum::Long => {
|
|
|
+ // // pd
|
|
|
+ // price = (mp * dec!(0.9985) / market_info.tick_size).floor() * market_info.tick_size;
|
|
|
+ // side = "pd";
|
|
|
+ // }
|
|
|
+ // PositionModeEnum::Short => {
|
|
|
+ // // pk
|
|
|
+ // price = (mp * dec!(1.0015) / market_info.tick_size).floor() * market_info.tick_size;
|
|
|
+ // side = "pk";
|
|
|
+ // }
|
|
|
+ // _ => {
|
|
|
+ // error!(" 仓位position_mode匹配失败,不做操作!");
|
|
|
+ // // 执行完当前币对 结束循环
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // // 发起清仓订单
|
|
|
+ // info!(?ticker);
|
|
|
+ // let mut ts = TraceStack::default();
|
|
|
+ // ts.on_before_send();
|
|
|
+ // match self.platform_rest.take_order_symbol(position.symbol.clone(), Decimal::ONE, utils::generate_client_id(None).as_str(), side, price, position.amount.abs()).await {
|
|
|
+ // Ok(order) => {
|
|
|
+ // ts.on_after_send();
|
|
|
+ // info!(" {}仓位清除下单成功 {:?}, {}", position.symbol.clone(), order, ts.to_string());
|
|
|
+ // // 执行完当前币对 结束循环
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // Err(error) => {
|
|
|
+ // ts.on_after_send();
|
|
|
+ // error!(" {}仓位清除下单异常 {}, {}", position.symbol.clone(), error, ts.to_string());
|
|
|
+ // // 执行完当前币对 结束循环
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // };
|
|
|
+ // }
|
|
|
+ // Err(err) => {
|
|
|
+ // error!(" {} 获取当前ticker异常: {}", position.symbol.clone(), err)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
}
|
|
|
Err(error) => {
|
|
|
length = 0;
|