mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 16:55:15 +00:00
bbgo: add RecordPosition method
This commit is contained in:
parent
9faaed6892
commit
6088f7b542
|
@ -573,7 +573,35 @@ func (environ *Environment) Sync(ctx context.Context, userConfig ...*Config) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (environ *Environment) RecordPosition(position *types.Position, trade types.Trade, profit types.Profit) {
|
||||||
|
// skip for back-test
|
||||||
|
if environ.BacktestService != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if environ.DatabaseService == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if environ.ProfitService == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := environ.PositionService.Insert(position, trade, profit.Profit); err != nil {
|
||||||
|
log.WithError(err).Errorf("can not insert position record")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := environ.ProfitService.Insert(profit); err != nil {
|
||||||
|
log.WithError(err).Errorf("can not insert profit record: %+v", profit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (environ *Environment) RecordProfit(profit types.Profit) {
|
func (environ *Environment) RecordProfit(profit types.Profit) {
|
||||||
|
// skip for back-test
|
||||||
|
if environ.BacktestService != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if environ.DatabaseService == nil {
|
if environ.DatabaseService == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user