Skip to content

Commit

Permalink
fixup! Bybit: Fix WS ticker processing
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed May 13, 2024
1 parent 859bfa5 commit b133fb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions exchanges/bybit/bybit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3140,6 +3140,9 @@ func TestWsTicker(t *testing.T) {
assert.Equal(t, 84.489, v.BidSize, "BidSize should be correct")
assert.Equal(t, 17216.00, v.Ask, "Ask should be correct")
assert.Equal(t, 83.020, v.AskSize, "AskSize should be correct")
assert.Equal(t, 17217.33, v.MarkPrice, "MarkPrice should be correct")
assert.Equal(t, 17227.36, v.IndexPrice, "IndexPrice should be correct")
assert.Equal(t, 68744.761, v.OpenInterest, "OpenInterest should be correct")
assert.Equal(t, "BTC_USDT", v.Pair.String(), "Pair should be correct")
assert.Equal(t, asset.USDTMarginedFutures, v.AssetType, "AssetType should be correct")
assert.EqualValues(t, 233366402, v.LastUpdated.Unix(), "LastUpdated should be correct")
Expand All @@ -3152,6 +3155,9 @@ func TestWsTicker(t *testing.T) {
assert.Equal(t, 4.0, v.BidSize, "BidSize should be correct")
assert.Equal(t, 11.00, v.Ask, "Ask should be correct")
assert.Equal(t, 5.10, v.AskSize, "AskSize should be correct")
assert.Equal(t, 7.86976724, v.MarkPrice, "MarkPrice should be correct")
assert.Equal(t, 16823.73, v.IndexPrice, "IndexPrice should be correct")
assert.Equal(t, 49.85, v.OpenInterest, "OpenInterest should be correct")
assert.Equal(t, "BTC-USD-220930-28000-P", v.Pair.String(), "Pair should be correct")
assert.Equal(t, asset.Options, v.AssetType, "AssetType should be correct")
assert.EqualValues(t, 233366403, v.LastUpdated.Unix(), "LastUpdated should be correct")
Expand All @@ -3164,6 +3170,9 @@ func TestWsTicker(t *testing.T) {
assert.Equal(t, 80.289, v.BidSize, "BidSize should be correct")
assert.Equal(t, 17220.04, v.Ask, "Ask should be correct")
assert.Equal(t, 94.200, v.AskSize, "AskSize should be correct")
assert.Equal(t, 17218.12, v.MarkPrice, "MarkPrice should be correct")
assert.Equal(t, 17218.14, v.IndexPrice, "IndexPrice should be correct")
assert.Equal(t, 68750.881, v.OpenInterest, "OpenInterest should be correct")
assert.Equal(t, "BTC_USDT", v.Pair.String(), "Pair should be correct")
assert.Equal(t, asset.USDTMarginedFutures, v.AssetType, "AssetType should be correct")
assert.EqualValues(t, 233366404, v.LastUpdated.Unix(), "LastUpdated should be correct")
Expand Down
14 changes: 14 additions & 0 deletions exchanges/bybit/bybit_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,20 @@ func updateTicker(tick *ticker.Price, resp *TickerItem) {
tick.Volume = resp.Volume24H.Float64()
}

if tick.AssetType == asset.Spot {
return
}

if resp.MarkPrice.Float64() != 0 {
tick.MarkPrice = resp.MarkPrice.Float64()
}
if resp.IndexPrice.Float64() != 0 {
tick.IndexPrice = resp.IndexPrice.Float64()
}
if resp.OpenInterest.Float64() != 0 {
tick.OpenInterest = resp.OpenInterest.Float64()
}

switch tick.AssetType {
case asset.Options:
if resp.BidPrice.Float64() != 0 {
Expand Down

0 comments on commit b133fb9

Please sign in to comment.