|
|
@@ -3,6 +3,8 @@ use std::io::{Error, ErrorKind};
|
|
|
use std::str::FromStr;
|
|
|
use tokio::sync::mpsc::Sender;
|
|
|
use async_trait::async_trait;
|
|
|
+use futures::stream::FuturesUnordered;
|
|
|
+use futures::TryStreamExt;
|
|
|
use rust_decimal::Decimal;
|
|
|
use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
|
|
|
use serde_json::json;
|
|
|
@@ -510,15 +512,15 @@ impl Platform for GateSwap {
|
|
|
|
|
|
// 指令下单
|
|
|
async fn command_order(&mut self, order_command: &mut OrderCommand, trace_stack: &TraceStack) {
|
|
|
- let ins = trace_stack.ins.clone();
|
|
|
- TraceStack::show_delay(&ins);
|
|
|
+ let mut handles = vec![];
|
|
|
+
|
|
|
// 撤销订单
|
|
|
for item in order_command.cancel.keys() {
|
|
|
let order_id = order_command.cancel[item].get(1).unwrap().clone();
|
|
|
let custom_id = order_command.cancel[item].get(0).unwrap().clone();
|
|
|
|
|
|
let mut self_clone = self.clone();
|
|
|
- spawn(async move {
|
|
|
+ let handle = spawn(async move {
|
|
|
let result = self_clone.cancel_order(&order_id, &custom_id).await;
|
|
|
match result {
|
|
|
Ok(_) => {
|
|
|
@@ -540,7 +542,9 @@ impl Platform for GateSwap {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ handles.push(handle)
|
|
|
}
|
|
|
+
|
|
|
// 下单指令
|
|
|
order_command.limits_open.extend(order_command.limits_close.clone());
|
|
|
for item in order_command.limits_open.keys() {
|
|
|
@@ -553,7 +557,7 @@ impl Platform for GateSwap {
|
|
|
|
|
|
// order_name: [数量,方向,价格,c_id]
|
|
|
let mut self_clone = self.clone();
|
|
|
- spawn(async move {
|
|
|
+ let handle = spawn(async move {
|
|
|
ts.on_before_send();
|
|
|
let result = self_clone.take_order(&cid, &side, price, amount).await;
|
|
|
ts.on_after_send();
|
|
|
@@ -576,14 +580,16 @@ impl Platform for GateSwap {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ handles.push(handle)
|
|
|
}
|
|
|
+
|
|
|
// 检查订单指令
|
|
|
for item in order_command.check.keys() {
|
|
|
let order_id = order_command.check[item].get(1).unwrap().clone();
|
|
|
let custom_id = order_command.check[item].get(0).unwrap().clone();
|
|
|
|
|
|
let mut self_clone = self.clone();
|
|
|
- spawn(async move {
|
|
|
+ let handle = spawn(async move {
|
|
|
let result = self_clone.get_order_detail(&order_id, &custom_id).await;
|
|
|
match result {
|
|
|
Ok(result) => {
|
|
|
@@ -594,7 +600,11 @@ impl Platform for GateSwap {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ handles.push(handle)
|
|
|
}
|
|
|
+
|
|
|
+ let futures = FuturesUnordered::from_iter(handles);
|
|
|
+ let _: Result<Vec<_>, _> = futures.try_collect().await;
|
|
|
}
|
|
|
}
|
|
|
|