|
|
@@ -13,8 +13,6 @@ use standard::OrderCommand;
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
pub struct Strategy {
|
|
|
- // pub interval: Decimal, // 原文没有使用过这个参数
|
|
|
-
|
|
|
// 各类时间戳和时延,我们都改成了毫秒级
|
|
|
pub _print_time: i64, // 上次打印时间
|
|
|
pub _print_interval: i64, // 打印时延
|
|
|
@@ -39,7 +37,6 @@ pub struct Strategy {
|
|
|
pub limit_order_requests_num: i64, // 单位(时延)时间内下单次数上限
|
|
|
pub _req_num_per_window: i64, // 单位(时延)时间内请求上限窗口
|
|
|
|
|
|
- pub place_order_limit: i64, // 参数层面传进来的下单数量限制
|
|
|
pub params: Params, //
|
|
|
pub exchange: String, //
|
|
|
pub broker_id: String, //
|
|
|
@@ -124,7 +121,6 @@ impl Strategy {
|
|
|
check_wait_interval: 10 * 1000,
|
|
|
_check_local_orders_time: 0,
|
|
|
_check_local_orders_interval: 0,
|
|
|
- place_order_limit: 0,
|
|
|
request_limit_check_time: 0,
|
|
|
request_limit_check_interval: 0,
|
|
|
limit_requests_num: 0,
|
|
|
@@ -214,16 +210,15 @@ impl Strategy {
|
|
|
strategy._check_local_orders_time = now.timestamp_millis();
|
|
|
strategy._check_local_orders_interval = 10 * 1000;
|
|
|
// 下单的相关限制处理
|
|
|
- strategy.place_order_limit = params.place_order_limit;
|
|
|
strategy.request_limit_check_time = now.timestamp_millis();
|
|
|
strategy.request_limit_check_interval = 10 * 1000;
|
|
|
// 求得正常请求数量和下单请求数量(interval时间内)
|
|
|
let request_limit_check_interval_per_second = strategy.request_limit_check_interval / 1000;
|
|
|
- strategy.limit_requests_num = utils::get_limit_requests_num_per_second(params.exchange.clone(), params.place_order_limit) * (request_limit_check_interval_per_second);
|
|
|
- strategy.limit_order_requests_num = utils::get_limit_order_requests_num_per_second(params.exchange.clone(), params.place_order_limit) * (request_limit_check_interval_per_second);
|
|
|
+ strategy.limit_requests_num = utils::get_limit_requests_num_per_second(params.exchange.clone()) * (request_limit_check_interval_per_second);
|
|
|
+ strategy.limit_order_requests_num = utils::get_limit_order_requests_num_per_second(params.exchange.clone()) * (request_limit_check_interval_per_second);
|
|
|
// 开仓下单间隔 均匀下单机会
|
|
|
strategy.post_open_time = now.timestamp_millis();
|
|
|
- let post_open_interval_per_second = Decimal::ONE.div(Decimal::from_i64(utils::get_limit_order_requests_num_per_second(params.exchange.clone(), 0)).unwrap());
|
|
|
+ let post_open_interval_per_second = Decimal::ONE.div(Decimal::from_i64(utils::get_limit_order_requests_num_per_second(params.exchange.clone())).unwrap());
|
|
|
strategy.post_open_interval = dec!(1000).mul(post_open_interval_per_second).to_i64().unwrap();
|
|
|
info!("策略模块初始化完成!");
|
|
|
|
|
|
@@ -1282,6 +1277,7 @@ mod tests {
|
|
|
create_time: 0,
|
|
|
status: "".to_string(),
|
|
|
fee: Default::default(),
|
|
|
+ trace_stack: Default::default(),
|
|
|
});
|
|
|
trader_msg.cash = dec!(1000);
|
|
|
trader_msg.coin = Decimal::ZERO;
|