examples/engine_with_historic_candles.rs breaks
HereticSK opened this issue · comments
File path issue
Tried run examples with the following command
cd barter-rs # Same level as barter-rs/Cargo.toml
cargo run --example engine_with_historic_candles
rust complains the data file candles_1h.json
can not be found
Running
target/debug/examples/engine_with_historic_candles
thread 'main' panicked at 'failed to read file: Os { code: 2, kind: NotFound, message: "No such file or directory" }', examples/engine_with_historic_candles.rs:116:71
I guess this is because the path of the data file lives in barter-rs/examples/data/candles_1h.json
, while the current working directory is barter-rs
. The line causing trouble is in engine_with_historic_candles.rs
line 116: let candles = fs::read_to_string("barter-rs/examples/data/candles_1h.json").expect("failed to read file");
When I changed the path to fs::read_to_string("examples/data/candles_1h.json")
, The error can be fixed.
I am not sure if this is a bug, or I am in the wrong directory? What is the expected working directory for a new user to run the example with cargo run --example engine_with_historic_candles
?
Data out of sync
The example requires the example has a field close_time
:
candles
.into_iter()
.map(|candle| MarketEvent {
exchange_time: candle.close_time,
received_time: Utc::now(),
exchange: Exchange::from("binance"),
......
But the example data in candles_1h.json
only has start_time
and end_time
, but no close_time
:
{
"start_time": "2022-04-05 20:00:00.000000000 UTC",
"end_time": "2022-04-05 21:00:00.000000000 UTC",
"open": 1000.0,
"high": 1100.0,
"low": 900.0,
"close": 1050.0,
"volume": 1000000000.0,
"trade_count": 100
},
resulting in this error:
Running
target/debug/examples/engine_with_historic_candles
thread 'main' panicked at 'failed to parse candles String: Error("missing fieldclose_time
", line: 11, column: 3)', examples/engine_with_historic_candles.rs:119:55
This can also be fixed by replacing all the end_time
fields with close_time
in candles_1h.json
. But I am not sure whether the start_time
and end_time
fileds are still valid fields to keep.
Hey, thanks for raising this.
I re-factored end_time -> close_time in barter data without thinking about this static file example!
Regarding the relative file path. I've updated to your suggestion. I've been running as part of a workspace (barter + barter-data + etc) and it did not occur to me this was an issue.
Please update to barter-rs 0.8.12 for the updates - thanks again it's much appreciated!