mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
core: pull out RecoverTrade method
This commit is contained in:
parent
fad8642a59
commit
2abd84aec9
|
@ -101,11 +101,8 @@ func (c *TradeCollector) Recover(ctx context.Context, ex types.ExchangeTradeHist
|
|||
|
||||
cnt := 0
|
||||
for _, td := range trades {
|
||||
logrus.Debugf("checking trade: %s", td.String())
|
||||
if c.processTrade(td) {
|
||||
logrus.Infof("recovered trade: %s", td.String())
|
||||
if c.RecoverTrade(td) {
|
||||
cnt++
|
||||
c.EmitRecover(td)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,6 +110,19 @@ func (c *TradeCollector) Recover(ctx context.Context, ex types.ExchangeTradeHist
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *TradeCollector) RecoverTrade(td types.Trade) bool {
|
||||
logrus.Debugf("checking trade: %s", td.String())
|
||||
if c.processTrade(td) {
|
||||
logrus.Infof("recovered trade: %s", td.String())
|
||||
c.EmitRecover(td)
|
||||
return true
|
||||
}
|
||||
|
||||
// add to the trade store, and then we can recover it when an order is matched
|
||||
c.tradeStore.Add(td)
|
||||
return false
|
||||
}
|
||||
|
||||
// Process filters the received trades and see if there are orders matching the trades
|
||||
// if we have the order in the order store, then the trade will be considered for the position.
|
||||
// profit will also be calculated.
|
||||
|
|
|
@ -16,7 +16,7 @@ func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) {
|
|||
collector := NewTradeCollector(symbol, position, orderStore)
|
||||
assert.NotNil(t, collector)
|
||||
|
||||
matched := collector.ProcessTrade(types.Trade{
|
||||
matched := collector.RecoverTrade(types.Trade{
|
||||
ID: 1,
|
||||
OrderID: 399,
|
||||
Exchange: types.ExchangeBinance,
|
||||
|
@ -28,7 +28,7 @@ func TestTradeCollector_ShouldNotCountDuplicatedTrade(t *testing.T) {
|
|||
IsBuyer: true,
|
||||
})
|
||||
assert.False(t, matched, "should be added to the trade store")
|
||||
assert.Equal(t, 1, len(collector.tradeStore.Trades()), "should have one trade in the trade store")
|
||||
assert.Equal(t, 1, len(collector.tradeStore.Trades()), "should have 1 trade in the trade store")
|
||||
|
||||
orderStore.Add(types.Order{
|
||||
SubmitOrder: types.SubmitOrder{
|
||||
|
|
Loading…
Reference in New Issue
Block a user