|
@@ -17,6 +17,7 @@ pub struct AvellanedaStoikov {
|
|
|
pub trade_long_vec: FixedTimeRangeDeque<Trade>, // 交易队列
|
|
pub trade_long_vec: FixedTimeRangeDeque<Trade>, // 交易队列
|
|
|
pub trade_short_vec: FixedTimeRangeDeque<Trade>, // 交易队列
|
|
pub trade_short_vec: FixedTimeRangeDeque<Trade>, // 交易队列
|
|
|
pub spread_vec: FixedTimeRangeDeque<Decimal>,
|
|
pub spread_vec: FixedTimeRangeDeque<Decimal>,
|
|
|
|
|
+ pub record_vec: FixedTimeRangeDeque<Record>, // 蜡烛队列
|
|
|
|
|
|
|
|
pub mid_price: Decimal, // 中间价
|
|
pub mid_price: Decimal, // 中间价
|
|
|
pub ask_price: Decimal, // 卖一价
|
|
pub ask_price: Decimal, // 卖一价
|
|
@@ -54,6 +55,7 @@ pub struct AvellanedaStoikov {
|
|
|
impl AvellanedaStoikov {
|
|
impl AvellanedaStoikov {
|
|
|
// 时间窗口大小(微秒)
|
|
// 时间窗口大小(微秒)
|
|
|
const MAX_TIME_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
const MAX_TIME_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
|
|
|
+ const RECORD_RANGE_MICROS: i64 = 4 * 60_000_000;
|
|
|
const TRADE_LONG_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
const TRADE_LONG_RANGE_MICROS: i64 = 3 * 60_000_000;
|
|
|
const TRADE_SHORT_RANGE_MICROS: i64 = 20_000_000;
|
|
const TRADE_SHORT_RANGE_MICROS: i64 = 20_000_000;
|
|
|
// const ONE_MILLION: Decimal = dec!(1_000_000);
|
|
// const ONE_MILLION: Decimal = dec!(1_000_000);
|
|
@@ -67,6 +69,7 @@ impl AvellanedaStoikov {
|
|
|
spread_vec: FixedTimeRangeDeque::new(Self::MAX_TIME_RANGE_MICROS),
|
|
spread_vec: FixedTimeRangeDeque::new(Self::MAX_TIME_RANGE_MICROS),
|
|
|
trade_long_vec: FixedTimeRangeDeque::new(Self::TRADE_LONG_RANGE_MICROS),
|
|
trade_long_vec: FixedTimeRangeDeque::new(Self::TRADE_LONG_RANGE_MICROS),
|
|
|
trade_short_vec: FixedTimeRangeDeque::new(Self::TRADE_SHORT_RANGE_MICROS),
|
|
trade_short_vec: FixedTimeRangeDeque::new(Self::TRADE_SHORT_RANGE_MICROS),
|
|
|
|
|
+ record_vec: FixedTimeRangeDeque::new(Self::RECORD_RANGE_MICROS),
|
|
|
|
|
|
|
|
mid_price: Default::default(),
|
|
mid_price: Default::default(),
|
|
|
ask_price: Default::default(),
|
|
ask_price: Default::default(),
|
|
@@ -174,7 +177,18 @@ impl AvellanedaStoikov {
|
|
|
pub async fn on_ticker(&mut self, _ticker: &Ticker) {}
|
|
pub async fn on_ticker(&mut self, _ticker: &Ticker) {}
|
|
|
|
|
|
|
|
pub async fn on_record(&mut self, record: &Record) {
|
|
pub async fn on_record(&mut self, record: &Record) {
|
|
|
- info!(?record);
|
|
|
|
|
|
|
+ // 添加新蜡烛
|
|
|
|
|
+ if self.record_vec.len() == 0 {
|
|
|
|
|
+ self.record_vec.push_back(record.clone());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ let last_record = self.record_vec.deque.back_mut().unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ if last_record.time == record.time {
|
|
|
|
|
+ *last_record = record.clone();
|
|
|
|
|
+ } else if last_record.time < record.time {
|
|
|
|
|
+ self.record_vec.push_back(record.clone());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pub async fn update_inventory(&mut self, inventory: &Decimal, min_amount_value: &Decimal) {
|
|
pub async fn update_inventory(&mut self, inventory: &Decimal, min_amount_value: &Decimal) {
|