mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
add document for the backtest engine
This commit is contained in:
parent
7fb4d2f78d
commit
60e4442f85
|
@ -1,3 +1,30 @@
|
|||
/*
|
||||
The backtest process
|
||||
|
||||
The backtest engine loads the klines from the database into a kline-channel,
|
||||
there are multiple matching engine that matches the order sent from the strategy.
|
||||
|
||||
for each kline, the backtest engine:
|
||||
|
||||
1) load the kline, run matching logics to send out order update and trades to the user data stream.
|
||||
2) once the matching process for the kline is done, the kline will be pushed to the market data stream.
|
||||
3) go to 1 and load the next kline.
|
||||
|
||||
There are 2 ways that a strategy could work with backtest engine:
|
||||
|
||||
1. the strategy receives kline from the market data stream, and then it submits the order by the given market data to the backtest engine.
|
||||
backtest engine receives the order and then pushes the trade and order updates to the user data stream.
|
||||
|
||||
the strategy receives the trade and update its position.
|
||||
|
||||
2. the strategy places the orders when it starts. (like grid) the strategy then receives the order updates and then submit a new order
|
||||
by its order update message.
|
||||
|
||||
We need to ensure that:
|
||||
|
||||
1. if the strategy submits the order from the market data stream, since it's a separate goroutine, the strategy should block the backtest engine
|
||||
to process the trades before the next kline is published.
|
||||
*/
|
||||
package backtest
|
||||
|
||||
import (
|
||||
|
|
|
@ -93,6 +93,7 @@ func (s *Stream) Connect(ctx context.Context) error {
|
|||
continue
|
||||
}
|
||||
|
||||
// here we generate trades and order updates
|
||||
matching.processKLine(k)
|
||||
numKlines++
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user