|
|
@@ -331,18 +331,21 @@ impl Platform for CoinexSwap {
|
|
|
let symbol = self.symbol.replace("_", "").to_uppercase();
|
|
|
let ct_val = self.market.ct_val;
|
|
|
let res_data;
|
|
|
+ let status ;
|
|
|
if order_id != "" {
|
|
|
+ status = "";
|
|
|
res_data = self.request.get_order_details(order_id.to_string(), symbol).await;
|
|
|
} else if custom_id != "" {
|
|
|
// 通过客户端id查询 只有未完成的订单才能查询出来
|
|
|
res_data = self.request.get_pending_order(format!("t-{}", custom_id)).await;
|
|
|
+ status = "open";
|
|
|
} else {
|
|
|
return Err(Error::new(ErrorKind::Other, format!("订单id和客户端id都为空,查询失败!order_id :{}, custom_id: {}", order_id, custom_id)));
|
|
|
}
|
|
|
|
|
|
if res_data.code == 200 {
|
|
|
let res_data_json: Value = res_data.data;
|
|
|
- let mut result = format_order_item(res_data_json, ct_val, "");
|
|
|
+ let mut result = format_order_item(res_data_json, ct_val, status);
|
|
|
result.custom_id = custom_id.to_string();
|
|
|
result.id = order_id.to_string();
|
|
|
Ok(result)
|
|
|
@@ -350,7 +353,7 @@ impl Platform for CoinexSwap {
|
|
|
let mut order = Order::new();
|
|
|
order.id = order_id.to_string();
|
|
|
order.custom_id = custom_id.to_string();
|
|
|
- order.status = "REMOVE".to_string();
|
|
|
+ order.status = "NULL".to_string();
|
|
|
Ok(order)
|
|
|
} else {
|
|
|
Err(Error::new(ErrorKind::Other, res_data.to_string()))
|
|
|
@@ -374,6 +377,9 @@ impl Platform for CoinexSwap {
|
|
|
}
|
|
|
if res_data.code == 200 {
|
|
|
let res_data_json = res_data.data.as_array().unwrap();
|
|
|
+ if res_data_json.len() ==0 {
|
|
|
+ return Ok(vec![])
|
|
|
+ }
|
|
|
let order_info: Vec<_> = res_data_json.iter().filter(|item| item["market"].as_str().unwrap_or("") == symbol).collect();
|
|
|
let result = order_info.iter().map(|&item| format_order_item(item.clone(), ct_val, status_order)).collect();
|
|
|
Ok(result)
|
|
|
@@ -455,7 +461,6 @@ impl Platform for CoinexSwap {
|
|
|
let res_data = self.request.order(symbol, position_side.to_string(), order_side.to_string(), size, price, custom_id.to_string()).await;
|
|
|
if res_data.code == 200 {
|
|
|
let res_data_json: Value = res_data.data;
|
|
|
- // info!("take_order_symbol {}", res_data_json);
|
|
|
let result = format_order_item(res_data_json, ct_val, "open");
|
|
|
Ok(result)
|
|
|
} else {
|
|
|
@@ -471,10 +476,24 @@ impl Platform for CoinexSwap {
|
|
|
let res_data = self.request.cancel_order(symbol, order_id, custom_id).await;
|
|
|
if res_data.code == 200 {
|
|
|
let res_data_json: Value = res_data.data;
|
|
|
- // info!("cancel_order {} order_id {} custom_id {}", res_data_json, order_id, custom_id);
|
|
|
- let mut result = format_order_item(res_data_json, ct_val, "canceled");
|
|
|
- result.custom_id = custom_id.to_string();
|
|
|
- result.id = order_id.to_string();
|
|
|
+ let mut result;
|
|
|
+ if res_data_json.is_null(){
|
|
|
+ result = Order{
|
|
|
+ id: custom_id.to_string(),
|
|
|
+ custom_id: order_id.to_string(),
|
|
|
+ price: Default::default(),
|
|
|
+ amount: Default::default(),
|
|
|
+ deal_amount: Default::default(),
|
|
|
+ avg_price: Default::default(),
|
|
|
+ status: "NULL".to_string(),
|
|
|
+ order_type: "".to_string(),
|
|
|
+ trace_stack: TraceStack::new(0, Instant::now()).on_special("485 coinex_swap".to_string()),
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ result = format_order_item(res_data_json, ct_val, "canceled");
|
|
|
+ result.custom_id = custom_id.to_string();
|
|
|
+ result.id = order_id.to_string();
|
|
|
+ }
|
|
|
Ok(result)
|
|
|
} else {
|
|
|
let message = format!("撤单HTTP请求失败 order_id: {}, custom_id: {}, res_data: {:?}", order_id, custom_id, res_data);
|
|
|
@@ -486,8 +505,6 @@ impl Platform for CoinexSwap {
|
|
|
let symbol = self.symbol.replace("_", "").to_uppercase();
|
|
|
let res_data = self.request.cancel_order_all(symbol).await;
|
|
|
if res_data.code == 200 {
|
|
|
- // let res_data_json = res_data.data.as_array().unwrap();
|
|
|
- // info!("cancel_orders {:?}", res_data_json);
|
|
|
let result = vec![];
|
|
|
Ok(result)
|
|
|
} else {
|
|
|
@@ -496,18 +513,13 @@ impl Platform for CoinexSwap {
|
|
|
}
|
|
|
|
|
|
async fn cancel_orders_all(&mut self) -> Result<Vec<Order>, Error> {
|
|
|
- let ct_val = self.market.ct_val;
|
|
|
let orders_res_data = self.request.get_pending_orders().await;
|
|
|
- let status = "canceled";
|
|
|
if orders_res_data.code == 200 {
|
|
|
- let mut result = vec![];
|
|
|
+ let result = vec![];
|
|
|
let orders_res_data_json = orders_res_data.data.as_array().unwrap();
|
|
|
for order in orders_res_data_json {
|
|
|
let cancel_res_data = self.request.cancel_order_all( order["market"].as_str().unwrap().to_string()).await;
|
|
|
- // info!("cancel_orders_all {:?}", cancel_res_data);
|
|
|
- if cancel_res_data.code == 200 {
|
|
|
- result.push(format_order_item(order.clone(), ct_val, status))
|
|
|
- } else {
|
|
|
+ if cancel_res_data.code != 200 {
|
|
|
return Err(Error::new(ErrorKind::Other, cancel_res_data.to_string()));
|
|
|
}
|
|
|
}
|
|
|
@@ -680,20 +692,8 @@ pub fn format_position_item(position: &Value, ct_val: Decimal) -> Position {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-pub fn format_order_item(order: Value, ct_val: Decimal, status :&str) -> Order {
|
|
|
- if order.is_null() || (order.is_array() && order.as_array().unwrap().is_empty()){
|
|
|
- return Order {
|
|
|
- id: "".to_string(),
|
|
|
- custom_id: "".to_string(),
|
|
|
- price: Decimal::ZERO,
|
|
|
- amount: Decimal::ZERO,
|
|
|
- deal_amount: Decimal::ZERO,
|
|
|
- avg_price: Decimal::ZERO,
|
|
|
- status: "REMOVE".to_string(),
|
|
|
- order_type: "limit".to_string(),
|
|
|
- trace_stack: TraceStack::new(0, Instant::now()).on_special("688 trace_stack".to_string()),
|
|
|
- }
|
|
|
- }
|
|
|
+pub fn format_order_item(order: Value, ct_val: Decimal, status: &str) -> Order {
|
|
|
+ // info!("order_format {}", order);
|
|
|
let size;
|
|
|
match order["amount"].as_str() {
|
|
|
Some(val) => {
|