|
|
@@ -7,6 +7,7 @@ use futures::stream::FuturesUnordered;
|
|
|
use futures::TryStreamExt;
|
|
|
use rust_decimal::Decimal;
|
|
|
use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
|
|
|
+use rust_decimal_macros::dec;
|
|
|
use serde_json::{json};
|
|
|
use tokio::spawn;
|
|
|
use tokio::time::Instant;
|
|
|
@@ -536,7 +537,8 @@ impl Platform for GateSwap {
|
|
|
let response_data = self.request.place_price_order(base_coin, params).await;
|
|
|
if response_data.code == "200" {
|
|
|
Ok(PriceOrder {
|
|
|
- id: response_data.data["id"].to_string(),
|
|
|
+ price_order_id: response_data.data["id"].to_string(),
|
|
|
+ order_id: "".to_string(),
|
|
|
})
|
|
|
} else {
|
|
|
Err(Error::new(ErrorKind::Other, response_data.to_string()))
|
|
|
@@ -551,7 +553,8 @@ impl Platform for GateSwap {
|
|
|
let response_data = self.request.cancel_price_order(base_coin, order_id.to_string()).await;
|
|
|
if response_data.code == "200" {
|
|
|
Ok(PriceOrder {
|
|
|
- id: order_id.to_string(),
|
|
|
+ price_order_id: order_id.to_string(),
|
|
|
+ order_id: "".to_string(),
|
|
|
})
|
|
|
} else {
|
|
|
Err(Error::new(ErrorKind::Other, response_data.to_string()))
|
|
|
@@ -611,6 +614,7 @@ impl Platform for GateSwap {
|
|
|
let side = order_command.limits_open[item].get(1).unwrap().clone();
|
|
|
let price = Decimal::from_str(&*order_command.limits_open[item].get(2).unwrap().clone()).unwrap();
|
|
|
let cid = order_command.limits_open[item].get(3).unwrap().clone();
|
|
|
+ let stop_price = Decimal::from_str(&*order_command.limits_open[item].get(4).unwrap().clone()).unwrap();
|
|
|
|
|
|
// order_name: [数量,方向,价格,c_id]
|
|
|
let mut self_clone = self.clone();
|
|
|
@@ -621,10 +625,28 @@ impl Platform for GateSwap {
|
|
|
ts.on_after_send();
|
|
|
|
|
|
match result {
|
|
|
- Ok(mut result) => {
|
|
|
- result.trace_stack = ts;
|
|
|
+ Ok(mut order) => {
|
|
|
+ order.trace_stack = ts;
|
|
|
|
|
|
- self_clone.order_sender.send(result).await.unwrap();
|
|
|
+ self_clone.order_sender.send(order).await.unwrap();
|
|
|
+
|
|
|
+ // 成功之后下止损单
|
|
|
+ let price_order_result = self_clone.take_stop_loss_order(
|
|
|
+ stop_price,
|
|
|
+ dec!(0),
|
|
|
+ &side).await;
|
|
|
+
|
|
|
+ // 下止损单成功之后发到逻辑层处理。
|
|
|
+ match price_order_result {
|
|
|
+ Ok(mut price_order) => {
|
|
|
+ price_order.order_id = order.id.clone();
|
|
|
+
|
|
|
+ self_clone.price_order_sender.send(price_order).await.unwrap();
|
|
|
+ }
|
|
|
+ Err(error) => {
|
|
|
+ error!("gate swap 止损单下单失败,原因:{:?}。", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
Err(error) => {
|
|
|
let mut err_order = Order::new();
|