|
|
@@ -4,6 +4,7 @@ use std::collections::BTreeMap;
|
|
|
use std::io::Error;
|
|
|
use strategy::{exchange_disguise, quant};
|
|
|
use std::sync::Arc;
|
|
|
+use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
use std::time::Duration;
|
|
|
use tokio::sync::{mpsc, Mutex};
|
|
|
use tracing::{error, info};
|
|
|
@@ -11,7 +12,7 @@ use standard::exchange::ExchangeEnum::GateSwap;
|
|
|
use standard::Order;
|
|
|
use strategy::model::OrderInfo;
|
|
|
|
|
|
-pub async fn init(params: Params) -> Arc<Mutex<Quant>> {
|
|
|
+pub async fn init(params: Params, running: Arc<AtomicBool>) -> Arc<Mutex<Quant>> {
|
|
|
// 封装
|
|
|
let mut exchange_params:BTreeMap<String, String> = BTreeMap::new();
|
|
|
exchange_params.insert("access_key".to_string(), params.access_key.clone());
|
|
|
@@ -39,7 +40,7 @@ pub async fn init(params: Params) -> Arc<Mutex<Quant>> {
|
|
|
|
|
|
let order_handler_quant_arc = quant_arc.clone();
|
|
|
tokio::spawn(async move {
|
|
|
- loop {
|
|
|
+ while running.load(Ordering::Relaxed) {
|
|
|
tokio::time::sleep(Duration::from_millis(1)).await;
|
|
|
|
|
|
match order_receiver.recv().await {
|
|
|
@@ -74,7 +75,7 @@ pub async fn init(params: Params) -> Arc<Mutex<Quant>> {
|
|
|
|
|
|
// let error_handler_quant_arc = quant_arc.clone();
|
|
|
tokio::spawn(async move {
|
|
|
- loop {
|
|
|
+ while running.load(Ordering::Relaxed) {
|
|
|
tokio::time::sleep(Duration::from_millis(1)).await;
|
|
|
|
|
|
match error_receiver.recv().await {
|