Skip to content

Commit 707dc4e

Browse files
authored
Merge pull request #1778 from c9s/edwin/bybit/ws-trades
FEATURE: [bybit] use execution.fast topic
2 parents 76e2d29 + 74feb92 commit 707dc4e

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

pkg/exchange/bybit/stream.go

-8
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,6 @@ func (s *Stream) handleKLineEvent(klineEvent KLineEvent) {
438438
}
439439
}
440440

441-
func pollAndGetFeeRate(ctx context.Context, symbol string, poller FeeRatePoller, marketsInfo types.MarketMap) (SymbolFeeDetail, error) {
442-
err := poller.PollFeeRate(ctx)
443-
if err != nil {
444-
return SymbolFeeDetail{}, err
445-
}
446-
return getFeeRate(symbol, poller, marketsInfo), nil
447-
}
448-
449441
func getFeeRate(symbol string, poller FeeRatePoller, marketsInfo types.MarketMap) SymbolFeeDetail {
450442
feeRate, found := poller.GetFeeRate(symbol)
451443
if !found {

pkg/exchange/bybit/types.go

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const (
107107
TopicTypeWallet TopicType = "wallet"
108108
TopicTypeOrder TopicType = "order"
109109
TopicTypeKLine TopicType = "kline"
110+
TopicTypeFastTrade TopicType = "execution.fast"
110111
TopicTypeTrade TopicType = "execution"
111112
)
112113

@@ -385,6 +386,11 @@ func (t *TradeEvent) toGlobalTrade(symbolFee SymbolFeeDetail) (*types.Trade, err
385386
// IsMakerOrder = FALSE
386387
// -> Side = Buy -> base currency (BTC)
387388
// -> Side = Sell -> quote currency (USDT)
389+
//
390+
// The `execution.fast` topic doesn't support fee currency and execution fees, so we're calculating the transaction fees here.
391+
// Although the `execution` topic is supported, it only covers the execution fee, so you'll still need to calculate the
392+
// fee currency.
393+
// Overall, I chose the one with lower latency (execution.fast) and calculated the fee myself.
388394
func calculateFee(t bybitapi.Trade, feeDetail SymbolFeeDetail) (string, fixedpoint.Value) {
389395
if feeDetail.MakerFeeRate.Sign() > 0 || !t.IsMaker {
390396
if t.Side == bybitapi.SideBuy {

0 commit comments

Comments
 (0)