Przeglądaj źródła

bybit rest新增 接口

hl 1 rok temu
rodzic
commit
e2cc07bf3b

+ 5 - 2
exchanges/src/bybit_swap_rest.rs

@@ -131,13 +131,16 @@ impl BybitSwapRest {
     }
 
     //查看持仓信息
-    pub async fn get_positions(&mut self, symbol: String) -> ResponseData {
+    pub async fn get_positions(&mut self, symbol: String, settle_coin: String) -> ResponseData {
         let mut params = serde_json::json!({
             "category":"linear",
          });
         if symbol.len() > 0 {
             params.as_object_mut().unwrap().insert("symbol".parse().unwrap(), serde_json::Value::from(symbol));
         }
+        if settle_coin.len() > 0 {
+            params.as_object_mut().unwrap().insert("settleCoin".parse().unwrap(), serde_json::Value::from(settle_coin));
+        }
         let data = self.request("GET".to_string(),
                                 "/v5".to_string(),
                                 "/position/list".to_string(),
@@ -250,7 +253,7 @@ impl BybitSwapRest {
 
     //撤銷所有訂單
     pub async fn cancel_orders(&mut self, symbol: String) -> ResponseData {
-        let  params = serde_json::json!({
+        let params = serde_json::json!({
              "category": "linear",
              "symbol": symbol,
          });

+ 6 - 6
exchanges/tests/bybit_swap_test.rs

@@ -29,7 +29,6 @@ async fn ws_custom_subscribe_pu() {
         // BybitSwapSubscribeType::PuOrderBook50,
         // BybitSwapSubscribeType::PuBlicTrade,
         BybitSwapSubscribeType::PuTickers,
-
     ]);
 
 
@@ -93,9 +92,9 @@ async fn ws_custom_subscribe_pr() {
     let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
     let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded();
 
-    let logparam = BybitSwapLogin{
-        api_key:ACCESS_KEY.to_string(),
-        secret_key :SECRET_KEY.to_string(),
+    let logparam = BybitSwapLogin {
+        api_key: ACCESS_KEY.to_string(),
+        secret_key: SECRET_KEY.to_string(),
     };
 
     let mut ws = get_ws(Option::from(logparam), BybitSwapWsType::Private).await;
@@ -168,6 +167,7 @@ async fn rest_get_server_time_test() {
     let req_data = ret.get_server_time().await;
     println!("Bybit--服務器時間--{:?}", req_data);
 }
+
 //rest-查詢最新行情信息
 #[tokio::test]
 async fn rest_get_tickers_test() {
@@ -177,6 +177,7 @@ async fn rest_get_tickers_test() {
     let req_data = ret.get_tickers("DOGEUSDT".to_string()).await;
     println!("Bybit--查詢最新行情信息--{:?}", req_data);
 }
+
 //rest-查詢市場價格K線數據
 #[tokio::test]
 async fn rest_get_kline_test() {
@@ -225,7 +226,7 @@ async fn rest_get_positions_test() {
     global::log_utils::init_log_with_trace();
 
     let mut ret = get_rest();
-    let req_data = ret.get_positions("DOGEUSDT".to_string()).await;
+    let req_data = ret.get_positions("DOGEUSDT".to_string(), "".to_string()).await;
     println!("Bybit--查看持仓信息--{:?}", req_data);
 }
 
@@ -304,7 +305,6 @@ async fn rest_cancel_orders_test() {
 }
 
 
-
 async fn get_ws(btree_map: Option<BybitSwapLogin>, type_v: BybitSwapWsType) -> BybitSwapWs {
     let ku_ws = BybitSwapWs::new(false, btree_map, type_v);
     ku_ws