exchange_disguise.rs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. use std::collections::BTreeMap;
  2. use std::sync::Arc;
  3. use std::sync::atomic::AtomicBool;
  4. use tokio::sync::Mutex;
  5. use global::trace_stack::TraceStack;
  6. use standard::{Depth, Record, Ticker, Trade};
  7. use crate::binance_usdt_swap::{binance_swap_run, reference_binance_swap_run};
  8. use crate::bybit_usdt_swap::{bybit_swap_run, reference_bybit_swap_run};
  9. use crate::coinex_usdt_swap::coinex_swap_run;
  10. use crate::gate_usdt_swap::gate_swap_run;
  11. use crate::core::Core;
  12. // 交易交易所启动
  13. pub async fn run_transactional_exchange(is_shutdown_arc :Arc<AtomicBool>,
  14. exchange_name: String,
  15. core_arc: Arc<Mutex<Core>>,
  16. name: String,
  17. symbols: Vec<String>,
  18. is_colo: bool,
  19. exchange_params: BTreeMap<String, String>) {
  20. match exchange_name.as_str() {
  21. "binance_usdt_swap" => {
  22. binance_swap_run(is_shutdown_arc, core_arc, name, symbols, is_colo, exchange_params).await;
  23. },
  24. "gate_usdt_swap" => {
  25. gate_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
  26. }
  27. // "kucoin_usdt_swap" => {
  28. // kucoin_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
  29. // },
  30. // "okex_usdt_swap" => {
  31. // okex_swap_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
  32. // },
  33. // "bitget_spot" => {
  34. // bitget_spot_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
  35. // },
  36. // "bitget_usdt_swap" => {
  37. // bitget_usdt_swap_run(is_shutdown_arc, true, core_arc, name, symbols, is_colo, exchange_params).await;
  38. // }
  39. "bybit_usdt_swap" => {
  40. bybit_swap_run(is_shutdown_arc, core_arc, name, symbols, is_colo, exchange_params).await;
  41. }
  42. "coinex_usdt_swap" => {
  43. coinex_swap_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
  44. }
  45. // "htx_usdt_swap" =>{
  46. // htx_swap_run(is_shutdown_arc,true, core_arc, name, symbols, is_colo, exchange_params).await;
  47. // }
  48. _ => {
  49. let msg = format!("不支持的交易交易所:{}", exchange_name);
  50. panic!("{}", msg);
  51. }
  52. }
  53. }
  54. // 参考交易所启动
  55. pub async fn run_reference_exchange(is_shutdown_arc: Arc<AtomicBool>,
  56. exchange_name: String,
  57. core_arc: Arc<Mutex<Core>>,
  58. name: String,
  59. symbols: Vec<String>,
  60. is_colo: bool,
  61. exchange_params: BTreeMap<String, String>) {
  62. match exchange_name.as_str() {
  63. "binance_usdt_swap" => {
  64. reference_binance_swap_run(is_shutdown_arc, core_arc, name, symbols, is_colo).await;
  65. },
  66. // "binance_spot" => {
  67. // reference_binance_spot_run(is_shutdown_arc, core_arc, name, symbols, is_colo, exchange_params).await;
  68. // },
  69. "gate_usdt_swap" => {
  70. gate_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
  71. },
  72. // "okex_usdt_swap" => {
  73. // okex_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
  74. // },
  75. // "kucoin_usdt_swap" => {
  76. // kucoin_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
  77. // },
  78. // "kucoin_spot" => {
  79. // kucoin_spot_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
  80. // },
  81. // "bitget_spot" => {
  82. // bitget_spot_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
  83. // },
  84. // "bitget_usdt_swap" => {
  85. // bitget_usdt_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
  86. // }
  87. "bybit_usdt_swap" => {
  88. reference_bybit_swap_run(is_shutdown_arc, core_arc, name, symbols, is_colo).await;
  89. },
  90. "coinex_usdt_swap" => {
  91. coinex_swap_run(is_shutdown_arc,false, core_arc, name, symbols, is_colo, exchange_params).await;
  92. }
  93. // "htx_usdt_swap" =>{
  94. // htx_swap_run(is_shutdown_arc, false, core_arc, name, symbols, is_colo, exchange_params).await;
  95. // }
  96. _ => {
  97. let msg = format!("不支持的参考交易所:{}", exchange_name);
  98. panic!("{}", msg);
  99. }
  100. }
  101. }
  102. // pub async fn on_special_depth(_core_arc: Arc<Mutex<Core>>,
  103. // update_flag_u: &mut Decimal,
  104. // _label: &String,
  105. // trace_stack: &mut TraceStack,
  106. // special_depth: &SpecialDepth) {
  107. // if special_depth.t > *update_flag_u {
  108. // // let mut core = core_arc.lock().await;
  109. // trace_stack.on_after_unlock_core();
  110. //
  111. // // core.tickers.insert(label.clone(), special_depth.ticker.clone());
  112. // // core.depths.insert(label.clone(), special_depth.depth.clone());
  113. // //
  114. // // // 触发depth更新
  115. // // core.on_depth_update(&(special_depth.depth), &label, trace_stack).await;
  116. // //
  117. // // core.local_depths.insert(special_depth.name.clone(), special_depth.depth.clone());
  118. //
  119. // *update_flag_u = special_depth.t;
  120. // }
  121. // }
  122. pub async fn on_depth(core_arc: Arc<Mutex<Core>>, label: &String, trace_stack: &mut TraceStack, depth: &Depth) {
  123. let mut core = core_arc.lock().await;
  124. trace_stack.on_after_unlock_core();
  125. core.on_depth(depth, &label, trace_stack).await;
  126. }
  127. pub async fn on_trade(core_arc: Arc<Mutex<Core>>, label: &String, trace_stack: &mut TraceStack, trade: Vec<Trade>) {
  128. let mut core = core_arc.lock().await;
  129. trace_stack.on_after_unlock_core();
  130. core.on_trade(trade, &label, trace_stack).await;
  131. }
  132. pub async fn on_ticker(core_arc: Arc<Mutex<Core>>, trace_stack: &mut TraceStack, ticker: &Ticker) {
  133. let mut core = core_arc.lock().await;
  134. trace_stack.on_after_unlock_core();
  135. core.on_ticker(ticker, trace_stack).await;
  136. }
  137. pub async fn on_record(core_arc: Arc<Mutex<Core>>, record: &Record) {
  138. let mut core = core_arc.lock().await;
  139. core.on_record(record).await;
  140. }
  141. pub async fn on_order() {}
  142. pub async fn on_position() {}
  143. pub async fn on_account() {}