|
|
@@ -1,715 +0,0 @@
|
|
|
-use std::collections::{BTreeMap};
|
|
|
-use std::io::{Error};
|
|
|
-use std::sync::Arc;
|
|
|
-use std::sync::atomic::AtomicBool;
|
|
|
-use rust_decimal::Decimal;
|
|
|
-use tokio::sync::mpsc::{channel, Receiver, Sender};
|
|
|
-use tokio::sync::Mutex;
|
|
|
-use tracing::{error, trace};
|
|
|
-// use exchanges::binance_spot_ws::{BinanceSpotLogin, BinanceSpotSubscribeType, BinanceSpotWs, BinanceSpotWsType};
|
|
|
-use exchanges::binance_swap_ws::{BinanceSwapLogin, BinanceSwapSubscribeType, BinanceSwapWs, BinanceSwapWsType};
|
|
|
-// use exchanges::kucoin_swap_ws::{KucoinSwapLogin, KucoinSwapSubscribeType, KucoinSwapWs, KucoinSwapWsType};
|
|
|
-// use exchanges::kucoin_spot_ws::{KucoinSpotLogin, KucoinSpotSubscribeType, KucoinSpotWs, KucoinSpotWsType};
|
|
|
-// use exchanges::gate_swap_ws::{GateSwapLogin, GateSwapSubscribeType, GateSwapWs, GateSwapWsType};
|
|
|
-// use exchanges::bitget_spot_ws::{BitgetSpotLogin, BitgetSpotSubscribeType, BitgetSpotWs, BitgetSpotWsType};
|
|
|
-// use exchanges::okx_swap_ws::{OkxSwapLogin, OkxSwapSubscribeType, OkxSwapWs, OkxSwapWsType};
|
|
|
-// use exchanges::htx_swap_ws::{HtxSwapLogin, HtxSwapSubscribeType, HtxSwapWs, HtxSwapWsType};
|
|
|
-use exchanges::response_base::ResponseData;
|
|
|
-use standard::exchange::{Exchange, ExchangeEnum};
|
|
|
-// use standard::{binance_spot_handle, Order, Platform, utils};
|
|
|
-use standard::{Order, Platform, utils};
|
|
|
-use standard::exchange_struct_handler::ExchangeStructHandler;
|
|
|
-// use standard::{kucoin_handle, Order, Platform, utils};
|
|
|
-// use standard::{kucoin_spot_handle, Order, Platform, utils};
|
|
|
-// use standard::{gate_swap_handle, handle_info, Order, Platform, utils};
|
|
|
-// use standard::{bitget_spot_handle, Order, Platform, utils};
|
|
|
-// use standard::{okx_handle, Order, Platform, utils};
|
|
|
-// use standard::{htx_swap_handle, handle_info, Order, Platform, utils};
|
|
|
-
|
|
|
-// 创建实体
|
|
|
-#[allow(dead_code)]
|
|
|
-pub async fn test_new_exchange(exchange: ExchangeEnum, symbol: &str) -> Box<dyn Platform> {
|
|
|
- utils::proxy_handle(None);
|
|
|
- let (order_sender, _order_receiver): (Sender<Order>, Receiver<Order>) = channel(1024);
|
|
|
- let (error_sender, _error_receiver): (Sender<Error>, Receiver<Error>) = channel(1024);
|
|
|
-
|
|
|
- let account_info = global::account_info::get_account_info("../test_account.toml");
|
|
|
- match exchange {
|
|
|
- ExchangeEnum::BinanceSwap => {
|
|
|
- let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- let access_key = account_info.binance_access_key;
|
|
|
- let secret_key = account_info.binance_secret_key;
|
|
|
- params.insert("access_key".to_string(), access_key);
|
|
|
- params.insert("secret_key".to_string(), secret_key);
|
|
|
- Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- }
|
|
|
- // ExchangeEnum::BinanceSpot => {
|
|
|
- // let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- // let access_key = account_info.binance_access_key;
|
|
|
- // let secret_key = account_info.binance_secret_key;
|
|
|
- // params.insert("access_key".to_string(), access_key);
|
|
|
- // params.insert("secret_key".to_string(), secret_key);
|
|
|
- // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- // }
|
|
|
- ExchangeEnum::GateSwap => {
|
|
|
- let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- let access_key = account_info.gate_access_key;
|
|
|
- let secret_key = account_info.gate_secret_key;
|
|
|
- params.insert("access_key".to_string(), access_key);
|
|
|
- params.insert("secret_key".to_string(), secret_key);
|
|
|
- Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- }
|
|
|
- // ExchangeEnum::GateSpot => {
|
|
|
- // let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- // let access_key = account_info.gate_access_key;
|
|
|
- // let secret_key = account_info.gate_secret_key;
|
|
|
- // params.insert("access_key".to_string(), access_key);
|
|
|
- // params.insert("secret_key".to_string(), secret_key);
|
|
|
- // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- // }
|
|
|
- // ExchangeEnum::KucoinSwap => {
|
|
|
- // let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- // let access_key = account_info.kucoin_access_key;
|
|
|
- // let secret_key = account_info.kucoin_secret_key;
|
|
|
- // let pass_key = account_info.kucoin_pass;
|
|
|
- // params.insert("access_key".to_string(), access_key);
|
|
|
- // params.insert("secret_key".to_string(), secret_key);
|
|
|
- // params.insert("pass_key".to_string(), pass_key);
|
|
|
- // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- // }
|
|
|
- // ExchangeEnum::KucoinSpot => {
|
|
|
- // let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- // let access_key = account_info.kucoin_access_key;
|
|
|
- // let secret_key = account_info.kucoin_secret_key;
|
|
|
- // let pass_key = account_info.kucoin_pass;
|
|
|
- // params.insert("access_key".to_string(), access_key);
|
|
|
- // params.insert("secret_key".to_string(), secret_key);
|
|
|
- // params.insert("pass_key".to_string(), pass_key);
|
|
|
- // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- // }
|
|
|
- // ExchangeEnum::OkxSwap => {
|
|
|
- // let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- // let access_key = account_info.okx_access_key;
|
|
|
- // let secret_key = account_info.okx_secret_key;
|
|
|
- // let pass_key = account_info.okx_pass;
|
|
|
- // params.insert("access_key".to_string(), access_key);
|
|
|
- // params.insert("secret_key".to_string(), secret_key);
|
|
|
- // params.insert("pass_key".to_string(), pass_key);
|
|
|
- // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- // }
|
|
|
- // ExchangeEnum::BitgetSpot => {
|
|
|
- // let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- // let access_key = account_info.bitget_access_key;
|
|
|
- // let secret_key = account_info.bitget_secret_key;
|
|
|
- // let pass_key = account_info.bitget_pass;
|
|
|
- // params.insert("access_key".to_string(), access_key);
|
|
|
- // params.insert("secret_key".to_string(), secret_key);
|
|
|
- // params.insert("pass_key".to_string(), pass_key);
|
|
|
- // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- // }
|
|
|
- ExchangeEnum::BitgetSwap => {
|
|
|
- let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- let access_key = account_info.bitget_access_key;
|
|
|
- let secret_key = account_info.bitget_secret_key;
|
|
|
- let pass_key = account_info.bitget_pass;
|
|
|
- params.insert("access_key".to_string(), access_key);
|
|
|
- params.insert("secret_key".to_string(), secret_key);
|
|
|
- params.insert("pass_key".to_string(), pass_key);
|
|
|
- Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- }
|
|
|
- ExchangeEnum::BybitSwap => {
|
|
|
- let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- let access_key = account_info.bybit_access_key;
|
|
|
- let secret_key = account_info.bybit_secret_key;
|
|
|
- params.insert("access_key".to_string(), access_key);
|
|
|
- params.insert("secret_key".to_string(), secret_key);
|
|
|
- Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- }
|
|
|
- // ExchangeEnum::HtxSwap => {
|
|
|
- // let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
- // let access_key = account_info.htx_access_key;
|
|
|
- // let secret_key = account_info.htx_secret_key;
|
|
|
- // let pass_key = account_info.htx_pass;
|
|
|
- // params.insert("access_key".to_string(), access_key);
|
|
|
- // params.insert("secret_key".to_string(), secret_key);
|
|
|
- // params.insert("pass_key".to_string(), pass_key);
|
|
|
- // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
|
|
|
- // }
|
|
|
- _ => {
|
|
|
- panic!("该交易所未实现!")
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-#[allow(dead_code)]
|
|
|
-pub async fn test_new_exchange_wss<T>(exchange: ExchangeEnum, symbol: &str, subscriber_type: T, mold: &str)
|
|
|
-where
|
|
|
- Vec<BinanceSwapSubscribeType>: From<T>,
|
|
|
-{
|
|
|
- utils::proxy_handle(None);
|
|
|
- let account_info = global::account_info::get_account_info("../test_account.toml");
|
|
|
- match exchange {
|
|
|
- // ExchangeEnum::BinanceSpot => {
|
|
|
- // let symbol_format = utils::format_symbol(symbol.to_string(), "").to_uppercase();
|
|
|
- // trace!(symbol_format);
|
|
|
- // let name = format!("binance_spot@{}", symbol.to_string().to_lowercase());
|
|
|
- // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
|
|
|
- // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
|
|
|
- // let write_tx_am = Arc::new(Mutex::new(write_tx));
|
|
|
- // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
|
|
|
- //
|
|
|
- // let params = BinanceSpotLogin {
|
|
|
- // api_key: account_info.binance_access_key,
|
|
|
- // api_secret: account_info.binance_secret_key,
|
|
|
- // };
|
|
|
- // let mut exchange_wss;
|
|
|
- // exchange_wss = BinanceSpotWs::new_label(name, false, Option::from(params), BinanceSpotWsType::PublicAndPrivate);
|
|
|
- // exchange_wss.set_symbols(vec![symbol_format]);
|
|
|
- // exchange_wss.set_subscribe(subscriber_type.into());
|
|
|
- //
|
|
|
- //
|
|
|
- // let mold_arc = Arc::new(mold.to_string());
|
|
|
- // //读取
|
|
|
- // tokio::spawn(async move {
|
|
|
- // let mold_clone = Arc::clone(&mold_arc);
|
|
|
- // loop {
|
|
|
- // if let Some(data) = read_rx.next().await {
|
|
|
- // trace!("原始数据 data:{:?}",data);
|
|
|
- // match mold_clone.as_str() {
|
|
|
- // "depth" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = binance_spot_handle::handle_special_depth(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "ticker" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = binance_spot_handle::handle_special_ticker(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // _ => {
|
|
|
- // error!("没有该命令!mode={}", mold_clone);
|
|
|
- // panic!("没有该命令!mode={}", mold_clone)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // };
|
|
|
- // });
|
|
|
- //
|
|
|
- // let t1 = tokio::spawn(async move {
|
|
|
- // //链接
|
|
|
- // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
|
|
|
- // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
|
|
|
- // });
|
|
|
- // try_join!(t1).unwrap();
|
|
|
- // }
|
|
|
- ExchangeEnum::BinanceSwap => {
|
|
|
- let symbol_format = utils::format_symbol(symbol.to_string(), "").to_uppercase();
|
|
|
- trace!(symbol_format);
|
|
|
- let name = format!("binance_swap@{}", symbol.to_string().to_lowercase());
|
|
|
- let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
|
|
|
- let write_tx_am = Arc::new(Mutex::new(write_tx));
|
|
|
- let is_shutdown_arc = Arc::new(AtomicBool::new(true));
|
|
|
-
|
|
|
- let params = BinanceSwapLogin {
|
|
|
- api_key: account_info.binance_access_key,
|
|
|
- api_secret: account_info.binance_secret_key
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- let mut exchange_wss = if ["depth", "ticker","trade","record"].contains(&mold) {
|
|
|
- BinanceSwapWs::new_label(name, false, Option::from(params), BinanceSwapWsType::Public).await
|
|
|
- } else {
|
|
|
- BinanceSwapWs::new_label(name, false, Option::from(params), BinanceSwapWsType::Private).await
|
|
|
- };
|
|
|
- exchange_wss.set_symbols(vec![symbol_format.clone()]);
|
|
|
- exchange_wss.set_subscribe(subscriber_type.into());
|
|
|
- let bool_v3_clone = Arc::clone(&is_shutdown_arc);
|
|
|
- let mold_clone = mold.to_string().clone();
|
|
|
- let fun = move |data: ResponseData| {
|
|
|
- let symbol_format_c = symbol_format.clone();
|
|
|
- let mold_cc = mold_clone.clone();
|
|
|
-
|
|
|
- async move {
|
|
|
- trace!("原始数据 data:{:?}",data);
|
|
|
- match mold_cc.as_str() {
|
|
|
- "depth" => {
|
|
|
- if data.data != "" {
|
|
|
- let result = ExchangeStructHandler::order_book_handle(ExchangeEnum::BinanceSwap, &data, &Decimal::ONE);
|
|
|
- trace!("-------------------------------");
|
|
|
- trace!(?result)
|
|
|
- }
|
|
|
- }
|
|
|
- "ticker" => {
|
|
|
- if data.data != "" {
|
|
|
- let result = ExchangeStructHandler::book_ticker_handle(ExchangeEnum::BinanceSwap, &data, &Decimal::ONE);
|
|
|
- trace!("-------------------------------");
|
|
|
- trace!(?result)
|
|
|
- }
|
|
|
- }
|
|
|
- "trade" => {
|
|
|
- if data.data != "" {
|
|
|
- let result = ExchangeStructHandler::trades_handle(ExchangeEnum::BinanceSwap, &data, &Decimal::ONE);
|
|
|
- trace!("-------------------------------");
|
|
|
- trace!(?result)
|
|
|
- }
|
|
|
- }
|
|
|
- "record" => {
|
|
|
- if data.data != "" {
|
|
|
- let result = ExchangeStructHandler::records_handle(ExchangeEnum::BinanceSwap, &data);
|
|
|
- trace!("-------------------------------");
|
|
|
- trace!(?result)
|
|
|
- }
|
|
|
- }
|
|
|
- "account" => {
|
|
|
- if data.data != "" {
|
|
|
- if data.channel != "ACCOUNT_UPDATE" { return; };
|
|
|
- let result = ExchangeStructHandler::account_info_handle(ExchangeEnum::BinanceSwap, &data, &symbol_format_c);
|
|
|
- trace!("-------------------------------");
|
|
|
- trace!(?result)
|
|
|
- }
|
|
|
- }
|
|
|
- "order" => {
|
|
|
- if data.data != "" {
|
|
|
- if data.channel != "ORDER_TRADE_UPDATE" { return; };
|
|
|
- let result = ExchangeStructHandler::order_handle(ExchangeEnum::BinanceSwap, &data, &Decimal::ONE);
|
|
|
- trace!("-------------------------------");
|
|
|
- trace!(?result)
|
|
|
- }
|
|
|
- }
|
|
|
- "position" => {
|
|
|
- if data.data != "" {
|
|
|
- if data.channel != "ACCOUNT_UPDATE" { return; };
|
|
|
- let result = ExchangeStructHandler::position_handle(ExchangeEnum::BinanceSwap, &data, &Decimal::ONE);
|
|
|
- trace!("-------------------------------");
|
|
|
- trace!(?result)
|
|
|
- }
|
|
|
- }
|
|
|
- _ => {
|
|
|
- error!("没有该命令!mode={}", mold_cc);
|
|
|
- panic!("没有该命令!mode={}", mold_cc)
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
- };
|
|
|
- exchange_wss.ws_connect_async(bool_v3_clone, fun, &write_tx_am, write_rx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
|
|
|
- }
|
|
|
- // ExchangeEnum::KucoinSwap => {
|
|
|
- // let symbol_format = format!("{}M", utils::format_symbol(symbol.to_string(), ""));
|
|
|
- // let symbol_back = utils::format_symbol(symbol.to_string(), "_");
|
|
|
- //
|
|
|
- // let name = format!("kucoin_swap@{}", symbol.to_string().to_lowercase());
|
|
|
- // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
|
|
|
- // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
|
|
|
- // let write_tx_am = Arc::new(Mutex::new(write_tx));
|
|
|
- // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
|
|
|
- //
|
|
|
- // let params = KucoinSwapLogin {
|
|
|
- // access_key: account_info.kucoin_access_key,
|
|
|
- // secret_key: account_info.kucoin_secret_key,
|
|
|
- // pass_key: account_info.kucoin_pass,
|
|
|
- // };
|
|
|
- // let mut exchange_wss;
|
|
|
- // if ["depth", "ticker"].contains(&mold) {
|
|
|
- // exchange_wss = KucoinSwapWs::new_label(name, false, Option::from(params), KucoinSwapWsType::Public).await;
|
|
|
- // } else {
|
|
|
- // exchange_wss = KucoinSwapWs::new_label(name, false, Option::from(params), KucoinSwapWsType::Private).await;
|
|
|
- // }
|
|
|
- // exchange_wss.set_symbols(vec![symbol_format]);
|
|
|
- // exchange_wss.set_subscribe(subscriber_type.into());
|
|
|
- //
|
|
|
- // let mold_arc = Arc::new(mold.to_string());
|
|
|
- // tokio::spawn(async move {
|
|
|
- // let mold_clone = Arc::clone(&mold_arc);
|
|
|
- // loop {
|
|
|
- // if let Some(data) = read_rx.next().await {
|
|
|
- // trace!("原始数据 data:{:?}",data);
|
|
|
- // match mold_clone.as_str() {
|
|
|
- // "depth" => {
|
|
|
- // let result = kucoin_handle::handle_special_depth(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // "ticker" => {
|
|
|
- // let result = kucoin_handle::handle_special_ticker(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // "account" => {
|
|
|
- // let result = kucoin_handle::handle_account_info(data, symbol_back.clone());
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // "position" => {
|
|
|
- // let result = kucoin_handle::handle_position(data, dec!(1));
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // "orders" => {
|
|
|
- // let result = kucoin_handle::handle_order(data, dec!(0.001));
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // _ => {
|
|
|
- // error!("没有该命令!mode={}", mold_clone);
|
|
|
- // panic!("没有该命令!mode={}", mold_clone)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- //
|
|
|
- // let t1 = tokio::spawn(async move {
|
|
|
- // //链接
|
|
|
- // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
|
|
|
- // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
|
|
|
- // });
|
|
|
- // try_join!(t1).unwrap();
|
|
|
- // }
|
|
|
- // ExchangeEnum::KucoinSpot => {
|
|
|
- // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
|
|
|
- // let symbol_back = utils::format_symbol(symbol.to_string(), "_");
|
|
|
- // trace!(symbol_format);
|
|
|
- // let name = format!("kucoin_spot@{}", symbol.to_string().to_lowercase());
|
|
|
- // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
|
|
|
- // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
|
|
|
- // let write_tx_am = Arc::new(Mutex::new(write_tx));
|
|
|
- // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
|
|
|
- //
|
|
|
- // let params = KucoinSpotLogin {
|
|
|
- // access_key: account_info.kucoin_access_key,
|
|
|
- // secret_key: account_info.kucoin_secret_key,
|
|
|
- // pass_key: account_info.kucoin_pass,
|
|
|
- // };
|
|
|
- // let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
|
|
|
- // KucoinSpotWs::new_label(name, false, Option::from(params), KucoinSpotWsType::Public).await
|
|
|
- // } else {
|
|
|
- // KucoinSpotWs::new_label(name, false, Option::from(params), KucoinSpotWsType::Private).await
|
|
|
- // };
|
|
|
- // exchange_wss.set_symbols(vec![symbol_format]);
|
|
|
- // exchange_wss.set_subscribe(subscriber_type.into());
|
|
|
- //
|
|
|
- // let mold_arc = Arc::new(mold.to_string());
|
|
|
- // tokio::spawn(async move {
|
|
|
- // let mold_clone = Arc::clone(&mold_arc);
|
|
|
- // loop {
|
|
|
- // if let Some(data) = read_rx.next().await {
|
|
|
- // trace!("原始数据 data:{:?}",data);
|
|
|
- // match mold_clone.as_str() {
|
|
|
- // "depth" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = kucoin_spot_handle::handle_special_depth(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "ticker" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = kucoin_spot_handle::handle_special_ticker(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "account" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = kucoin_spot_handle::handle_account_info(data, symbol_back.clone());
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "orders" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = kucoin_spot_handle::handle_order(data, dec!(1));
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // _ => {
|
|
|
- // error!("没有该命令!mode={}", mold_clone);
|
|
|
- // panic!("没有该命令!mode={}", mold_clone)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- // let t1 = tokio::spawn(async move {
|
|
|
- // //链接
|
|
|
- // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
|
|
|
- // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
|
|
|
- // });
|
|
|
- // try_join!(t1).unwrap();
|
|
|
- // }
|
|
|
- ExchangeEnum::GateSwap => {
|
|
|
- // let symbol_format = utils::format_symbol(symbol.to_string(), "_").to_uppercase();
|
|
|
- // trace!(symbol_format);
|
|
|
- // let name = format!("gate_swap@{}", symbol.to_string().to_lowercase());
|
|
|
- // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
|
|
|
- // let write_tx_am = Arc::new(Mutex::new(write_tx));
|
|
|
- // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
|
|
|
- //
|
|
|
- // let params = GateSwapLogin {
|
|
|
- // api_key: account_info.gate_access_key,
|
|
|
- // secret: account_info.gate_secret_key,
|
|
|
- // };
|
|
|
- // let mut exchange_wss = GateSwapWs::new_label(name, false, Option::from(params), GateSwapWsType::PublicAndPrivate("usdt".to_string()));
|
|
|
- // exchange_wss.set_symbols(vec![symbol_format.clone()]);
|
|
|
- // exchange_wss.set_subscribe(subscriber_type.into());
|
|
|
- //
|
|
|
- // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
|
|
|
- // let mold_clone = mold.to_string().clone();
|
|
|
- // let fun = move |data: ResponseData| {
|
|
|
- // let symbol_format_c = symbol_format.clone();
|
|
|
- // let mold_cc = mold_clone.clone();
|
|
|
- //
|
|
|
- // async move {
|
|
|
- // trace!("原始数据 data:{:?}",data);
|
|
|
- // match mold_cc.as_str() {
|
|
|
- // "depth" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = handle_info::format_depth(ExchangeEnum::GateSwap, &data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "ticker" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = gate_swap_handle::handle_book_ticker(&data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "account" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = gate_swap_handle::handle_account_info(&data, &symbol_format_c);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "orders" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = gate_swap_handle::handle_order(data, dec!(1));
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // _ => {
|
|
|
- // error!("没有该命令!mode={}", mold_cc);
|
|
|
- // panic!("没有该命令!mode={}", mold_cc)
|
|
|
- // }
|
|
|
- // };
|
|
|
- // }
|
|
|
- // };
|
|
|
- // exchange_wss.ws_connect_async(bool_v3_clone, fun, &write_tx_am, write_rx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
|
|
|
- }
|
|
|
- // ExchangeEnum::BitgetSpot => {
|
|
|
- // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
|
|
|
- // let symbol_back = utils::format_symbol(symbol.to_string(), "_");
|
|
|
- // trace!(symbol_format);
|
|
|
- // let name = format!("bitget_spot@{}", symbol.to_string().to_lowercase());
|
|
|
- // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
|
|
|
- // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
|
|
|
- // let write_tx_am = Arc::new(Mutex::new(write_tx));
|
|
|
- // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
|
|
|
- //
|
|
|
- // let params = BitgetSpotLogin {
|
|
|
- // api_key: account_info.bitget_access_key,
|
|
|
- // secret_key: account_info.bitget_secret_key,
|
|
|
- // passphrase_key: account_info.bitget_pass,
|
|
|
- // };
|
|
|
- //
|
|
|
- // let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
|
|
|
- // BitgetSpotWs::new_label(name, false, Option::from(params), BitgetSpotWsType::Public)
|
|
|
- // } else {
|
|
|
- // BitgetSpotWs::new_label(name, false, Option::from(params), BitgetSpotWsType::Private)
|
|
|
- // };
|
|
|
- // exchange_wss.set_symbols(vec![symbol_format]);
|
|
|
- // exchange_wss.set_subscribe(subscriber_type.into());
|
|
|
- //
|
|
|
- // let mold_arc = Arc::new(mold.to_string());
|
|
|
- // //读取
|
|
|
- // tokio::spawn(async move {
|
|
|
- // loop {
|
|
|
- // let mold_clone = Arc::clone(&mold_arc);
|
|
|
- // if let Some(data) = read_rx.next().await {
|
|
|
- // trace!("原始数据 data:{:?}",data);
|
|
|
- // match mold_clone.as_str() {
|
|
|
- // "depth" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = bitget_spot_handle::handle_special_depth(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "ticker" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = bitget_spot_handle::handle_special_ticker(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "account" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = bitget_spot_handle::handle_account_info(data, symbol_back.clone());
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "orders" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = bitget_spot_handle::handle_order(data, dec!(1));
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // _ => {
|
|
|
- // error!("没有该命令!mode={}", mold_clone);
|
|
|
- // panic!("没有该命令!mode={}", mold_clone)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- // let t1 = tokio::spawn(async move {
|
|
|
- // //链接
|
|
|
- // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
|
|
|
- // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
|
|
|
- // });
|
|
|
- // try_join!(t1).unwrap();
|
|
|
- // }
|
|
|
- // ExchangeEnum::OkxSwap => {
|
|
|
- // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
|
|
|
- // trace!(symbol_format);
|
|
|
- // let name = format!("okx_swap@{}", symbol.to_string().to_lowercase());
|
|
|
- // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
|
|
|
- // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
|
|
|
- // let write_tx_am = Arc::new(Mutex::new(write_tx));
|
|
|
- // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
|
|
|
- //
|
|
|
- // let params = OkxSwapLogin {
|
|
|
- // api_key: account_info.okx_access_key,
|
|
|
- // secret_key: account_info.okx_secret_key,
|
|
|
- // passphrase: account_info.okx_pass,
|
|
|
- // };
|
|
|
- //
|
|
|
- // let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
|
|
|
- // OkxSwapWs::new_label(name, false, Option::from(params), OkxSwapWsType::Public)
|
|
|
- // } else if ["account", "orders", "position"].contains(&mold) {
|
|
|
- // OkxSwapWs::new_label(name, false, Option::from(params), OkxSwapWsType::Private)
|
|
|
- // } else {
|
|
|
- // OkxSwapWs::new_label(name, false, Option::from(params), OkxSwapWsType::Business)
|
|
|
- // };
|
|
|
- //
|
|
|
- // exchange_wss.set_symbols(vec![symbol_format.clone()]);
|
|
|
- // exchange_wss.set_subscribe(subscriber_type.into());
|
|
|
- //
|
|
|
- // let mold_arc = Arc::new(mold.to_string());
|
|
|
- // tokio::spawn(async move {
|
|
|
- // let mold_clone = Arc::clone(&mold_arc);
|
|
|
- // loop {
|
|
|
- // if let Some(data) = read_rx.next().await {
|
|
|
- // trace!("原始数据 data:{:?}",data);
|
|
|
- // match mold_clone.as_str() {
|
|
|
- // "depth" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = okx_handle::handle_special_depth(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "ticker" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = okx_handle::handle_special_ticker(data);
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "account" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = okx_handle::handle_account_info(data, symbol_format.clone());
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "position" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = okx_handle::handle_position(data, dec!(10));
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "orders" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = okx_handle::handle_order(data, dec!(10));
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // _ => {
|
|
|
- // error!("没有该命令!mode={}", mold_clone);
|
|
|
- // panic!("没有该命令!mode={}", mold_clone)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- //
|
|
|
- // let t1 = tokio::spawn(async move {
|
|
|
- // //链接
|
|
|
- // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
|
|
|
- // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
|
|
|
- // });
|
|
|
- // try_join!(t1).unwrap();
|
|
|
- // }
|
|
|
- // ExchangeEnum::HtxSwap => {
|
|
|
- // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
|
|
|
- // trace!(symbol_format);
|
|
|
- // let name = format!("htx_swap@{}", symbol.to_string().to_lowercase());
|
|
|
- // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
|
|
|
- // let write_tx_am = Arc::new(Mutex::new(write_tx));
|
|
|
- // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
|
|
|
- //
|
|
|
- // let params = HtxSwapLogin {
|
|
|
- // api_key: account_info.htx_access_key,
|
|
|
- // secret: account_info.htx_secret_key,
|
|
|
- // };
|
|
|
- //
|
|
|
- // let htx_wss_type = match mold.to_string().clone().as_str() {
|
|
|
- // "depth" => HtxSwapWsType::Public,
|
|
|
- // _ => HtxSwapWsType::Private
|
|
|
- // };
|
|
|
- //
|
|
|
- // let mut exchange_wss = HtxSwapWs::new_label(name, Option::from(params), htx_wss_type);
|
|
|
- // exchange_wss.set_symbols(vec![symbol_format.clone()]);
|
|
|
- // exchange_wss.set_subscribe(subscriber_type.into());
|
|
|
- // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
|
|
|
- // let mold_clone = mold.to_string().clone();
|
|
|
- // let fun = move |data: ResponseData| {
|
|
|
- // let symbol_format_c = symbol_format.clone();
|
|
|
- // let mold_cc = mold_clone.clone();
|
|
|
- //
|
|
|
- // async move {
|
|
|
- // trace!("原始数据 data:{:?}",data);
|
|
|
- // match mold_cc.as_str() {
|
|
|
- // "depth" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = handle_info::format_depth(ExchangeEnum::HtxSwap, &data);
|
|
|
- // trace!("-------------------------------");
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "position" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = htx_swap_handle::handle_position(&data, &dec!(10));
|
|
|
- // trace!("-------------------------------");
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "account" => {
|
|
|
- // if data.data != "" {
|
|
|
- // let result = htx_swap_handle::handle_account_info(&data, &symbol_format_c);
|
|
|
- // trace!("-------------------------------");
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // "orders" => {
|
|
|
- // println!("{:?}", data);
|
|
|
- // if data.data != "" {
|
|
|
- // let result = htx_swap_handle::handle_order(data, dec!(10));
|
|
|
- // trace!("-------------------------------");
|
|
|
- // trace!(?result)
|
|
|
- // }
|
|
|
- // }
|
|
|
- // _ => {
|
|
|
- // error!("没有该命令!mode={}", mold_cc);
|
|
|
- // panic!("没有该命令!mode={}", mold_cc)
|
|
|
- // }
|
|
|
- // };
|
|
|
- // }
|
|
|
- // };
|
|
|
- // exchange_wss.ws_connect_async(bool_v3_clone, fun, &write_tx_am, write_rx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
|
|
|
- // }
|
|
|
- _ => {
|
|
|
- error!("该交易所不支持!test_new_exchange_wss:{:?}", exchange);
|
|
|
- panic!("该交易所不支持!test_new_exchange_wss:{:?}", exchange)
|
|
|
- }
|
|
|
- }
|
|
|
-}
|