Skip to content

Commit

Permalink
fix: ticker not found causes error
Browse files Browse the repository at this point in the history
Skip the not-found tickers
  • Loading branch information
dasbd72 committed Aug 11, 2024
1 parent de9cbc4 commit c50162a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions manager/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package manager
import (
"context"
"fmt"
"log/slog"

binanceModels "github.com/dasbd72/go-exchange-sdk/binance/pkg/models"
"github.com/dasbd72/go-exchange-sdk/max"
Expand Down Expand Up @@ -44,7 +45,7 @@ func (c *Client) GetBalance(ctx context.Context) (*Balance, error) {
btcPrice := averagePrice.Price.Float64()

totalBalanceUsdt += sum * btcPrice
fmt.Println("Binance balance: ", sum*btcPrice)
slog.Info(fmt.Sprintf("Binance balance: %f", sum*btcPrice))
return nil
},
func() error {
Expand All @@ -66,6 +67,10 @@ func (c *Client) GetBalance(ctx context.Context) (*Balance, error) {
if err != nil {
return err
}
if len(ticker.Tickers) == 0 {
slog.Warn(fmt.Sprintf("no ticker found for %s-USDT", detail.Ccy))
continue
}
price = ticker.Tickers[0].Last.Float64()
}
sum += detail.Eq.Float64() * price
Expand All @@ -83,6 +88,10 @@ func (c *Client) GetBalance(ctx context.Context) (*Balance, error) {
if err != nil {
return err
}
if len(ticker.Tickers) == 0 {
slog.Warn(fmt.Sprintf("no ticker found for %s-USDT", f.Ccy))
continue
}
price = ticker.Tickers[0].Last.Float64()
}
sum += f.Bal.Float64() * price
Expand All @@ -104,7 +113,7 @@ func (c *Client) GetBalance(ctx context.Context) (*Balance, error) {
sum += s.Amt.Float64() * price
}
totalBalanceUsdt += sum
fmt.Println("OKX balance: ", sum)
slog.Info(fmt.Sprintf("OKX balance: %f", sum))
return nil
},
func() error {
Expand All @@ -125,7 +134,7 @@ func (c *Client) GetBalance(ctx context.Context) (*Balance, error) {
}

totalBalanceUsdt += sum
fmt.Println("Bitfinex balance: ", sum)
slog.Info(fmt.Sprintf("Bitfinex balance: %f", sum))
return nil
},
func() error {
Expand Down

0 comments on commit c50162a

Please sign in to comment.