Skip to content

Commit fe0929c

Browse files
authored
parse Bybit specific CrossSequence in Trades stream (#737)
1 parent c1bd985 commit fe0929c

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitAPI.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,12 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
274274
{
275275
foreach (var dataRow in token)
276276
{
277-
ExchangeTrade trade = dataRow.ParseTrade(
277+
var trade = dataRow.ParseTradeBybit(
278278
amountKey: "size",
279279
priceKey: "price",
280280
typeKey: "side",
281-
timestampKey: "timestamp",
282-
timestampType: TimestampType.Iso8601UTC,
281+
timestampKey: "trade_time_ms",
282+
timestampType: TimestampType.UnixMilliseconds,
283283
idKey: "trade_id");
284284
await callback(new KeyValuePair<string, ExchangeTrade>(dataRow["symbol"].ToStringInvariant(), trade));
285285
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace ExchangeSharp.Bybit
6+
{
7+
public class BybitTrade : ExchangeTrade
8+
{
9+
/// <summary>
10+
/// Cross sequence (internal value)
11+
/// </summary>
12+
public long CrossSequence { get; set; }
13+
public override string ToString()
14+
{
15+
return string.Format("{0},{1}", base.ToString(), CrossSequence);
16+
}
17+
18+
}
19+
}

src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPIExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The above copyright notice and this permission notice shall be included in all c
2424
using Newtonsoft.Json.Linq;
2525
using ExchangeSharp.NDAX;
2626
using ExchangeSharp.API.Exchanges.FTX.Models;
27+
using ExchangeSharp.Bybit;
2728

2829
namespace ExchangeSharp
2930
{
@@ -540,6 +541,15 @@ internal static ExchangeTrade ParseTradeBinance(this JToken token, object amount
540541
return trade;
541542
}
542543

544+
internal static ExchangeTrade ParseTradeBybit(this JToken token, object amountKey, object priceKey, object typeKey,
545+
object timestampKey, TimestampType timestampType, object idKey, string typeKeyIsBuyValue = "buy")
546+
{
547+
var trade = ParseTradeComponents<BybitTrade>(token, amountKey, priceKey, typeKey,
548+
timestampKey, timestampType, idKey, typeKeyIsBuyValue);
549+
trade.CrossSequence = token["cross_seq"].ConvertInvariant<long>();
550+
return trade;
551+
}
552+
543553
internal static ExchangeTrade ParseTradeBinanceDEX(this JToken token, object amountKey, object priceKey, object typeKey,
544554
object timestampKey, TimestampType timestampType, object idKey, string typeKeyIsBuyValue = "buy")
545555
{

0 commit comments

Comments
 (0)