875428575@qq.com 2 жил өмнө
parent
commit
59738a18c3

+ 11 - 5
exchanges/src/okx_swap_rest.rs

@@ -56,14 +56,20 @@ impl OkxSwapRest {
     /*******************************************************************************************************/
     /*****************************************rest请求函数********************************************************/
     /*******************************************************************************************************/
-    //查看账户余额
-    pub async fn get_account(&mut self, ccy: String) -> ResponseData {
-        let params = serde_json::json!({
-            "ccy":ccy
+    //获取订单信息
+    pub async fn get_order(&mut self, symbol: String,ord_id:String,cl_ord_id:String) -> ResponseData {
+        let mut  params = serde_json::json!({
+            "instId":symbol
          });
+        if ord_id.len() > 0{
+            params.as_object_mut().unwrap().insert("ordId".parse().unwrap(), serde_json::Value::from(ord_id));
+        }
+        if cl_ord_id.len() > 0{
+            params.as_object_mut().unwrap().insert("clOrdId".parse().unwrap(), serde_json::Value::from(cl_ord_id));
+        }
         let data = self.request("GET".to_string(),
                                 "/api/v5".to_string(),
-                                "/account/balance".to_string(),
+                                "/trade/order".to_string(),
                                 true,
                                 params.to_string(),
         ).await;

+ 1 - 1
exchanges/src/okx_swap_ws.rs

@@ -219,7 +219,7 @@ impl OkxSwapWs {
                 access_key = value.parse().unwrap();
             } else if key == "secret_key" {
                 secret_key = value.parse().unwrap();
-            } else if key == "passphrase" {
+            } else if key == "pass_key" {
                 passphrase = value.parse().unwrap();
             }
         }

+ 14 - 17
exchanges/tests/okx_swap_test.rs

@@ -10,13 +10,14 @@ use exchanges::binance_swap_ws::{BinanceSubscribeType, BinanceSwapWs, BinanceWsT
 use exchanges::coinex_swap_rest::CoinexSwapRest;
 use exchanges::kucoin_swap_rest::KucoinSwapRest;
 use exchanges::kucoin_swap_ws::{KucoinSubscribeType, KucoinSwapWs, KucoinWsType};
+use exchanges::okx_swap_rest::OkxSwapRest;
 use exchanges::okx_swap_ws::{OkxSubscribeType, OkxSwapWs, OkxWsType};
 use exchanges::proxy;
 use exchanges::response_base::ResponseData;
 
-const ACCESS_KEY: &str = "";
-const SECRET_KEY: &str = "";
-const PASS_KEY: &str = "";
+const ACCESS_KEY: &str = "b812814f-b792-432c-9c65-44ebe3b8976b";
+const SECRET_KEY: &str = "D6AF4764DF5FDC74BF2CC88A4A8FD035";
+const PASS_KEY: &str = "Astest!@#1";
 
 
 //ws-订阅公共频道信息
@@ -28,7 +29,7 @@ async fn ws_custom_subscribe_pu() {
     let mut btree_map: BTreeMap<String, String> = BTreeMap::new();
     btree_map.insert("access_key".to_string(), ACCESS_KEY.to_string());
     btree_map.insert("secret_key".to_string(), SECRET_KEY.to_string());
-    btree_map.insert("passphrase".to_string(), PASS_KEY.to_string());
+    btree_map.insert("pass_key".to_string(), PASS_KEY.to_string());
     let (tx, mut rx) = channel(1024);
     let mut ws = get_ws(btree_map, OkxWsType::Public, tx).await;
     ws.set_subscribe(vec![
@@ -57,7 +58,6 @@ async fn ws_custom_subscribe_pu() {
 #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
 async fn ws_custom_subscribe_bu() {
     global::log_utils::init_log_with_trace();
-
 }
 
 //ws-订阅私有频道信息
@@ -70,7 +70,7 @@ async fn ws_custom_subscribe_pr() {
 
     btree_map.insert("access_key".to_string(), ACCESS_KEY.to_string());
     btree_map.insert("secret_key".to_string(), SECRET_KEY.to_string());
-    btree_map.insert("passphrase".to_string(), PASS_KEY.to_string());
+    btree_map.insert("pass_key".to_string(), PASS_KEY.to_string());
 
     let (tx, mut rx) = channel(1024);
     let mut ws = get_ws(btree_map, OkxWsType::Private, tx).await;
@@ -78,7 +78,6 @@ async fn ws_custom_subscribe_pr() {
         OkxSubscribeType::PrBalanceAndPosition,
         OkxSubscribeType::PrAccount("USDT".to_string()),
         OkxSubscribeType::PrOrders,
-
     ]);
 
     let t1 = tokio::spawn(async move {
@@ -95,14 +94,14 @@ async fn ws_custom_subscribe_pr() {
     try_join!(t1,t2).unwrap();
 }
 
-
-//rest-用戶持倉
+//rest-订单查询
 #[tokio::test]
-async fn rest_get_server_time_test() {
+async fn rest_get_order_test() {
     global::log_utils::init_log_with_trace();
 
-    let e = ResponseData::error("12".to_string(), "登陆参数错误!".to_string());
-    println!("{}", e.to_string())
+    let mut ret = get_rest();
+    let req_data = ret.get_order("BTC-USDT".to_string(), "".to_string(), "".to_string()).await;
+    println!("okx--订单查询--{:?}", req_data);
 }
 
 
@@ -111,14 +110,12 @@ async fn get_ws(btree_map: BTreeMap<String, String>, type_v: OkxWsType, tx: Send
     ku_ws
 }
 
-fn get_rest() -> CoinexSwapRest {
+fn get_rest() -> OkxSwapRest {
     let mut btree_map: BTreeMap<String, String> = BTreeMap::new();
-    // btree_map.insert("access_key".to_string(), ACCESS_KEY.to_string());
-    // btree_map.insert("secret_key".to_string(), SECRET_KEY.to_string());
     btree_map.insert("access_key".to_string(), ACCESS_KEY.to_string());
     btree_map.insert("secret_key".to_string(), SECRET_KEY.to_string());
     btree_map.insert("pass_key".to_string(), PASS_KEY.to_string());
 
-    let mut co_exc = CoinexSwapRest::new(false, btree_map);
-    co_exc
+    let mut okx_exc = OkxSwapRest::new(false, btree_map.clone());
+    okx_exc
 }