Skip to content

Commit

Permalink
Bybit: Add support for SOL options (thrasher-corp#1533)
Browse files Browse the repository at this point in the history
  • Loading branch information
gloriousCode authored May 6, 2024
1 parent 3ee65b9 commit ece58eb
Show file tree
Hide file tree
Showing 3 changed files with 113,756 additions and 69,429 deletions.
3 changes: 3 additions & 0 deletions exchanges/bybit/bybit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (

var validCategory = []string{"spot", "linear", "inverse", "option"}

// supportedOptionsTypes Bybit does not offer a way to retrieve option denominations via its API
var supportedOptionsTypes = []string{"BTC", "ETH", "SOL"}

type orderbookResponse struct {
Symbol string `json:"s"`
Asks [][2]string `json:"a"`
Expand Down
26 changes: 17 additions & 9 deletions exchanges/bybit/bybit_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ func (by *Bybit) AuthenticateWebsocket(ctx context.Context) error {

// FetchTradablePairs returns a list of the exchanges tradable pairs
func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) (currency.Pairs, error) {
if !by.SupportsAsset(a) {
return nil, fmt.Errorf("%s %w", a, asset.ErrNotSupported)
}
var pair currency.Pair
var category string
format, err := by.GetPairFormat(a, false)
Expand All @@ -287,13 +290,19 @@ func (by *Bybit) FetchTradablePairs(ctx context.Context, a asset.Item) (currency
allPairs = response.List
case asset.Options:
category = getCategoryName(a)
baseCoins := []string{"BTC", "ETH"}
for x := range baseCoins {
response, err = by.GetInstrumentInfo(ctx, category, "", "Trading", baseCoins[x], "", int64(by.Features.Enabled.Kline.GlobalResultLimit))
if err != nil {
return nil, err
for x := range supportedOptionsTypes {
var bookmark = ""
for {
response, err = by.GetInstrumentInfo(ctx, category, "", "Trading", supportedOptionsTypes[x], bookmark, int64(by.Features.Enabled.Kline.GlobalResultLimit))
if err != nil {
return nil, err
}
allPairs = append(allPairs, response.List...)
if response.NextPageCursor == "" || (bookmark != "" && bookmark == response.NextPageCursor) || len(response.List) == 0 {
break
}
bookmark = response.NextPageCursor
}
allPairs = append(allPairs, response.List...)
}
default:
return nil, fmt.Errorf("%w %v", asset.ErrNotSupported, a)
Expand Down Expand Up @@ -432,9 +441,8 @@ func (by *Bybit) UpdateTickers(ctx context.Context, assetType asset.Item) error
}
}
case asset.Options:
baseCoins := []string{"BTC", "ETH"}
for x := range baseCoins {
ticks, err = by.GetTickers(ctx, getCategoryName(assetType), "", baseCoins[x], time.Time{})
for x := range supportedOptionsTypes {
ticks, err = by.GetTickers(ctx, getCategoryName(assetType), "", supportedOptionsTypes[x], time.Time{})
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit ece58eb

Please sign in to comment.