mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
Merge pull request #173 from c9s/refactor/fixed-point-fee
refactor: use fixedpoint to store fee
This commit is contained in:
commit
b3f613227a
|
@ -47,8 +47,8 @@ type SimplePriceMatching struct {
|
|||
|
||||
Account *types.Account
|
||||
|
||||
MakerCommission float64 `json:"makerCommission"`
|
||||
TakerCommission float64 `json:"takerCommission"`
|
||||
MakerCommission fixedpoint.Value `json:"makerCommission"`
|
||||
TakerCommission fixedpoint.Value `json:"takerCommission"`
|
||||
|
||||
tradeUpdateCallbacks []func(trade types.Trade)
|
||||
orderUpdateCallbacks []func(order types.Order)
|
||||
|
@ -205,9 +205,9 @@ func (m *SimplePriceMatching) newTradeFromOrder(order types.Order, isMaker bool)
|
|||
// MAX uses 0.050% for maker and 0.15% for taker
|
||||
var commission = DefaultFeeRate
|
||||
if isMaker && m.Account.MakerCommission > 0 {
|
||||
commission = 0.0001 * m.Account.MakerCommission // binance uses 10~15
|
||||
commission = fixedpoint.NewFromFloat(0.0001).Mul(m.Account.MakerCommission).Float64() // binance uses 10~15
|
||||
} else if m.Account.TakerCommission > 0 {
|
||||
commission = 0.0001 * m.Account.TakerCommission // binance uses 10~15
|
||||
commission = fixedpoint.NewFromFloat(0.0001).Mul(m.Account.TakerCommission).Float64() // binance uses 10~15
|
||||
}
|
||||
|
||||
var fee float64
|
||||
|
|
|
@ -113,8 +113,8 @@ func (t Backtest) ParseStartTime() (time.Time, error) {
|
|||
}
|
||||
|
||||
type BacktestAccount struct {
|
||||
MakerCommission float64 `json:"makerCommission"`
|
||||
TakerCommission float64 `json:"takerCommission"`
|
||||
MakerCommission fixedpoint.Value `json:"makerCommission"`
|
||||
TakerCommission fixedpoint.Value `json:"takerCommission"`
|
||||
BuyerCommission int `json:"buyerCommission"`
|
||||
SellerCommission int `json:"sellerCommission"`
|
||||
Balances BacktestAccountBalanceMap `json:"balances" yaml:"balances"`
|
||||
|
|
|
@ -378,8 +378,8 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
|
|||
}
|
||||
|
||||
a := &types.Account{
|
||||
MakerCommission: float64(account.MakerCommission),
|
||||
TakerCommission: float64(account.TakerCommission),
|
||||
MakerCommission: fixedpoint.NewFromInt64(account.MakerCommission),
|
||||
TakerCommission: fixedpoint.NewFromInt64(account.TakerCommission),
|
||||
}
|
||||
a.UpdateBalances(balances)
|
||||
return a, nil
|
||||
|
|
|
@ -75,8 +75,8 @@ func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
|
|||
|
||||
bps := fixedpoint.NewFromFloat(10000)
|
||||
a := &types.Account{
|
||||
MakerCommission: fixedpoint.NewFromFloat(resp.Result.MakerFee).Mul(bps).Float64(),
|
||||
TakerCommission: fixedpoint.NewFromFloat(resp.Result.TakerFee).Mul(bps).Float64(),
|
||||
MakerCommission: fixedpoint.NewFromFloat(resp.Result.MakerFee).Mul(bps),
|
||||
TakerCommission: fixedpoint.NewFromFloat(resp.Result.TakerFee).Mul(bps),
|
||||
}
|
||||
|
||||
balances, err := e.QueryAccountBalances(ctx)
|
||||
|
|
|
@ -365,6 +365,6 @@ func TestExchange_QueryAccount(t *testing.T) {
|
|||
expected.Locked = expected.Locked.Sub(expected.Available)
|
||||
assert.Equal(t, expected, b)
|
||||
|
||||
assert.Equal(t, 0.0002*10000, resp.MakerCommission)
|
||||
assert.Equal(t, 0.0005*10000, resp.TakerCommission)
|
||||
assert.Equal(t, fixedpoint.NewFromFloat(0.0002).Mul(fixedpoint.NewFromInt64(10000)), resp.MakerCommission)
|
||||
assert.Equal(t, fixedpoint.NewFromFloat(0.0005).Mul(fixedpoint.NewFromInt64(10000)), resp.TakerCommission)
|
||||
}
|
||||
|
|
|
@ -103,9 +103,9 @@ type Account struct {
|
|||
sync.Mutex `json:"-"`
|
||||
|
||||
// bps. 0.15% fee will be 15.
|
||||
MakerCommission float64 `json:"makerCommission,omitempty"`
|
||||
TakerCommission float64 `json:"takerCommission,omitempty"`
|
||||
AccountType string `json:"accountType,omitempty"`
|
||||
MakerCommission fixedpoint.Value `json:"makerCommission,omitempty"`
|
||||
TakerCommission fixedpoint.Value `json:"takerCommission,omitempty"`
|
||||
AccountType string `json:"accountType,omitempty"`
|
||||
|
||||
balances BalanceMap
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user