| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- use std::collections::BTreeMap;
- use std::sync::Arc;
- use std::sync::atomic::AtomicBool;
- use tokio::sync::Mutex;
- use global::trace_stack::TraceStack;
- use standard::{Depth, Record, Ticker, Trade};
- use crate::binance_usdt_swap::{binance_swap_run, reference_binance_swap_run};
- use crate::bybit_usdt_swap::{bybit_swap_run, reference_bybit_swap_run};
- use crate::coinex_usdt_swap::coinex_swap_run;
- use crate::gate_usdt_swap::gate_swap_run;
- use crate::core::Core;
- // 交易交易所启动
- pub async fn run_transactional_exchange(is_shutdown_arc :Arc<AtomicBool>,
- exchange_name: String,
- core_arc: Arc<Mutex<Core>>,
- name: String,
- symbols: Vec<String>,
- is_colo: bool,
- exchange_params: BTreeMap<String, String>) {
- match exchange_name.as_str() {
- "binance_usdt_swap" => {
- binance_swap_run(is_shutdown_arc, core_arc, name, symbols, is_colo, exchange_params).await;
- },
- "gate_usdt_swap" => {
- gate_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
- }
- // "kucoin_usdt_swap" => {
- // kucoin_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
- // },
- // "okex_usdt_swap" => {
- // okex_swap_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
- // },
- // "bitget_spot" => {
- // bitget_spot_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
- // },
- // "bitget_usdt_swap" => {
- // bitget_usdt_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
- // }
- "bybit_usdt_swap" => {
- bybit_swap_run(is_shutdown_arc, core_arc, name, symbols, is_colo, exchange_params).await;
- }
- "coinex_usdt_swap" => {
- coinex_swap_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
- }
- // "htx_usdt_swap" =>{
- // htx_swap_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
- // }
- _ => {
- let msg = format!("不支持的交易交易所:{}", exchange_name);
- panic!("{}", msg);
- }
- }
- }
- // 参考交易所启动
- pub async fn run_reference_exchange(is_shutdown_arc: Arc<AtomicBool>,
- exchange_name: String,
- core_arc: Arc<Mutex<Core>>,
- 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(is_shutdown_arc, core_arc, name, symbols, is_colo).await;
- },
- // "binance_spot" => {
- // reference_binance_spot_run(is_shutdown_arc, core_arc, name, symbols, is_colo, exchange_params).await;
- // },
- "gate_usdt_swap" => {
- gate_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
- },
- // "okex_usdt_swap" => {
- // okex_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
- // },
- // "kucoin_usdt_swap" => {
- // kucoin_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
- // },
- // "kucoin_spot" => {
- // kucoin_spot_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
- // },
- // "bitget_spot" => {
- // bitget_spot_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
- // },
- // "bitget_usdt_swap" => {
- // bitget_usdt_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
- // }
- "bybit_usdt_swap" => {
- reference_bybit_swap_run(is_shutdown_arc, core_arc, name, symbols, is_colo).await;
- },
- "coinex_usdt_swap" => {
- coinex_swap_run(is_shutdown_arc,false, core_arc, name, symbols, is_colo, exchange_params).await;
- }
- // "htx_usdt_swap" =>{
- // htx_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
- // }
- _ => {
- let msg = format!("不支持的参考交易所:{}", exchange_name);
- panic!("{}", msg);
- }
- }
- }
- // pub async fn on_special_depth(_core_arc: Arc<Mutex<Core>>,
- // update_flag_u: &mut Decimal,
- // _label: &String,
- // trace_stack: &mut TraceStack,
- // special_depth: &SpecialDepth) {
- // if special_depth.t > *update_flag_u {
- // // let mut core = core_arc.lock().await;
- // trace_stack.on_after_unlock_core();
- //
- // // core.tickers.insert(label.clone(), special_depth.ticker.clone());
- // // core.depths.insert(label.clone(), special_depth.depth.clone());
- // //
- // // // 触发depth更新
- // // core.on_depth_update(&(special_depth.depth), &label, trace_stack).await;
- // //
- // // core.local_depths.insert(special_depth.name.clone(), special_depth.depth.clone());
- //
- // *update_flag_u = special_depth.t;
- // }
- // }
- pub async fn on_depth(core_arc: Arc<Mutex<Core>>, label: &String, trace_stack: &mut TraceStack, depth: &Depth) {
- let mut core = core_arc.lock().await;
- trace_stack.on_after_unlock_core();
- core.on_depth(depth, &label, trace_stack).await;
- }
- pub async fn on_trade(core_arc: Arc<Mutex<Core>>, label: &String, trace_stack: &mut TraceStack, trade: Vec<Trade>) {
- let mut core = core_arc.lock().await;
- trace_stack.on_after_unlock_core();
- core.on_trade(trade, &label, trace_stack).await;
- }
- pub async fn on_ticker(core_arc: Arc<Mutex<Core>>, trace_stack: &mut TraceStack, ticker: &Ticker) {
- let mut core = core_arc.lock().await;
- trace_stack.on_after_unlock_core();
- core.on_ticker(ticker, trace_stack).await;
- }
- pub async fn on_record(core_arc: Arc<Mutex<Core>>, record: &Record) {
- let mut core = core_arc.lock().await;
- core.on_record(record).await;
- }
- pub async fn on_order() {}
- pub async fn on_position() {}
- pub async fn on_account() {}
|