| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- use std::collections::BTreeMap;
- use std::sync::Arc;
- use std::sync::atomic::AtomicBool;
- use rust_decimal::Decimal;
- use tokio::sync::Mutex;
- use global::trace_stack::TraceStack;
- use standard::SpecialDepth;
- use crate::binance_spot::reference_binance_spot_run;
- use crate::binance_usdt_swap::reference_binance_swap_run;
- use crate::bitget_spot::bitget_spot_run;
- use crate::bybit_usdt_swap::bybit_swap_run;
- use crate::gate_swap::gate_swap_run;
- use crate::kucoin_spot::kucoin_spot_run;
- use crate::kucoin_swap::kucoin_swap_run;
- use crate::okx_usdt_swap::okex_swap_run;
- use crate::quant::Quant;
- // 交易交易所启动
- pub async fn run_transactional_exchange(bool_v1 :Arc<AtomicBool>,
- exchange_name: String,
- quant_arc: Arc<Mutex<Quant>>,
- name: String,
- symbols: Vec<String>,
- is_colo: bool,
- exchange_params: BTreeMap<String, String>) {
- match exchange_name.as_str() {
- "gate_usdt_swap" => {
- gate_swap_run(bool_v1, true, quant_arc, name, symbols, is_colo, exchange_params).await;
- }
- "kucoin_usdt_swap" => {
- kucoin_swap_run(bool_v1, true, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "okex_usdt_swap" => {
- okex_swap_run(bool_v1,true, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "bitget_spot" => {
- bitget_spot_run(bool_v1,true, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "bybit_usdt_swap" => {
- bybit_swap_run(bool_v1,true, quant_arc, name, symbols, is_colo, exchange_params).await;
- }
- _ => {
- let msg = format!("不支持的交易交易所:{}", exchange_name);
- panic!("{}", msg);
- }
- }
- }
- // 参考交易所启动
- pub async fn run_reference_exchange(bool_v1: Arc<AtomicBool>,
- exchange_name: String,
- quant_arc: Arc<Mutex<Quant>>,
- name: String,
- symbols: Vec<String>,
- is_colo: bool,
- exchange_params: BTreeMap<String, String>) {
- match exchange_name.as_str() {
- "binance_usdt_swap" => {
- reference_binance_swap_run(bool_v1, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "binance_spot" => {
- reference_binance_spot_run(bool_v1, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "gate_usdt_swap" => {
- gate_swap_run(bool_v1, false, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "okex_usdt_swap" => {
- okex_swap_run(bool_v1, false, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "kucoin_usdt_swap" => {
- kucoin_swap_run(bool_v1, false, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "kucoin_spot" => {
- kucoin_spot_run(bool_v1, false, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "bitget_spot" => {
- bitget_spot_run(bool_v1, false, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- "bybit_usdt_swap" => {
- bybit_swap_run(bool_v1, false, quant_arc, name, symbols, is_colo, exchange_params).await;
- },
- _ => {
- let msg = format!("不支持的参考交易所:{}", exchange_name);
- panic!("{}", msg);
- }
- }
- }
- pub async fn on_special_depth(bot_arc: Arc<Mutex<Quant>>,
- update_flag_u: &mut Decimal,
- label: String,
- trace_stack: TraceStack,
- special_depth: SpecialDepth) {
- if special_depth.t > *update_flag_u {
- *update_flag_u = special_depth.t;
- let mut quant = bot_arc.lock().await;
- quant._update_ticker(special_depth.ticker, label.clone());
- quant._update_depth(special_depth.depth.clone(), label.clone(), trace_stack);
- quant.local_depths.insert(special_depth.name, special_depth.depth);
- }
- }
- // pub async fn on_trade(trade: OriginalTradeBa,
- // bot_arc_clone: Arc<Mutex<Quant>>) {
- // let mut bot = bot_arc_clone.lock().await;
- // // 1. 塞入数据到bot
- // bot.trades.push(trade.clone());
- // // 2. 长度检查
- // if bot.trades.len() > bot.recall_max_count {
- // bot.trades.remove(0);
- // }
- // // 3. 如果少于100条,不进行判断
- // if bot.trades.len() < 100 {
- // return;
- // }
- // // 求最近的多空总和
- // let mut long_sum = Decimal::ZERO;
- // let mut short_sum = Decimal::ZERO;
- // let last_trade_t = trade.t.clone();
- // let mut rev = bot.trades.clone();
- // rev.reverse();
- // for trade_o in rev {
- // // 如果该元素已过期,我们是按时间顺序插入的,说明前面的应该都过期了,跳出循环,停止检测
- // if trade_o.t < last_trade_t - bot.recall_time {
- // continue;
- // }
- //
- // // 卖出订单
- // if trade_o.m {
- // short_sum += trade_o.q;
- // } else {
- // long_sum += trade_o.q;
- // }
- // }
- //
- // // 做多主动性
- // if (long_sum / (long_sum + short_sum)) > bot.long_volume_rate {
- // if bot.side != "long".to_string() {
- // bot.side = "long".to_string();
- // }
- // } else if (short_sum / (long_sum + short_sum)) > bot.short_volume_rate {
- // if bot.side != "short".to_string() {
- // bot.side = "short".to_string();
- // }
- // } else {
- // if bot.side != "normal".to_string() {
- // bot.side = "normal".to_string();
- // }
- // }
- // }
- pub async fn on_order() {}
- pub async fn on_position() {}
- pub async fn on_account() {}
|