pass types.SubmitOrder by value

This commit is contained in:
c9s 2020-10-13 18:08:02 +08:00
parent ec23266cc2
commit a91f851ac7
8 changed files with 17 additions and 17 deletions

View File

@ -25,11 +25,11 @@ type BackTestTrader struct {
SourceKLines []types.KLine
ProfitAndLossCalculator *accounting.ProfitAndLossCalculator
doneOrders []*types.SubmitOrder
pendingOrders []*types.SubmitOrder
doneOrders []types.SubmitOrder
pendingOrders []types.SubmitOrder
}
func (trader *BackTestTrader) SubmitOrder(cxt context.Context, order *types.SubmitOrder) {
func (trader *BackTestTrader) SubmitOrder(ctx context.Context, order types.SubmitOrder) {
trader.pendingOrders = append(trader.pendingOrders, order)
}

View File

@ -37,9 +37,9 @@ type OrderProcessor struct {
Trader *Trader `json:"-"`
}
func (p *OrderProcessor) Submit(ctx context.Context, order *types.SubmitOrder) error {
func (p *OrderProcessor) Submit(ctx context.Context, order types.SubmitOrder) error {
/*
tradingCtx := p.Trader.Context
tradingCtx := p.OrderExecutor.Context
currentPrice := tradingCtx.CurrentPrice
market := order.Market
quantity := order.Quantity

View File

@ -17,11 +17,11 @@ import (
// SingleExchangeStrategy represents the single Exchange strategy
type SingleExchangeStrategy interface {
Run(ctx context.Context, trader types.Trader, session *ExchangeSession) error
Run(ctx context.Context, trader types.OrderExecutor, session *ExchangeSession) error
}
type CrossExchangeStrategy interface {
Run(ctx context.Context, trader types.Trader, sessions map[string]*ExchangeSession) error
Run(ctx context.Context, trader types.OrderExecutor, sessions map[string]*ExchangeSession) error
}
// ExchangeSession presents the exchange connection session
@ -237,7 +237,7 @@ func (trader *Trader) Run(ctx context.Context) error {
}
/*
func (trader *Trader) RunStrategyWithHotReload(ctx context.Context, strategy SingleExchangeStrategy, configFile string) (chan struct{}, error) {
func (trader *OrderExecutor) RunStrategyWithHotReload(ctx context.Context, strategy SingleExchangeStrategy, configFile string) (chan struct{}, error) {
var done = make(chan struct{})
var configWatcherDone = make(chan struct{})
@ -315,7 +315,7 @@ func (trader *Trader) RunStrategyWithHotReload(ctx context.Context, strategy Sin
*/
/*
func (trader *Trader) RunStrategy(ctx context.Context, strategy SingleExchangeStrategy) (chan struct{}, error) {
func (trader *OrderExecutor) RunStrategy(ctx context.Context, strategy SingleExchangeStrategy) (chan struct{}, error) {
trader.reportTimer = time.AfterFunc(1*time.Second, func() {
trader.reportPnL()
})
@ -363,7 +363,7 @@ func (trader *Trader) Notify(msg string, args ...interface{}) {
}
}
func (trader *Trader) SubmitOrder(ctx context.Context, order *types.SubmitOrder) {
func (trader *Trader) SubmitOrder(ctx context.Context, order types.SubmitOrder) {
trader.Notify(":memo: Submitting %s %s %s order with quantity: %s", order.Symbol, order.Type, order.Side, order.QuantityString, order)
orderProcessor := &OrderProcessor{

View File

@ -220,7 +220,7 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
}, nil
}
func (e *Exchange) SubmitOrder(ctx context.Context, order *types.SubmitOrder) error {
func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) error {
/*
limit order example

View File

@ -38,7 +38,7 @@ func (e *Exchange) NewStream() types.Stream {
return NewStream(e.key, e.secret)
}
func (e *Exchange) SubmitOrder(ctx context.Context, order *types.SubmitOrder) error {
func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) error {
orderType, err := toLocalOrderType(order.Type)
if err != nil {
return err

View File

@ -49,7 +49,7 @@ func (s *Strategy) SetMaxAssetQuantity(q float64) *Strategy {
return s
}
func (s *Strategy) Run(ctx context.Context, trader types.Trader, session *bbgo.ExchangeSession) error {
func (s *Strategy) Run(ctx context.Context, orderExecutor types.OrderExecutor, session *bbgo.ExchangeSession) error {
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
session.Stream.OnKLineClosed(func(kline types.KLine) {
@ -70,7 +70,7 @@ func (s *Strategy) Run(ctx context.Context, trader types.Trader, session *bbgo.E
}
}
trader.SubmitOrder(ctx, &types.SubmitOrder{
orderExecutor.SubmitOrder(ctx, types.SubmitOrder{
Symbol: kline.Symbol,
Side: types.SideTypeBuy,
Type: types.OrderTypeMarket,

View File

@ -48,7 +48,7 @@ type Exchange interface {
QueryWithdrawHistory(ctx context.Context, asset string, since, until time.Time) (allWithdraws []Withdraw, err error)
SubmitOrder(ctx context.Context, order *SubmitOrder) error
SubmitOrder(ctx context.Context, order SubmitOrder) error
}
type TradeQueryOptions struct {

View File

@ -2,6 +2,6 @@ package types
import "context"
type Trader interface {
SubmitOrder(ctx context.Context, order *SubmitOrder)
type OrderExecutor interface {
SubmitOrder(ctx context.Context, order SubmitOrder)
}