Skip to content

Commit b6f1ab3

Browse files
authored
Fix for Okex OnGetTradesWebSocketAsync (#552)
Not unified property. On futures it's "qty", while on the other type of instruments it's "size".
1 parent e34f6d7 commit b6f1ab3

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/ExchangeSharp/API/Exchanges/OKGroup/OKGroupCommon.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,20 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
227227
await AddMarketSymbolsToChannel(_socket, "/trade:{0}", marketSymbols);
228228
}, async (_socket, symbol, sArray, token) =>
229229
{
230-
ExchangeTrade trade = token.ParseTrade(amountKey: "size", priceKey: "price",
230+
ExchangeTrade trade;
231+
var instrumentType = GetInstrumentType(symbol);
232+
if (instrumentType == "futures")
233+
{
234+
trade = token.ParseTrade(amountKey: "qty", priceKey: "price",
235+
typeKey: "side", timestampKey: "timestamp",
236+
timestampType: TimestampType.Iso8601, idKey: "trade_id");
237+
}
238+
else
239+
{
240+
trade = token.ParseTrade(amountKey: "size", priceKey: "price",
231241
typeKey: "side", timestampKey: "timestamp",
232242
timestampType: TimestampType.Iso8601, idKey: "trade_id");
243+
}
233244
await callback(new KeyValuePair<string, ExchangeTrade>(symbol, trade));
234245
});
235246
}
@@ -733,6 +744,24 @@ async Task sendMessageAsync(string category, IEnumerable<string> symbolsToSend)
733744
return marketSymbols;
734745
}
735746

736-
#endregion
747+
private string GetInstrumentType(string marketSymbol)
748+
{
749+
string type;
750+
if (marketSymbol.Split('-').Length == 3 && marketSymbol.Split('-')[2] == "SWAP")
751+
{
752+
type = "swap";
753+
}
754+
else if (marketSymbol.Split('-').Length == 3 && int.TryParse(marketSymbol.Split('-')[2], out _))
755+
{
756+
type = "futures";
757+
}
758+
else
759+
{
760+
type = "spot";
761+
}
762+
return type;
763+
}
764+
765+
#endregion
737766
}
738767
}

0 commit comments

Comments
 (0)