Explorar o código

coinex订单查询逻辑完善

JiahengHe hai 1 ano
pai
achega
537fc2a351

+ 2 - 1
exchanges/src/coinex_swap_rest.rs

@@ -147,8 +147,9 @@ impl CoinexSwapRest {
         data
     }
     //查询单个订单详情  /spot/order-status?market=CETUSDT&order_id=13400
-    pub async fn get_order_details(&mut self, order_id: String) -> ResponseData {
+    pub async fn get_order_details(&mut self, order_id: String, market: String) -> ResponseData {
         let params = serde_json::json!({
+            "market": market,
             "order_id": order_id
          });
         let data = self.request("GET".to_string(),

+ 9 - 16
exchanges/tests/coinex_swap_test.rs

@@ -1,26 +1,19 @@
-use std::cmp::max;
+
 use std::collections::BTreeMap;
-use std::io::{Error, ErrorKind};
 use std::str::FromStr;
 use std::sync::Arc;
 use std::sync::atomic::AtomicBool;
-use futures_channel::mpsc::UnboundedSender;
-use futures_util::StreamExt;
 use rust_decimal::Decimal;
 use serde_json::Value;
 use tokio::sync::Mutex;
-use tokio::time::Instant;
-use tracing::{error, info, trace};
-use exchanges::binance_swap_ws::BinanceSwapSubscribeType;
+use tracing::{error, trace};
 use exchanges::coinex_swap_rest::CoinexSwapRest;
 use exchanges::coinex_swap_ws::{CoinexSwapLogin, CoinexSwapSubscribeType, CoinexSwapWs};
-use exchanges::gate_swap_rest::GateSwapRest;
-use exchanges::gate_swap_ws::{GateSwapLogin, GateSwapWs, GateSwapWsType};
 use exchanges::response_base::ResponseData;
-use global::trace_stack::TraceStack;
 
-const ACCESS_KEY: &str = "";
-const SECRET_KEY: &str = "";
+
+const ACCESS_KEY: &str = "458BD3429F334456BC73A36773BD7551";
+const SECRET_KEY: &str = "901604EB82D196D61D1AD57CEAA785E24ED9AA2032CBEEE9";
 
 
 //ws-订阅公共频道信息
@@ -29,7 +22,7 @@ async fn ws_custom_subscribe() {
     global::log_utils::init_log_with_trace();
 
     let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
-    let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
+    let (_read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
 
     // let (write_tx, write_rx) = tokio::sync::broadcast::channel::<Message>(10);
     // let (read_tx, mut read_rx) = tokio::sync::broadcast::channel::<ResponseData>(10);
@@ -44,7 +37,7 @@ async fn ws_custom_subscribe() {
         trace!("线程-数据读取-开启");
         loop {
             // 从通道中接收并丢弃所有的消息,直到通道为空
-            while let Ok(Some(data)) = read_rx.try_next() {
+            while let Ok(Some(_data)) = read_rx.try_next() {
 
                 // 从通道中接收并丢弃所有的消息,直到通道为空
                 while let Ok(Some(_)) = read_rx.try_next() {
@@ -198,7 +191,7 @@ async fn rest_cancel_order_test() {
 #[tokio::test]
 async fn rest_cancel_all_order_test() {
     let mut ret = get_rest();
-    let ct_val = Decimal::ONE;
+    let _ct_val = Decimal::ONE;
     let orders_res_data = ret.get_pending_orders().await;
     let mut result = vec![];
     if orders_res_data.code == 200 {
@@ -230,7 +223,7 @@ async fn rest_pending_order_list_test() {
 #[tokio::test]
 async fn rest_order_status_test() {
     let mut ret = get_rest();
-    let req_data = ret.get().await;
+    let req_data = ret.get_order_details("136925916412".to_string(), "DOGEUSDT".to_string()).await;
     println!("coinex--查询pending_order--{:?}", req_data);
 }
 

+ 7 - 1
standard/src/coinex_swap.rs

@@ -341,10 +341,16 @@ impl Platform for CoinexSwap {
 
         if res_data.code == 200 {
             let res_data_json: Value = res_data.data;
-            let mut result = format_order_item(res_data_json, ct_val, "open");
+            let mut result = format_order_item(res_data_json, ct_val, "");
             result.custom_id = custom_id.to_string();
             result.id = order_id.to_string();
             Ok(result)
+        } else if res_data.code == -1 && res_data.message.contains("3103:order not exists") { // 未成交已取消的订单会报不存在
+            let mut order = Order::new();
+            order.id = order_id.to_string();
+            order.custom_id = custom_id.to_string();
+            order.status = "REMOVE".to_string();
+            Ok(order)
         } else {
             Err(Error::new(ErrorKind::Other, res_data.to_string()))
         }