nkaz001 / hftbacktest

A high-frequency trading and market-making backtesting tool in Python and Rust, which accounts for limit orders, queue positions, and latencies, utilizing full tick data for trades and order books, with real-world crypto market-making examples for Binance Futures
MIT License
1.78k stars 357 forks source link

Request for another example #74

Closed simsim-14 closed 5 months ago

simsim-14 commented 5 months ago

Hello,

I am having some hard time trying to run a Multi asset, multi exchange live script.

From what I have seen from the code, I understand that asset_no is probably a pointer to asset info as well as the exchange that it refers to.

However, I am a bit confused on how to use this, I would have some intuition to use for example depth(connection/exchange, asset_name) instead of depth(asset_no) (which I am not sure exactly what it is).

So I would be very grateful if you provide some example implementation on how to run a Multi asset, multi exchange live script (even if the second connection is dummy, since we now have only binance futures).

nkaz001 commented 5 months ago

I'm in the process of stabilizing the API, so it hasn't undergone thorough testing yet. But, I will certainly provide more examples. In the meantime, please refer to the following snippet:

let mut hbt = LiveBuilder::new()
    .register("binancefutures", binance_futures)
    .add("binancefutures", "BTCUSDT", 0.1, 0.001) // asset_no: 0
    .add("binancefutures", "ETHUSDT", 0.01, 0.001) // asset_no: 1
    .build()
    .unwrap();

in the algo,

while hbt.elapse(1_000_000_000).unwrap() {
    {
        // BTCUSDT
        let depth = hbt.depth(0);
        let position = hbt.position(0);

        // your algo
    }

    // Due to Rust's borrowing rules, {} is necessary.
    {
        // ETHUSDT
        let depth = hbt.depth(1);
        let position = hbt.position(1);

        // your algo
    }
}
simsim-14 commented 5 months ago

Oh okay, so that would still have worked if we had

let mut hbt = LiveBuilder::new() .register("binancefutures", binance_futures), .register("dummyexchange", exchange_2), .add("binancefutures", "BTCUSDT", 0.1, 0.001) // asset_no: 0 .add("dummyexchange", "ETHUSDT", 0.01, 0.001) // asset_no: 1 .build() .unwrap();

?

Thanks for the answer.

nkaz001 commented 5 months ago

yes, that's the planned usage of the api.

pepi99 commented 5 months ago

Ok, now I understand. Thanks.