Skip to content

Commit

Permalink
core: drop ExchangeAmountFeeProtect interface (ftx)
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 14, 2024
1 parent f86fc8c commit e3972e0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 74 deletions.
58 changes: 11 additions & 47 deletions pkg/bbgo/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,16 @@ func TestLoadConfig(t *testing.T) {
assert.Equal(t, map[string]interface{}{
"sessions": map[string]interface{}{
"max": map[string]interface{}{
"exchange": "max",
"envVarPrefix": "MAX",
"takerFeeRate": 0.,
"makerFeeRate": 0.,
"modifyOrderAmountForFee": false,
"exchange": "max",
"envVarPrefix": "MAX",
"takerFeeRate": 0.,
"makerFeeRate": 0.,
},
"binance": map[string]interface{}{
"exchange": "binance",
"envVarPrefix": "BINANCE",
"takerFeeRate": 0.,
"makerFeeRate": 0.,
"modifyOrderAmountForFee": false,
},
"ftx": map[string]interface{}{
"exchange": "ftx",
"envVarPrefix": "FTX",
"takerFeeRate": 0.,
"makerFeeRate": 0.,
"modifyOrderAmountForFee": true,
"exchange": "binance",
"envVarPrefix": "BINANCE",
"takerFeeRate": 0.,
"makerFeeRate": 0.,
},
},
"build": map[string]interface{}{
Expand Down Expand Up @@ -155,43 +146,16 @@ func TestLoadConfig(t *testing.T) {
assert.NotNil(t, config.Persistence.Json)
},
},

{
name: "order_executor",
args: args{configFile: "testdata/order_executor.yaml"},
wantErr: false,
f: func(t *testing.T, config *Config) {
assert.Len(t, config.Sessions, 2)

session, ok := config.Sessions["max"]
assert.True(t, ok)
assert.NotNil(t, session)

riskControls := config.RiskControls
assert.NotNil(t, riskControls)
assert.NotNil(t, riskControls.SessionBasedRiskControl)

conf, ok := riskControls.SessionBasedRiskControl["max"]
assert.True(t, ok)
assert.NotNil(t, conf)
assert.NotNil(t, conf.OrderExecutor)
assert.NotNil(t, conf.OrderExecutor.BySymbol)

executorConf, ok := conf.OrderExecutor.BySymbol["BTCUSDT"]
assert.True(t, ok)
assert.NotNil(t, executorConf)
},
},
{
name: "backtest",
args: args{configFile: "testdata/backtest.yaml"},
wantErr: false,
f: func(t *testing.T, config *Config) {
assert.Len(t, config.ExchangeStrategies, 1)
assert.NotNil(t, config.Backtest)
assert.NotNil(t, config.Backtest.Account)
assert.NotNil(t, config.Backtest.Account["binance"].Balances)
assert.Len(t, config.Backtest.Account["binance"].Balances, 2)
assert.NotNil(t, config.Backtest.Accounts)
assert.NotNil(t, config.Backtest.Accounts["binance"].Balances)
assert.Len(t, config.Backtest.Accounts["binance"].Balances, 2)
},
},
}
Expand Down
17 changes: 3 additions & 14 deletions pkg/bbgo/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ type ExchangeSession struct {
SubAccount string `json:"subAccount,omitempty" yaml:"subAccount,omitempty"`

// Withdrawal is used for enabling withdrawal functions
Withdrawal bool `json:"withdrawal,omitempty" yaml:"withdrawal,omitempty"`
MakerFeeRate fixedpoint.Value `json:"makerFeeRate" yaml:"makerFeeRate"`
TakerFeeRate fixedpoint.Value `json:"takerFeeRate" yaml:"takerFeeRate"`
ModifyOrderAmountForFee bool `json:"modifyOrderAmountForFee" yaml:"modifyOrderAmountForFee"`
Withdrawal bool `json:"withdrawal,omitempty" yaml:"withdrawal,omitempty"`
MakerFeeRate fixedpoint.Value `json:"makerFeeRate" yaml:"makerFeeRate"`
TakerFeeRate fixedpoint.Value `json:"takerFeeRate" yaml:"takerFeeRate"`

// PublicOnly is used for setting the session to public only (without authentication, no private user data)
PublicOnly bool `json:"publicOnly,omitempty" yaml:"publicOnly"`
Expand Down Expand Up @@ -319,16 +318,6 @@ func (session *ExchangeSession) Init(ctx context.Context, environ *Environment)
}
}

if session.ModifyOrderAmountForFee {
amountProtectExchange, ok := session.Exchange.(types.ExchangeAmountFeeProtect)
if !ok {
return fmt.Errorf("exchange %s does not support order amount protection", session.ExchangeName.String())
}

fees := types.ExchangeFee{MakerFeeRate: session.MakerFeeRate, TakerFeeRate: session.TakerFeeRate}
amountProtectExchange.SetModifyOrderAmountForFee(fees)
}

if session.UseHeikinAshi {
// replace the existing market data stream
session.MarketDataStream = &types.HeikinAshiStream{
Expand Down
2 changes: 1 addition & 1 deletion pkg/bbgo/testdata/backtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ backtest:
# see here for more details
# https://www.investopedia.com/terms/m/maximum-drawdown-mdd.asp
startTime: "2020-01-01"
account:
accounts:
binance:
makerFeeRate: 15
takerFeeRate: 15
Expand Down
8 changes: 0 additions & 8 deletions pkg/bbgo/testdata/strategy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@ sessions:
envVarPrefix: MAX
takerFeeRate: 0
makerFeeRate: 0
modifyOrderAmountForFee: false
binance:
exchange: binance
envVarPrefix: BINANCE
takerFeeRate: 0
makerFeeRate: 0
modifyOrderAmountForFee: false
ftx:
exchange: ftx
envVarPrefix: FTX
takerFeeRate: 0
makerFeeRate: 0
modifyOrderAmountForFee: true

exchangeStrategies:
- on: ["binance"]
Expand Down
4 changes: 0 additions & 4 deletions pkg/types/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ type ExchangeDefaultFeeRates interface {
DefaultFeeRates() ExchangeFee
}

type ExchangeAmountFeeProtect interface {
SetModifyOrderAmountForFee(ExchangeFee)
}

//go:generate mockgen -destination=mocks/mock_exchange_trade_history.go -package=mocks . ExchangeTradeHistoryService
type ExchangeTradeHistoryService interface {
QueryTrades(ctx context.Context, symbol string, options *TradeQueryOptions) ([]Trade, error)
Expand Down

0 comments on commit e3972e0

Please sign in to comment.