JiahengHe преди 1 година
родител
ревизия
bea2dbced7
променени са 4 файла, в които са добавени 12 реда и са изтрити 22 реда
  1. 7 7
      standard/src/bybit_swap.rs
  2. 2 9
      standard/src/bybit_swap_handle.rs
  3. 3 3
      standard/src/handle_info.rs
  4. 0 3
      strategy/src/bybit_usdt_swap.rs

+ 7 - 7
standard/src/bybit_swap.rs

@@ -4,12 +4,12 @@ use std::str::FromStr;
 use tokio::sync::mpsc::Sender;
 use tokio::sync::mpsc::Sender;
 use async_trait::async_trait;
 use async_trait::async_trait;
 use rust_decimal::Decimal;
 use rust_decimal::Decimal;
-use rust_decimal::prelude::{FromPrimitive, ToPrimitive};
 use serde_json::{from_str, from_value, json, Value};
 use serde_json::{from_str, from_value, json, Value};
 use futures::stream::FuturesUnordered;
 use futures::stream::FuturesUnordered;
 use futures::{TryStreamExt};
 use futures::{TryStreamExt};
+use rust_decimal::prelude::FromPrimitive;
 use serde::{Deserialize, Serialize};
 use serde::{Deserialize, Serialize};
-use tracing::{error, debug, trace, info};
+use tracing::{error, debug, trace};
 use exchanges::bybit_swap_rest::BybitSwapRest;
 use exchanges::bybit_swap_rest::BybitSwapRest;
 use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order, OrderCommand, PositionModeEnum};
 use crate::{Platform, ExchangeEnum, Account, Position, Ticker, Market, Order, OrderCommand, PositionModeEnum};
 use global::trace_stack::TraceStack;
 use global::trace_stack::TraceStack;
@@ -205,7 +205,7 @@ impl Platform for BybitSwap {
     }
     }
 
 
     async fn get_ticker_symbol(&mut self, symbol: String) -> Result<Ticker, Error> {
     async fn get_ticker_symbol(&mut self, symbol: String) -> Result<Ticker, Error> {
-        let symbol_upper = self.symbol_uppercase.clone();
+        let symbol_upper = symbol.replace("_", "").to_uppercase();
         let res_data = self.request.get_tickers(symbol_upper.clone()).await;
         let res_data = self.request.get_tickers(symbol_upper.clone()).await;
         if res_data.code == "200" {
         if res_data.code == "200" {
             let res_data_str = &res_data.data;
             let res_data_str = &res_data.data;
@@ -287,7 +287,7 @@ impl Platform for BybitSwap {
     }
     }
 
 
     async fn get_market_symbol(&mut self, symbol: String) -> Result<Market, Error> {
     async fn get_market_symbol(&mut self, symbol: String) -> Result<Market, Error> {
-        let symbol = self.symbol_uppercase.clone();
+        let symbol = symbol.replace("_", "").to_uppercase();
         let res_data = self.request.get_instruments_info(symbol.clone()).await;
         let res_data = self.request.get_instruments_info(symbol.clone()).await;
         if res_data.code == "200" {
         if res_data.code == "200" {
             let res_data_str = &res_data.data;
             let res_data_str = &res_data.data;
@@ -355,7 +355,7 @@ impl Platform for BybitSwap {
         }
         }
     }
     }
     // 获取订单列表
     // 获取订单列表
-    async fn get_orders_list(&mut self, status: &str) -> Result<Vec<Order>, Error> {
+    async fn get_orders_list(&mut self, _status: &str) -> Result<Vec<Order>, Error> {
        Err(Error::new(ErrorKind::Other, "bybit获取订单列表暂未实现".to_string()))
        Err(Error::new(ErrorKind::Other, "bybit获取订单列表暂未实现".to_string()))
     }
     }
     // 下单接口
     // 下单接口
@@ -537,7 +537,7 @@ impl Platform for BybitSwap {
     async fn set_auto_deposit_status(&mut self, _status: bool) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate:该交易所方法未实现".to_string())) }
     async fn set_auto_deposit_status(&mut self, _status: bool) -> Result<String, Error> { Err(Error::new(ErrorKind::NotFound, "gate:该交易所方法未实现".to_string())) }
 
 
     // 交易账户互转
     // 交易账户互转
-    async fn wallet_transfers(&mut self, coin: &str, from: &str, to: &str, amount: Decimal) -> Result<String, Error> {
+    async fn wallet_transfers(&mut self, _coin: &str, _from: &str, _to: &str, _amount: Decimal) -> Result<String, Error> {
         // let coin_format = coin.to_string().to_lowercase();
         // let coin_format = coin.to_string().to_lowercase();
         // let res_data = self.request.wallet_transfers(coin_format.clone(), from.to_string(), to.to_string(), amount.to_string(), coin_format.clone()).await;
         // let res_data = self.request.wallet_transfers(coin_format.clone(), from.to_string(), to.to_string(), amount.to_string(), coin_format.clone()).await;
         // if res_data.code == "200" {
         // if res_data.code == "200" {
@@ -742,7 +742,7 @@ pub fn format_order_item(order: Value, ct_val: Decimal) -> Order {
     if !order.get("qty").is_some() {
     if !order.get("qty").is_some() {
         size = Decimal::from_str(size_str.as_str()).unwrap();
         size = Decimal::from_str(size_str.as_str()).unwrap();
         let right_val = Decimal::from_str(order["cumExecValue"].as_str().unwrap()).unwrap();
         let right_val = Decimal::from_str(order["cumExecValue"].as_str().unwrap()).unwrap();
-        let mut right = Decimal::from_str(right_str.as_str()).unwrap();
+        let right = Decimal::from_str(right_str.as_str()).unwrap();
         if right != Decimal::ZERO {
         if right != Decimal::ZERO {
             avg_price = right_val / right;
             avg_price = right_val / right;
         }
         }

+ 2 - 9
standard/src/bybit_swap_handle.rs

@@ -3,12 +3,10 @@ use rust_decimal::Decimal;
 use rust_decimal_macros::dec;
 use rust_decimal_macros::dec;
 use serde_json::{from_str, from_value};
 use serde_json::{from_str, from_value};
 use toml::Value;
 use toml::Value;
-use tracing::{debug, error, info};
+use tracing::{debug, error};
 use exchanges::response_base::ResponseData;
 use exchanges::response_base::ResponseData;
 use global::trace_stack::TraceStack;
 use global::trace_stack::TraceStack;
 use crate::{Account, MarketOrder, Order, Position, PositionModeEnum, SpecialDepth, SpecialOrder, SpecialTicker};
 use crate::{Account, MarketOrder, Order, Position, PositionModeEnum, SpecialDepth, SpecialOrder, SpecialTicker};
-use crate::exchange::ExchangeEnum;
-use crate::handle_info::HandleSwapInfo;
 
 
 // 处理账号信息
 // 处理账号信息
 pub fn handle_account_info(res_data: ResponseData, symbol: String) -> Account {
 pub fn handle_account_info(res_data: ResponseData, symbol: String) -> Account {
@@ -120,7 +118,7 @@ pub fn format_order_item(order: serde_json::Value, ct_val: Decimal) -> Order {
     let status = order["orderStatus"].as_str().unwrap_or("");
     let status = order["orderStatus"].as_str().unwrap_or("");
     let text = order["orderLinkId"].as_str().unwrap_or("");
     let text = order["orderLinkId"].as_str().unwrap_or("");
     let size = Decimal::from_str(order["qty"].as_str().unwrap()).unwrap();
     let size = Decimal::from_str(order["qty"].as_str().unwrap()).unwrap();
-    let mut right = Decimal::from_str(order["cumExecQty"].as_str().unwrap()).unwrap();
+    let right = Decimal::from_str(order["cumExecQty"].as_str().unwrap()).unwrap();
     let right_val = Decimal::from_str(order["cumExecValue"].as_str().unwrap()).unwrap();
     let right_val = Decimal::from_str(order["cumExecValue"].as_str().unwrap()).unwrap();
     let price = Decimal::from_str(order["price"].as_str().unwrap()).unwrap();
     let price = Decimal::from_str(order["price"].as_str().unwrap()).unwrap();
     let amount = size * ct_val;
     let amount = size * ct_val;
@@ -177,11 +175,6 @@ pub fn format_special_ticker(data: serde_json::Value, label: String) -> SpecialD
     }
     }
 }
 }
 
 
-// 处理特殊深度数据
-pub fn handle_special_depth(res_data: ResponseData) -> SpecialDepth {
-    HandleSwapInfo::handle_special_depth(ExchangeEnum::BybitSwap, res_data)
-}
-
 pub fn format_depth_items(value: serde_json::Value) -> Vec<MarketOrder> {
 pub fn format_depth_items(value: serde_json::Value) -> Vec<MarketOrder> {
     let mut depth_items: Vec<MarketOrder> = vec![];
     let mut depth_items: Vec<MarketOrder> = vec![];
     for val in value.as_array().unwrap() {
     for val in value.as_array().unwrap() {

+ 3 - 3
standard/src/handle_info.rs

@@ -3,7 +3,7 @@ use std::str::FromStr;
 use rust_decimal::{Decimal};
 use rust_decimal::{Decimal};
 use rust_decimal::prelude::FromPrimitive;
 use rust_decimal::prelude::FromPrimitive;
 use rust_decimal_macros::dec;
 use rust_decimal_macros::dec;
-use tracing::{error, info};
+use tracing::{error};
 use exchanges::response_base::ResponseData;
 use exchanges::response_base::ResponseData;
 use global::public_params;
 use global::public_params;
 use crate::exchange::ExchangeEnum;
 use crate::exchange::ExchangeEnum;
@@ -230,8 +230,8 @@ pub fn make_special_depth(label: String, depth_asks: &mut Vec<MarketOrder>, dept
 pub fn format_depth(exchange: ExchangeEnum, res_data: ResponseData) -> DepthParam{
 pub fn format_depth(exchange: ExchangeEnum, res_data: ResponseData) -> DepthParam{
     let res_data_str = res_data.data;
     let res_data_str = res_data.data;
     let res_data_json: serde_json::Value = serde_json::from_str(&*res_data_str).unwrap();
     let res_data_json: serde_json::Value = serde_json::from_str(&*res_data_str).unwrap();
-    let mut depth_asks: Vec<MarketOrder>;
-    let mut depth_bids: Vec<MarketOrder>;
+    let depth_asks: Vec<MarketOrder>;
+    let depth_bids: Vec<MarketOrder>;
     let t: Decimal;
     let t: Decimal;
     let create_at: i64;
     let create_at: i64;
     match exchange {
     match exchange {

+ 0 - 3
strategy/src/bybit_usdt_swap.rs

@@ -1,14 +1,11 @@
 use std::cmp::Ordering;
 use std::cmp::Ordering;
 use std::collections::BTreeMap;
 use std::collections::BTreeMap;
-use std::net::IpAddr::V4;
 use std::sync::Arc;
 use std::sync::Arc;
 use std::sync::atomic::AtomicBool;
 use std::sync::atomic::AtomicBool;
-use futures_util::future::err;
 use futures_util::StreamExt;
 use futures_util::StreamExt;
 use rust_decimal::Decimal;
 use rust_decimal::Decimal;
 use tokio::spawn;
 use tokio::spawn;
 use tokio::sync::Mutex;
 use tokio::sync::Mutex;
-use tracing::info;
 use exchanges::bybit_swap_ws::{BybitSwapLogin, BybitSwapSubscribeType, BybitSwapWs, BybitSwapWsType};
 use exchanges::bybit_swap_ws::{BybitSwapLogin, BybitSwapSubscribeType, BybitSwapWs, BybitSwapWsType};
 use exchanges::response_base::ResponseData;
 use exchanges::response_base::ResponseData;
 use global::trace_stack::TraceStack;
 use global::trace_stack::TraceStack;