|
5 | 5 | using System.Security.Cryptography; |
6 | 6 | using System.Text; |
7 | 7 | using System.Threading.Tasks; |
8 | | -using ExchangeSharp.API.Exchanges.BL3P; |
9 | | -using ExchangeSharp.API.Exchanges.BL3P.Enums; |
10 | | -using ExchangeSharp.API.Exchanges.BL3P.Extensions; |
11 | | -using ExchangeSharp.API.Exchanges.BL3P.Models; |
12 | | -using ExchangeSharp.API.Exchanges.BL3P.Models.Orders.Add; |
13 | | -using ExchangeSharp.API.Exchanges.BL3P.Models.Orders.Result; |
| 8 | +using ExchangeSharp.BL3P; |
14 | 9 | using ExchangeSharp.Utility; |
15 | 10 | using Newtonsoft.Json; |
16 | 11 | using Newtonsoft.Json.Linq; |
@@ -127,10 +122,10 @@ protected override async Task<IWebSocket> OnGetDeltaOrderBookWebSocketAsync( |
127 | 122 | params string[] marketSymbols |
128 | 123 | ) |
129 | 124 | { |
130 | | - if (marketSymbols == null) |
131 | | - throw new ArgumentNullException(nameof(marketSymbols)); |
132 | | - if (marketSymbols.Length == 0) |
133 | | - throw new ArgumentException("Value cannot be an empty collection.", nameof(marketSymbols)); |
| 125 | + if (marketSymbols == null || marketSymbols.Length == 0) |
| 126 | + { |
| 127 | + marketSymbols = (await GetMarketSymbolsAsync()).ToArray(); |
| 128 | + } |
134 | 129 |
|
135 | 130 | Task MessageCallback(IWebSocket _, byte[] msg) |
136 | 131 | { |
@@ -170,6 +165,31 @@ await Task.WhenAll( |
170 | 165 | ); |
171 | 166 | } |
172 | 167 |
|
| 168 | + protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValuePair<string, ExchangeTrade>, Task> callback, params string[] marketSymbols) |
| 169 | + { |
| 170 | + if (marketSymbols == null || marketSymbols.Length == 0) |
| 171 | + { |
| 172 | + marketSymbols = (await GetMarketSymbolsAsync()).ToArray(); |
| 173 | + } |
| 174 | + Task MessageCallback(IWebSocket _, byte[] msg) |
| 175 | + { // {{ "date": 1573255932, "marketplace": "BTCEUR", "price_int": 802466000, "type": "buy", "amount_int": 6193344 } } |
| 176 | + JToken token = JToken.Parse(msg.ToStringFromUTF8()); |
| 177 | + var symbol = token["marketplace"].ToStringInvariant(); |
| 178 | + ExchangeTrade trade = token.ParseTrade(amountKey: "amount_int", priceKey: "price_int", typeKey: "type", timestampKey: "date", |
| 179 | + timestampType: TimestampType.UnixSeconds, |
| 180 | + idKey: null, // + TODO: add Id Key when BL3P starts providing this info |
| 181 | + typeKeyIsBuyValue: "buy"); |
| 182 | + callback(new KeyValuePair<string, ExchangeTrade>(symbol, trade)); |
| 183 | + return Task.CompletedTask; |
| 184 | + } |
| 185 | + |
| 186 | + return new MultiWebsocketWrapper( |
| 187 | + await Task.WhenAll( |
| 188 | + marketSymbols.Select(ms => ConnectWebSocketAsync($"{ms}/trades", MessageCallback)) |
| 189 | + ).ConfigureAwait(false) |
| 190 | + ); |
| 191 | + } |
| 192 | + |
173 | 193 | protected override bool CanMakeAuthenticatedRequest(IReadOnlyDictionary<string, object> payload) |
174 | 194 | { |
175 | 195 | return !(PublicApiKey is null) && !(PrivateApiKey is null); |
|
0 commit comments