Skip to content

Commit

Permalink
bitfinex: fix potential panic caused by wrapper issues cmd (thrasher-…
Browse files Browse the repository at this point in the history
…corp#1118)

* bitfinex: fix potential panic caused by wrapper issues cmd

* bitfinex: add tests and disallow empty base, empty quote is fine.

* rm quote check

Co-authored-by: Ryan O'Hara-Reid <[email protected]>
  • Loading branch information
shazbert and Ryan O'Hara-Reid authored Jan 24, 2023
1 parent 1d779c3 commit 05558aa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
5 changes: 1 addition & 4 deletions cmd/exchange_wrapper_issues/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1139,10 +1139,7 @@ func disruptFormatting(p currency.Pair) (currency.Pair, error) {
if p.Base.IsEmpty() {
return currency.EMPTYPAIR, errors.New("cannot disrupt formatting as base is not populated")
}
if p.Quote.IsEmpty() {
return currency.EMPTYPAIR, errors.New("cannot disrupt formatting as quote is not populated")
}

// NOTE: Quote can be empty for margin funding
return currency.Pair{
Base: p.Base.Upper(),
Quote: p.Quote.Lower(),
Expand Down
18 changes: 14 additions & 4 deletions cmd/exchange_wrapper_issues/wrapperconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"secret": "Secret",
"otpSecret": "-"
},
"binanceus": {
"key": "Key",
"secret": "Secret",
"otpSecret": "-"
},
"bitfinex": {
"key": "Key",
"secret": "Secret",
Expand Down Expand Up @@ -80,6 +85,11 @@
"secret": "Secret",
"otpSecret": "-"
},
"bybit": {
"key": "Key",
"secret": "Secret",
"otpSecret": "-"
},
"coinbasepro": {
"key": "Key",
"secret": "Secret",
Expand Down Expand Up @@ -148,10 +158,10 @@
"otpSecret": "-"
},
"okx": {
"key": "Key",
"secret": "Secret",
"clientID": "ClientID",
"otpSecret": "-"
"key": "Key",
"secret": "Secret",
"clientID": "ClientID",
"otpSecret": "-"
},
"poloniex": {
"key": "Key",
Expand Down
15 changes: 15 additions & 0 deletions exchanges/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,21 @@ func TestFixCasing(t *testing.T) {
if ret != "fUSD" {
t.Errorf("unexpected result: %v", ret)
}

_, err = b.fixCasing(currency.NewPair(currency.EMPTYCODE, currency.BTC), asset.MarginFunding)
if !errors.Is(err, currency.ErrCurrencyPairEmpty) {
t.Fatalf("received: '%v' but expected: '%v'", err, currency.ErrCurrencyPairEmpty)
}

_, err = b.fixCasing(currency.NewPair(currency.BTC, currency.EMPTYCODE), asset.MarginFunding)
if !errors.Is(err, nil) {
t.Fatalf("received: '%v' but expected: '%v'", err, nil)
}

_, err = b.fixCasing(currency.EMPTYPAIR, asset.MarginFunding)
if !errors.Is(err, currency.ErrCurrencyPairEmpty) {
t.Fatalf("received: '%v' but expected: '%v'", err, currency.ErrCurrencyPairEmpty)
}
}

func Test_FormatExchangeKlineInterval(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions exchanges/bitfinex/bitfinex_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,9 @@ func (b *Bitfinex) GetHistoricCandlesExtended(ctx context.Context, pair currency
}

func (b *Bitfinex) fixCasing(in currency.Pair, a asset.Item) (string, error) {
if in.IsEmpty() || in.Base.IsEmpty() {
return "", currency.ErrCurrencyPairEmpty
}
var checkString [2]byte
if a == asset.Spot || a == asset.Margin {
checkString[0] = 't'
Expand Down

0 comments on commit 05558aa

Please sign in to comment.