Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: add symbol exchange info and basic method rules #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions binance/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"math"
"strconv"

"github.com/adshao/go-binance/v2"
)

// SymbolBalance get available amount in user wallet.
Expand Down Expand Up @@ -42,3 +44,13 @@ func (me *Binance) SymbolPrice(symbol, buyWith, interval string) (float64, error

return symbolPrice, nil
}

// SymbolExchangeInfo get the last symbol price.
func (me *Binance) SymbolExchangeInfo(symbol string) (*binance.ExchangeInfo, error) {
res, err := me.Binance.NewExchangeInfoService().Symbol(symbol).Do(*me.Context)
if err != nil {
return nil, err
}

return res, nil
}
15 changes: 15 additions & 0 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ func (me *Bot) sell(trade config.Trade, price float64) error {
return nil
}

// check rules before buy.
func (me *Bot) rules(trade *config.Trade) error {
exchange, err := me.Binance.SymbolExchangeInfo(trade.Symbol)
if err != nil {
return err
}

minNotional := exchange.Symbols[0].MinNotionalFilter().MinNotional
minQuantity := exchange.Symbols[0].LotSizeFilter().MinQuantity
me.Log.Debug().Msgf("[%s] minNotional=%.2f minQuantity=%.2f",
trade.Symbol, minNotional, minQuantity)

return nil
}

// format welcome message notification.
func (me *Bot) welcomeMessage(config config.Config) string {
msg := fmt.Sprintf("%s started! :money_mouth_face:\n\n", config.Name)
Expand Down