Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
feat: split trading fee into maker and taker
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeyax committed Mar 7, 2024
1 parent b23db70 commit 3b181dc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
10 changes: 8 additions & 2 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ trading_options:
# For example, if you set this to 5, the bot will sell the coin if it rises 5% above the price at which it was bought.
take_profit: .8

# Trading fee in % per trade.
# Trading fee for the maker in % per trade.
#
# Binance:
# - If using BNB for fees, set this to 0.075 and make sure have enough BNB in your account.
trading_fee: 0.075
trading_fee_maker: 0.075

# Trading fee for the taker in % per trade.
#
# Binance:
# - If using BNB for fees, set this to 0.075 and make sure have enough BNB in your account.
trading_fee_taker: 0.075

# The amount of time in MINUTES to wait before buying the same coin again.
# This is to prevent buying the same coin multiple times in a short period of time.
Expand Down
9 changes: 5 additions & 4 deletions internal/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ func (b *Bot) sell(ctx context.Context, wg *sync.WaitGroup) {
profitOrLossText = "loss"
}

estimatedProfitLoss := (currentPrice - buyPrice) * boughtCoin.Volume * (1 - (b.config.TradingOptions.TradingFee))
estimatedProfitLossWithFees := b.config.TradingOptions.Quantity * (priceChangePercentage - (b.config.TradingOptions.TradingFee)) / 100
estimatedProfitLoss := (currentPrice - buyPrice) * boughtCoin.Volume * (1 - (b.config.TradingOptions.TradingFeeMaker + b.config.TradingOptions.TradingFeeTaker))
estimatedProfitLossWithFees := b.config.TradingOptions.Quantity * (priceChangePercentage - (b.config.TradingOptions.TradingFeeMaker + b.config.TradingOptions.TradingFeeTaker)) / 100
msg := fmt.Sprintf(
"Selling %.2f %s. Estimated %s: $%s %s%% (w/ fees: $%s %s%%)",
boughtCoin.Volume,
Expand All @@ -222,7 +222,7 @@ func (b *Bot) sell(ctx context.Context, wg *sync.WaitGroup) {
strconv.FormatFloat(estimatedProfitLoss, 'f', 2, 64),
strconv.FormatFloat(priceChangePercentage, 'f', 2, 64),
strconv.FormatFloat(estimatedProfitLossWithFees, 'f', 2, 64),
strconv.FormatFloat(priceChangePercentage-(b.config.TradingOptions.TradingFee), 'f', 2, 64),
strconv.FormatFloat(priceChangePercentage-(b.config.TradingOptions.TradingFeeMaker+b.config.TradingOptions.TradingFeeTaker), 'f', 2, 64),
)

b.sellLog.Infow(
Expand All @@ -231,7 +231,8 @@ func (b *Bot) sell(ctx context.Context, wg *sync.WaitGroup) {
"buyPrice", buyPrice,
"currentPrice", currentPrice,
"priceChangePercentage", priceChangePercentage,
"tradingFee", b.config.TradingOptions.TradingFee,
"tradingFeeMaker", b.config.TradingOptions.TradingFeeMaker,
"tradingFeeTaker", b.config.TradingOptions.TradingFeeTaker,
"quantity", b.config.TradingOptions.Quantity,
"testMode", b.config.EnableTestMode,
)
Expand Down
27 changes: 14 additions & 13 deletions internal/bot/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@ func TestBot_sell(t *testing.T) {
EnableTestMode: true,
LoggingOptions: config.LoggingOptions{Enable: false},
TradingOptions: config.TradingOptions{
ChangeInPrice: 0.5,
PairWith: "USDT",
Quantity: 15,
TakeProfit: 0.1,
StopLoss: 5,
TradingFee: 0.15,
ChangeInPrice: 0.5,
PairWith: "USDT",
Quantity: 15,
TakeProfit: 0.1,
StopLoss: 5,
TradingFeeMaker: 0.075,
TradingFeeTaker: 0.075,
},
}

Expand Down Expand Up @@ -235,13 +236,13 @@ func TestBot_sell_with_trailing_stop_loss(t *testing.T) {
EnableTestMode: true,
LoggingOptions: config.LoggingOptions{Enable: false},
TradingOptions: config.TradingOptions{
ChangeInPrice: 0.5,
PairWith: "USDT",
Quantity: 10,
TakeProfit: 10,
StopLoss: 5,
TradingFee: 0.15,
TrailingStopOptions: config.TrailingStopOptions{
ChangeInPrice: 0.5,
PairWith: "USDT",
Quantity: 10,
TakeProfit: 10,
StopLoss: 5,
TradingFeeMaker: 0.075,
TradingFeeTaker: 0.075, TrailingStopOptions: config.TrailingStopOptions{
Enable: true,
TrailingStopLoss: 1,
TrailingTakeProfit: 1,
Expand Down
3 changes: 2 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func TestLoad(t *testing.T) {
assert.Equal(t, float64(10), config.TradingOptions.ChangeInPrice)
assert.Equal(t, float64(5), config.TradingOptions.StopLoss)
assert.Equal(t, 0.8, config.TradingOptions.TakeProfit)
assert.Equal(t, 0.075, config.TradingOptions.TradingFee)
assert.Equal(t, 0.075, config.TradingOptions.TradingFeeMaker)
assert.Equal(t, 0.075, config.TradingOptions.TradingFeeTaker)
assert.Equal(t, 0, config.TradingOptions.CoolOffDelay)

assert.Equal(t, true, config.TradingOptions.TrailingStopOptions.Enable)
Expand Down
13 changes: 9 additions & 4 deletions internal/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ type TradingOptions struct {
// For example, if you set this to 5, the bot will sell the coin if it rises 5% above the price at which it was bought.
TakeProfit float64 `mapstructure:"take_profit"`

// Trading fee in % per trade.
// Trading fee for the maker in % per trade.
//
// Binance:
// - If using 0.75% (using BNB for fees) you must have BNB in your account to cover trading fees.
// - If using BNB for fees, it MUST be enabled in your Binance 'Dashboard' page (checkbox).
TradingFee float64 `mapstructure:"trading_fee"`
// - If using BNB for fees, set this to 0.075 and make sure have enough BNB in your account.
TradingFeeMaker float64 `mapstructure:"trading_fee_maker"`

// Trading fee for the taker in % per trade.
//
// Binance:
// - If using BNB for fees, set this to 0.075 and make sure have enough BNB in your account.
TradingFeeTaker float64 `mapstructure:"trading_fee_taker"`

// The amount of time in MINUTES to wait before buying the same coin again.
// This is to prevent buying the same coin multiple times in a short period of time.
Expand Down

0 comments on commit 3b181dc

Please sign in to comment.