|
|
@@ -8,8 +8,7 @@ use standard::utils;
|
|
|
use standard::exchange::{Exchange, ExchangeEnum};
|
|
|
|
|
|
// 创建交易所实体方法
|
|
|
-#[instrument(skip(exchange), level = "TRACE")]
|
|
|
-fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
|
|
|
+async fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
|
|
|
if proxy::ParsingDetail::http_enable_proxy() {
|
|
|
trace!("检测有代理配置,配置走代理");
|
|
|
}
|
|
|
@@ -20,7 +19,7 @@ fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
|
|
|
let secret_key = env::var("binance_secret_key").unwrap_or("".to_string());
|
|
|
params.insert("access_key".to_string(), access_key);
|
|
|
params.insert("secret_key".to_string(), secret_key);
|
|
|
- Exchange::new(exchange, "ROSE_USDT".to_string(), false, params)
|
|
|
+ Exchange::new(exchange, "ROSE_USDT".to_string(), false, params).await
|
|
|
}
|
|
|
ExchangeEnum::BinanceSpot => {
|
|
|
let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
@@ -28,7 +27,7 @@ fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
|
|
|
let secret_key = env::var("binance_secret_key").unwrap_or("".to_string());
|
|
|
params.insert("access_key".to_string(), access_key);
|
|
|
params.insert("secret_key".to_string(), secret_key);
|
|
|
- Exchange::new(exchange, "ROSE_USDT".to_string(), false, params)
|
|
|
+ Exchange::new(exchange, "ROSE_USDT".to_string(), false, params).await
|
|
|
}
|
|
|
ExchangeEnum::GateSwap => {
|
|
|
let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
@@ -36,7 +35,7 @@ fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
|
|
|
let secret_key = env::var("gate_secret_key").unwrap_or("".to_string());
|
|
|
params.insert("access_key".to_string(), access_key);
|
|
|
params.insert("secret_key".to_string(), secret_key);
|
|
|
- Exchange::new(exchange, "ROSE_USDT".to_string(), false, params)
|
|
|
+ Exchange::new(exchange, "ROSE_USDT".to_string(), false, params).await
|
|
|
}
|
|
|
ExchangeEnum::GateSpot => {
|
|
|
let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
@@ -44,7 +43,7 @@ fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
|
|
|
let secret_key = env::var("gate_secret_key").unwrap_or("".to_string());
|
|
|
params.insert("access_key".to_string(), access_key);
|
|
|
params.insert("secret_key".to_string(), secret_key);
|
|
|
- Exchange::new(exchange, "ROSE_USDT".to_string(), false, params)
|
|
|
+ Exchange::new(exchange, "ROSE_USDT".to_string(), false, params).await
|
|
|
}
|
|
|
ExchangeEnum::KucoinSwap => {
|
|
|
let mut params: BTreeMap<String, String> = BTreeMap::new();
|
|
|
@@ -54,7 +53,7 @@ fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
|
|
|
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, "ROSE_USDT".to_string(), false, params)
|
|
|
+ Exchange::new(exchange, "ROSE_USDT".to_string(), false, params).await
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -65,7 +64,7 @@ fn test_new_exchange(exchange: ExchangeEnum) -> Box<dyn Platform> {
|
|
|
async fn test_binance_swap_account() {
|
|
|
global::log_utils::init_log_with_trace();
|
|
|
|
|
|
- let binance_swap_exchange = test_new_exchange(ExchangeEnum::BinanceSwap);
|
|
|
+ let binance_swap_exchange = test_new_exchange(ExchangeEnum::BinanceSwap).await;
|
|
|
let self_exchange = binance_swap_exchange.get_self_exchange();
|
|
|
let self_is_colo = binance_swap_exchange.get_self_is_colo();
|
|
|
let self_params = binance_swap_exchange.get_self_params();
|
|
|
@@ -79,7 +78,7 @@ async fn test_binance_swap_account() {
|
|
|
async fn test_binance_spot_account() {
|
|
|
global::log_utils::init_log_with_trace();
|
|
|
|
|
|
- let binance_spot_exchange = test_new_exchange(ExchangeEnum::BinanceSpot);
|
|
|
+ let binance_spot_exchange = test_new_exchange(ExchangeEnum::BinanceSpot).await;
|
|
|
let self_exchange = binance_spot_exchange.get_self_exchange();
|
|
|
let self_is_colo = binance_spot_exchange.get_self_is_colo();
|
|
|
let self_params = binance_spot_exchange.get_self_params();
|
|
|
@@ -90,20 +89,25 @@ async fn test_binance_spot_account() {
|
|
|
|
|
|
// 测试获取Gate交易所期货实体
|
|
|
#[tokio::test]
|
|
|
+#[instrument(level = "TRACE")]
|
|
|
async fn test_gate_swap_account() {
|
|
|
- let gate_swap_exchange = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ global::log_utils::init_log_with_trace();
|
|
|
+
|
|
|
+ let gate_swap_exchange = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
let self_exchange = gate_swap_exchange.get_self_exchange();
|
|
|
let self_is_colo = gate_swap_exchange.get_self_is_colo();
|
|
|
let self_params = gate_swap_exchange.get_self_params();
|
|
|
+ let self_market = gate_swap_exchange.get_self_market();
|
|
|
trace!(?self_exchange);
|
|
|
trace!(?self_is_colo);
|
|
|
trace!(?self_params);
|
|
|
+ trace!(?self_market);
|
|
|
}
|
|
|
|
|
|
// 测试获取Gate交易所现货实体
|
|
|
#[tokio::test]
|
|
|
async fn test_gate_spot_account() {
|
|
|
- let gate_spot_exchange = test_new_exchange(ExchangeEnum::GateSpot);
|
|
|
+ let gate_spot_exchange = test_new_exchange(ExchangeEnum::GateSpot).await;
|
|
|
println!("exchange: {:?}", gate_spot_exchange.get_self_exchange());
|
|
|
println!("is_colo: {:?}", gate_spot_exchange.get_self_is_colo());
|
|
|
println!("params: {:?}", gate_spot_exchange.get_self_params());
|
|
|
@@ -112,7 +116,7 @@ async fn test_gate_spot_account() {
|
|
|
// 测试获取Gate交易所现货实体
|
|
|
#[tokio::test]
|
|
|
async fn test_kucoin_swap_account() {
|
|
|
- let kucoin_swap_exchange = test_new_exchange(ExchangeEnum::KucoinSwap);
|
|
|
+ let kucoin_swap_exchange = test_new_exchange(ExchangeEnum::KucoinSwap).await;
|
|
|
println!("exchange: {:?}", kucoin_swap_exchange.get_self_exchange());
|
|
|
println!("is_colo: {:?}", kucoin_swap_exchange.get_self_is_colo());
|
|
|
println!("params: {:?}", kucoin_swap_exchange.get_self_params());
|
|
|
@@ -127,115 +131,115 @@ async fn test_replace_symbol() {
|
|
|
// 测试Binance期货K线推送
|
|
|
#[tokio::test]
|
|
|
async fn test_get_account() {
|
|
|
- let binance_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::BinanceSwap);
|
|
|
+ let binance_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::BinanceSwap).await;
|
|
|
println!("binance_swap account:{:?}", binance_swap_exchange.get_account().await);
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap account:{:?}", gate_swap_exchange.get_account().await);
|
|
|
- let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap);
|
|
|
+ let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap).await;
|
|
|
println!("kucoin_swap account:{:?}", kucoin_swap_exchange.get_account().await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate 获取持仓信息
|
|
|
#[tokio::test]
|
|
|
async fn test_gate_swap_get_position() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap get_position:{:?}", gate_swap_exchange.get_position().await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate 获取所有持仓信息
|
|
|
#[tokio::test]
|
|
|
async fn test_gate_swap_get_positions() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap get_positions:{:?}", gate_swap_exchange.get_positions().await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate获取Ticker信息
|
|
|
#[tokio::test]
|
|
|
async fn test_gate_swap_get_ticker() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap get_ticker:{:?}", gate_swap_exchange.get_ticker().await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate获取Market信息
|
|
|
#[tokio::test]
|
|
|
async fn test_gate_swap_get_market() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap get_market:{:?}", gate_swap_exchange.get_market().await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate获取Order详情信息
|
|
|
#[tokio::test]
|
|
|
async fn test_gate_swap_get_order_detail() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap get_order_detail:{:?}", gate_swap_exchange.get_order_detail("336321097375", "").await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate获取Order列表信息
|
|
|
#[tokio::test]
|
|
|
async fn test_gate_swap_get_orders_list() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap get_orders_list:{:?}", gate_swap_exchange.get_orders_list("finished").await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate 设置持仓模式
|
|
|
#[tokio::test]
|
|
|
async fn test_set_dual_mode() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap set_dual_mode:{:?}", gate_swap_exchange.set_dual_mode("usdt", true).await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate 设置持仓模式
|
|
|
#[tokio::test]
|
|
|
async fn test_set_dual_leverage() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap set_dual_leverage:{:?}", gate_swap_exchange.set_dual_leverage("10").await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate 测试下单
|
|
|
#[tokio::test]
|
|
|
async fn test_take_order() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap take_order:{:?}", gate_swap_exchange.take_order("123456", "pd", dec!(0.038850), dec!(1)).await);
|
|
|
}
|
|
|
|
|
|
// 测试Gate 撤销订单
|
|
|
#[tokio::test]
|
|
|
async fn test_cancel_order() {
|
|
|
- let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap);
|
|
|
+ let gate_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::GateSwap).await;
|
|
|
println!("gate_swap cancel_order:{:?}", gate_swap_exchange.cancel_order("337811438982", "").await);
|
|
|
}
|
|
|
|
|
|
// 测试kucoin 获取持仓信息
|
|
|
#[tokio::test]
|
|
|
async fn test_kucoin_swap_get_position() {
|
|
|
- let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap);
|
|
|
+ let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap).await;
|
|
|
println!("kucoin_swap get_position:{:?}", kucoin_swap_exchange.get_position().await);
|
|
|
}
|
|
|
|
|
|
// 测试kucoin 获取所有持仓信息
|
|
|
#[tokio::test]
|
|
|
async fn test_kucoin_swap_get_positions() {
|
|
|
- let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap);
|
|
|
+ let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap).await;
|
|
|
println!("kucoin_swap get_positions:{:?}", kucoin_swap_exchange.get_positions().await);
|
|
|
}
|
|
|
|
|
|
// 测试kucoin 获取Ticker信息
|
|
|
#[tokio::test]
|
|
|
async fn test_kucoin_swap_get_ticker() {
|
|
|
- let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap);
|
|
|
+ let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap).await;
|
|
|
println!("kucoin_swap get_ticker:{:?}", kucoin_swap_exchange.get_ticker().await);
|
|
|
}
|
|
|
|
|
|
// 测试kucoin 获取Market信息
|
|
|
#[tokio::test]
|
|
|
async fn test_kucoin_swap_get_market() {
|
|
|
- let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap);
|
|
|
+ let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap).await;
|
|
|
println!("kucoin_swap get_market:{:?}", kucoin_swap_exchange.get_market().await);
|
|
|
}
|
|
|
|
|
|
// 测试kucoin 获取订单信息
|
|
|
#[tokio::test]
|
|
|
async fn test_kucoin_swap_get_order_detail() {
|
|
|
- let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap);
|
|
|
+ let kucoin_swap_exchange: Box<dyn Platform> = test_new_exchange(ExchangeEnum::KucoinSwap).await;
|
|
|
println!("kucoin_swap get_market:{:?}", kucoin_swap_exchange.get_order_detail("123", "").await);
|
|
|
}
|