Skip to content

Commit 8f1784b

Browse files
committed
refactor(rust): refactor in order to support l3 backtesting.
1 parent 3ba7b62 commit 8f1784b

25 files changed

+655
-127
lines changed

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hftbacktest"
3-
version = "0.1.5"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["nkaz001 <[email protected]>"]
66
license = "MIT"

rust/examples/algo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub fn gridtrading<MD, I, R>(
1414
) -> Result<(), i64>
1515
where
1616
MD: MarketDepth,
17-
I: Interface + BotTypedDepth<MD>,
18-
<I as Interface>::Error: Debug,
17+
I: Bot + BotTypedDepth<MD>,
18+
<I as Bot>::Error: Debug,
1919
R: Recorder,
2020
<R as Recorder>::Error: Debug,
2121
{

rust/examples/gridtrading_backtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hftbacktest::{
1212
ExchangeKind,
1313
MultiAssetMultiExchangeBacktest,
1414
},
15-
prelude::{ApplySnapshot, HashMapMarketDepth, Interface},
15+
prelude::{ApplySnapshot, HashMapMarketDepth, Bot},
1616
};
1717

1818
mod algo;

rust/examples/gridtrading_backtest_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hftbacktest::{
1212
reader::read_npz,
1313
recorder::BacktestRecorder,
1414
},
15-
prelude::{ApplySnapshot, HashMapMarketDepth, Interface},
15+
prelude::{ApplySnapshot, HashMapMarketDepth, Bot},
1616
};
1717

1818
mod algo;

rust/examples/gridtrading_live.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use algo::gridtrading;
22
use hftbacktest::{
33
connector::binancefutures::{BinanceFutures, Endpoint},
4-
live::{Bot, LoggingRecorder},
5-
prelude::{HashMapMarketDepth, Interface},
4+
live::{LiveBot, LoggingRecorder},
5+
prelude::{HashMapMarketDepth, Bot},
66
};
77

88
mod algo;
@@ -11,7 +11,7 @@ const ORDER_PREFIX: &str = "prefix";
1111
const API_KEY: &str = "apikey";
1212
const SECRET: &str = "secret";
1313

14-
fn prepare_live() -> Bot<HashMapMarketDepth> {
14+
fn prepare_live() -> LiveBot<HashMapMarketDepth> {
1515
let binance_futures = BinanceFutures::builder()
1616
.endpoint(Endpoint::Testnet)
1717
.api_key(API_KEY)
@@ -20,7 +20,7 @@ fn prepare_live() -> Bot<HashMapMarketDepth> {
2020
.build()
2121
.unwrap();
2222

23-
let mut hbt = Bot::builder()
23+
let mut hbt = LiveBot::builder()
2424
.register("binancefutures", binance_futures)
2525
.add("binancefutures", "1000SHIBUSDT", 0.000001, 1.0)
2626
.depth(|asset| HashMapMarketDepth::new(asset.tick_size, asset.lot_size))

rust/examples/live_order_error_handling.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use algo::gridtrading;
22
use chrono::Utc;
33
use hftbacktest::{
44
connector::binancefutures::{BinanceFutures, BinanceFuturesError, Endpoint},
5-
live::{Bot, BotError, LoggingRecorder},
6-
prelude::{ErrorKind, HashMapMarketDepth, Interface},
5+
live::{LiveBot, BotError, LoggingRecorder},
6+
prelude::{ErrorKind, HashMapMarketDepth, Bot},
77
};
88
use tracing::{error, info};
99

@@ -13,7 +13,7 @@ const ORDER_PREFIX: &str = "prefix";
1313
const API_KEY: &str = "apikey";
1414
const SECRET: &str = "secret";
1515

16-
fn prepare_live() -> Bot<HashMapMarketDepth> {
16+
fn prepare_live() -> LiveBot<HashMapMarketDepth> {
1717
let binance_futures = BinanceFutures::builder()
1818
.endpoint(Endpoint::Testnet)
1919
.api_key(API_KEY)
@@ -22,7 +22,7 @@ fn prepare_live() -> Bot<HashMapMarketDepth> {
2222
.build()
2323
.unwrap();
2424

25-
let mut hbt = Bot::builder()
25+
let mut hbt = LiveBot::builder()
2626
.register("binancefutures", binance_futures)
2727
.add("binancefutures", "SOLUSDT", 0.001, 1.0)
2828
.error_handler(|error| {

rust/examples/logging_order_latency.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use algo::gridtrading;
22
use chrono::Utc;
33
use hftbacktest::{
44
connector::binancefutures::{BinanceFutures, Endpoint},
5-
live::{Bot, LoggingRecorder},
6-
prelude::{HashMapMarketDepth, Interface, Status},
5+
live::{LiveBot, LoggingRecorder},
6+
prelude::{HashMapMarketDepth, Bot, Status},
77
};
88
use tracing::info;
99

@@ -13,7 +13,7 @@ const ORDER_PREFIX: &str = "prefix";
1313
const API_KEY: &str = "apikey";
1414
const SECRET: &str = "secret";
1515

16-
fn prepare_live() -> Bot<HashMapMarketDepth> {
16+
fn prepare_live() -> LiveBot<HashMapMarketDepth> {
1717
let binance_futures = BinanceFutures::builder()
1818
.endpoint(Endpoint::Public)
1919
.api_key(API_KEY)
@@ -22,7 +22,7 @@ fn prepare_live() -> Bot<HashMapMarketDepth> {
2222
.build()
2323
.unwrap();
2424

25-
let mut hbt = Bot::builder()
25+
let mut hbt = LiveBot::builder()
2626
.register("binancefutures", binance_futures)
2727
.add("binancefutures", "SOLUSDT", 0.001, 1.0)
2828
.order_recv_hook(|req, resp| {

rust/src/backtest/backtest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
BotTypedTrade,
1414
BuildError,
1515
Event,
16-
Interface,
16+
Bot,
1717
OrdType,
1818
Order,
1919
Side,
@@ -205,7 +205,7 @@ where
205205
}
206206
}
207207

208-
impl<MD> Interface for MultiAssetMultiExchangeBacktest<MD>
208+
impl<MD> Bot for MultiAssetMultiExchangeBacktest<MD>
209209
where
210210
MD: MarketDepth,
211211
{
@@ -718,7 +718,7 @@ where
718718
}
719719
}
720720

721-
impl<MD, Local, Exchange> Interface for MultiAssetSingleExchangeBacktest<MD, Local, Exchange>
721+
impl<MD, Local, Exchange> Bot for MultiAssetSingleExchangeBacktest<MD, Local, Exchange>
722722
where
723723
MD: MarketDepth,
724724
Local: LocalProcessor<MD, Event>,

0 commit comments

Comments
 (0)