Skip to content

Commit

Permalink
refactor(rust): refactor in order to support l3 backtesting.
Browse files Browse the repository at this point in the history
  • Loading branch information
nkaz001 committed Jun 17, 2024
1 parent 3ba7b62 commit 8f1784b
Show file tree
Hide file tree
Showing 25 changed files with 655 additions and 127 deletions.
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hftbacktest"
version = "0.1.5"
version = "0.2.0"
edition = "2021"
authors = ["nkaz001 <[email protected]>"]
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions rust/examples/algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub fn gridtrading<MD, I, R>(
) -> Result<(), i64>
where
MD: MarketDepth,
I: Interface + BotTypedDepth<MD>,
<I as Interface>::Error: Debug,
I: Bot + BotTypedDepth<MD>,
<I as Bot>::Error: Debug,
R: Recorder,
<R as Recorder>::Error: Debug,
{
Expand Down
2 changes: 1 addition & 1 deletion rust/examples/gridtrading_backtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hftbacktest::{
ExchangeKind,
MultiAssetMultiExchangeBacktest,
},
prelude::{ApplySnapshot, HashMapMarketDepth, Interface},
prelude::{ApplySnapshot, HashMapMarketDepth, Bot},
};

mod algo;
Expand Down
2 changes: 1 addition & 1 deletion rust/examples/gridtrading_backtest_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use hftbacktest::{
reader::read_npz,
recorder::BacktestRecorder,
},
prelude::{ApplySnapshot, HashMapMarketDepth, Interface},
prelude::{ApplySnapshot, HashMapMarketDepth, Bot},
};

mod algo;
Expand Down
8 changes: 4 additions & 4 deletions rust/examples/gridtrading_live.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use algo::gridtrading;
use hftbacktest::{
connector::binancefutures::{BinanceFutures, Endpoint},
live::{Bot, LoggingRecorder},
prelude::{HashMapMarketDepth, Interface},
live::{LiveBot, LoggingRecorder},
prelude::{HashMapMarketDepth, Bot},
};

mod algo;
Expand All @@ -11,7 +11,7 @@ const ORDER_PREFIX: &str = "prefix";
const API_KEY: &str = "apikey";
const SECRET: &str = "secret";

fn prepare_live() -> Bot<HashMapMarketDepth> {
fn prepare_live() -> LiveBot<HashMapMarketDepth> {
let binance_futures = BinanceFutures::builder()
.endpoint(Endpoint::Testnet)
.api_key(API_KEY)
Expand All @@ -20,7 +20,7 @@ fn prepare_live() -> Bot<HashMapMarketDepth> {
.build()
.unwrap();

let mut hbt = Bot::builder()
let mut hbt = LiveBot::builder()
.register("binancefutures", binance_futures)
.add("binancefutures", "1000SHIBUSDT", 0.000001, 1.0)
.depth(|asset| HashMapMarketDepth::new(asset.tick_size, asset.lot_size))
Expand Down
8 changes: 4 additions & 4 deletions rust/examples/live_order_error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use algo::gridtrading;
use chrono::Utc;
use hftbacktest::{
connector::binancefutures::{BinanceFutures, BinanceFuturesError, Endpoint},
live::{Bot, BotError, LoggingRecorder},
prelude::{ErrorKind, HashMapMarketDepth, Interface},
live::{LiveBot, BotError, LoggingRecorder},
prelude::{ErrorKind, HashMapMarketDepth, Bot},
};
use tracing::{error, info};

Expand All @@ -13,7 +13,7 @@ const ORDER_PREFIX: &str = "prefix";
const API_KEY: &str = "apikey";
const SECRET: &str = "secret";

fn prepare_live() -> Bot<HashMapMarketDepth> {
fn prepare_live() -> LiveBot<HashMapMarketDepth> {
let binance_futures = BinanceFutures::builder()
.endpoint(Endpoint::Testnet)
.api_key(API_KEY)
Expand All @@ -22,7 +22,7 @@ fn prepare_live() -> Bot<HashMapMarketDepth> {
.build()
.unwrap();

let mut hbt = Bot::builder()
let mut hbt = LiveBot::builder()
.register("binancefutures", binance_futures)
.add("binancefutures", "SOLUSDT", 0.001, 1.0)
.error_handler(|error| {
Expand Down
8 changes: 4 additions & 4 deletions rust/examples/logging_order_latency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use algo::gridtrading;
use chrono::Utc;
use hftbacktest::{
connector::binancefutures::{BinanceFutures, Endpoint},
live::{Bot, LoggingRecorder},
prelude::{HashMapMarketDepth, Interface, Status},
live::{LiveBot, LoggingRecorder},
prelude::{HashMapMarketDepth, Bot, Status},
};
use tracing::info;

Expand All @@ -13,7 +13,7 @@ const ORDER_PREFIX: &str = "prefix";
const API_KEY: &str = "apikey";
const SECRET: &str = "secret";

fn prepare_live() -> Bot<HashMapMarketDepth> {
fn prepare_live() -> LiveBot<HashMapMarketDepth> {
let binance_futures = BinanceFutures::builder()
.endpoint(Endpoint::Public)
.api_key(API_KEY)
Expand All @@ -22,7 +22,7 @@ fn prepare_live() -> Bot<HashMapMarketDepth> {
.build()
.unwrap();

let mut hbt = Bot::builder()
let mut hbt = LiveBot::builder()
.register("binancefutures", binance_futures)
.add("binancefutures", "SOLUSDT", 0.001, 1.0)
.order_recv_hook(|req, resp| {
Expand Down
6 changes: 3 additions & 3 deletions rust/src/backtest/backtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
BotTypedTrade,
BuildError,
Event,
Interface,
Bot,
OrdType,
Order,
Side,
Expand Down Expand Up @@ -205,7 +205,7 @@ where
}
}

impl<MD> Interface for MultiAssetMultiExchangeBacktest<MD>
impl<MD> Bot for MultiAssetMultiExchangeBacktest<MD>
where
MD: MarketDepth,
{
Expand Down Expand Up @@ -718,7 +718,7 @@ where
}
}

impl<MD, Local, Exchange> Interface for MultiAssetSingleExchangeBacktest<MD, Local, Exchange>
impl<MD, Local, Exchange> Bot for MultiAssetSingleExchangeBacktest<MD, Local, Exchange>
where
MD: MarketDepth,
Local: LocalProcessor<MD, Event>,
Expand Down
Loading

0 comments on commit 8f1784b

Please sign in to comment.