mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
service: drop unused methods
Signed-off-by: c9s <yoanlin93@gmail.com>
This commit is contained in:
parent
bd991a7080
commit
f4bb7bd231
|
@ -2,7 +2,6 @@ package service
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -335,49 +334,6 @@ func (s *TradeService) Load(ctx context.Context, id int64) (*types.Trade, error)
|
|||
return nil, errors.Wrapf(ErrTradeNotFound, "trade id:%d not found", id)
|
||||
}
|
||||
|
||||
func (s *TradeService) Mark(ctx context.Context, id int64, strategyID string) error {
|
||||
result, err := s.DB.NamedExecContext(ctx, "UPDATE `trades` SET `strategy` = :strategy WHERE `id` = :id", map[string]interface{}{
|
||||
"id": id,
|
||||
"strategy": strategyID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnt, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cnt == 0 {
|
||||
return fmt.Errorf("trade id:%d not found", id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *TradeService) UpdatePnL(ctx context.Context, id int64, pnl float64) error {
|
||||
result, err := s.DB.NamedExecContext(ctx, "UPDATE `trades` SET `pnl` = :pnl WHERE `id` = :id", map[string]interface{}{
|
||||
"id": id,
|
||||
"pnl": pnl,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cnt, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cnt == 0 {
|
||||
return fmt.Errorf("trade id:%d not found", id)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func queryTradesSQL(options QueryTradesOptions) string {
|
||||
ordering := "ASC"
|
||||
switch v := strings.ToUpper(options.Ordering); v {
|
||||
|
|
|
@ -38,24 +38,6 @@ func Test_tradeService(t *testing.T) {
|
|||
Time: types.Time(time.Now()),
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = service.Mark(ctx, 1, "grid")
|
||||
assert.NoError(t, err)
|
||||
|
||||
tradeRecord, err := service.Load(ctx, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, tradeRecord)
|
||||
assert.True(t, tradeRecord.StrategyID.Valid)
|
||||
assert.Equal(t, "grid", tradeRecord.StrategyID.String)
|
||||
|
||||
err = service.UpdatePnL(ctx, 1, 10.0)
|
||||
assert.NoError(t, err)
|
||||
|
||||
tradeRecord, err = service.Load(ctx, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, tradeRecord)
|
||||
assert.True(t, tradeRecord.PnL.Valid)
|
||||
assert.Equal(t, 10.0, tradeRecord.PnL.Float64)
|
||||
}
|
||||
|
||||
func Test_queryTradingVolumeSQL(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user