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

libxc/binance: Better error message #3106

Open
wants to merge 2 commits into
base: master
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
21 changes: 13 additions & 8 deletions client/mm/libxc/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func (bnc *binance) refreshBalances(ctx context.Context) error {
var resp bntypes.Account
err := bnc.getAPI(ctx, "/api/v3/account", nil, true, true, &resp)
if err != nil {
return fmt.Errorf("error getting balances: %w", err)
return err
}

tokenIDsI := bnc.tokenIDs.Load()
Expand Down Expand Up @@ -643,7 +643,7 @@ func (bnc *binance) getCoinInfo(ctx context.Context) error {
coins := make([]*bntypes.CoinInfo, 0)
err := bnc.getAPI(ctx, "/sapi/v1/capital/config/getall", nil, true, true, &coins)
if err != nil {
return fmt.Errorf("error getting binance coin info: %w", err)
return err
}

bnc.readCoins(coins)
Expand All @@ -654,7 +654,7 @@ func (bnc *binance) getMarkets(ctx context.Context) (map[string]*bntypes.Market,
var exchangeInfo bntypes.ExchangeInfo
err := bnc.getAPI(ctx, "/api/v3/exchangeInfo", nil, false, false, &exchangeInfo)
if err != nil {
return nil, fmt.Errorf("error getting markets from Binance: %w", err)
return nil, err
}

marketsMap := make(map[string]*bntypes.Market, len(exchangeInfo.Symbols))
Expand Down Expand Up @@ -712,11 +712,11 @@ func (bnc *binance) Connect(ctx context.Context) (*sync.WaitGroup, error) {
}

if err := bnc.setBalances(ctx); err != nil {
return nil, err
return nil, fmt.Errorf("error getting balances")
}

if err := bnc.getUserDataStream(ctx); err != nil {
return nil, err
return nil, fmt.Errorf("error getting user data stream")
}

// Refresh balances periodically. This is just for safety as they should
Expand Down Expand Up @@ -1329,9 +1329,14 @@ func (bnc *binance) request(ctx context.Context, method, endpoint string, query,
Msg string `json:"msg"`
}
if err := dexnet.Do(req, thing, dexnet.WithSizeLimit(1<<24), dexnet.WithErrorParsing(&errPayload)); err != nil {
bnc.log.Errorf("request error from endpoint %s %q with query = %q, body = %q", method, endpoint, queryString, bodyString)
return fmt.Errorf("%w, bn code = %d, msg = %q", err, errPayload.Code, errPayload.Msg)
bnc.log.Errorf("request error from endpoint %s %q with query = %q, body = %q, err = %v, bn code = %d, msg = %q",
method, endpoint, queryString, bodyString, err, errPayload.Code, errPayload.Msg)
if errPayload.Msg != "" {
return fmt.Errorf("Binance error: %v (%d)", errPayload.Msg, errPayload.Code)
}
return err
}

return nil
}

Expand Down Expand Up @@ -1509,7 +1514,7 @@ func (bnc *binance) getUserDataStream(ctx context.Context) (err error) {

cm := dex.NewConnectionMaster(conn)
if err = cm.ConnectOnce(ctx); err != nil {
return nil, fmt.Errorf("user data stream connection error: %v", err)
return nil, err
}

return cm, nil
Expand Down
2 changes: 1 addition & 1 deletion client/mm/mm.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ func (m *MarketMaker) Connect(ctx context.Context) (*sync.WaitGroup, error) {
// Try to connect so we can update our balances and set the
// connected flag, but ignore errors.
if err := m.connectCEX(ctx, c); err != nil {
m.log.Infof("Could not connect to %q: %w", cexCfg.Name, err)
m.log.Infof("Could not connect to %q: %v", cexCfg.Name, err)
}
}
}
Expand Down
Loading