Skip to content

Commit fa2534e

Browse files
committed
Fix for Kraken web socket
1 parent 9174013 commit fa2534e

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,14 @@ protected override async Task<IEnumerable<ExchangeMarket>> OnGetMarketSymbolsMet
498498
foreach (JProperty prop in res.Where(p => !p.Name.EndsWith(".d")))
499499
{
500500
JToken pair = prop.Value;
501+
JToken child = prop.Children().FirstOrDefault();
501502
var quantityStepSize = Math.Pow(0.1, pair["lot_decimals"].ConvertInvariant<int>()).ConvertInvariant<decimal>();
502503
var market = new ExchangeMarket
503504
{
504505
IsActive = true,
505506
MarketSymbol = prop.Name,
507+
AltMarketSymbol = child["altname"].ToStringInvariant(),
508+
AltMarketSymbol2 = child["wsname"].ToStringInvariant(),
506509
MinTradeSize = quantityStepSize,
507510
MarginEnabled = pair["leverage_buy"].Children().Any() || pair["leverage_sell"].Children().Any(),
508511
BaseCurrency = pair["base"].ToStringInvariant(),
@@ -856,20 +859,38 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
856859
}
857860
}, connectCallback: async (_socket) =>
858861
{
859-
//{
860-
// "event": "subscribe",
861-
// "pair": [
862-
// "XBT/USD","XBT/EUR"
863-
// ],
864-
// "subscription": {
865-
// "name": "ticker"
866-
// }
867-
//}
868-
await _socket.SendMessageAsync(new
862+
//{
863+
// "event": "subscribe",
864+
// "pair": [
865+
// "XBT/USD","XBT/EUR"
866+
// ],
867+
// "subscription": {
868+
// "name": "ticker"
869+
// }
870+
//}
871+
Task<string>[] marketSymbolsArray = marketSymbols.Select(async (m) =>
872+
{
873+
ExchangeMarket market = await GetExchangeMarketFromCacheAsync(m);
874+
if (market == null)
875+
{
876+
return null;
877+
}
878+
return market.AltMarketSymbol2;
879+
}).ToArray();
880+
List<string> marketSymbolList = new List<string>();
881+
foreach (Task<string> ms in marketSymbolsArray)
882+
{
883+
string result = await ms;
884+
if (result != null)
885+
{
886+
marketSymbolList.Add(result);
887+
}
888+
}
889+
await _socket.SendMessageAsync(new
869890
{
870891
@event = "subscribe",
871-
pair = marketSymbols,
872-
subscription = new { name = "trade" },
892+
pair = marketSymbolList,
893+
subscription = new { name = "trade" }
873894
});
874895
});
875896
}

ExchangeSharp/Model/ExchangeMarket.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
MIT LICENSE
33
44
Copyright 2017 Digital Ruby, LLC - http://www.digitalruby.com
@@ -21,8 +21,14 @@ public sealed class ExchangeMarket
2121
/// <summary>Gets or sets the symbol representing the market's currency pair.</summary>
2222
public string MarketSymbol { get; set; }
2323

24-
/// <summary>A value indicating whether the market is active.</summary>
25-
public bool IsActive { get; set; }
24+
/// <summary>Aternate market symbol</summary>
25+
public string AltMarketSymbol { get; set; }
26+
27+
/// <summary>Second aternate market symbol</summary>
28+
public string AltMarketSymbol2 { get; set; }
29+
30+
/// <summary>A value indicating whether the market is active.</summary>
31+
public bool IsActive { get; set; }
2632

2733
/// <summary>In a pair like ZRX/BTC, BTC is the quote currency.</summary>
2834
public string QuoteCurrency { get; set; }
@@ -72,4 +78,4 @@ public override string ToString()
7278
return $"{MarketSymbol}, {BaseCurrency}-{QuoteCurrency}";
7379
}
7480
}
75-
}
81+
}

ExchangeSharpTests/ExchangeBitBankTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ExchangeSharpTests
1010
[TestClass]
1111
public sealed class ExchangeBitBankTests
1212
{
13-
private ExchangeBitBankAPI makeMockRequestMaker(string response = null)
13+
private ExchangeBitBankAPI MakeMockRequestMaker(string response = null)
1414
{
1515
var requestMaker = new MockAPIRequestMaker();
1616
if (response != null)
@@ -38,7 +38,7 @@ public async Task ShouldParseGetTickerResult()
3838
}
3939
}
4040
";
41-
var api = makeMockRequestMaker(data);
41+
var api = MakeMockRequestMaker(data);
4242
var ticker = await api.GetTickerAsync("BTC-JPY");
4343
ticker.MarketSymbol.Should().Be("btc_jpy");
4444
ticker.Ask.Should().Be(395733m);
@@ -73,7 +73,7 @@ public async Task ShouldGetTransactions()
7373
}
7474
}
7575
";
76-
var api = makeMockRequestMaker(data);
76+
var api = MakeMockRequestMaker(data);
7777
ExchangeOrderBook resp = await api.GetOrderBookAsync("BTC-JPY");
7878
resp.MarketSymbol.Should().Be("btc_jpy");
7979
resp.Asks.Should().HaveCount(1);
@@ -114,7 +114,7 @@ public async Task ShouldGetCandleStick()
114114
}
115115
}
116116
";
117-
var api = makeMockRequestMaker(data);
117+
var api = MakeMockRequestMaker(data);
118118
// starttime is required.
119119
// await Assert.ThrowsExceptionAsync<APIException>(async () => await api.GetCandlesAsync("BTC-JPY", 3600));
120120
var resp = await api.GetCandlesAsync("BTC-JPY", 3600, CryptoUtility.UtcNow);
@@ -157,7 +157,7 @@ public async Task ShouldGetAssets()
157157
}
158158
}
159159
";
160-
var api = makeMockRequestMaker(data);
160+
var api = MakeMockRequestMaker(data);
161161
var resp = await api.GetAmountsAsync();
162162
resp.First().Key.Should().Equals("JPY");
163163
resp.First().Value.Should().Equals(3551.9501m);
@@ -185,7 +185,7 @@ public async Task ShouldGetOrderDetail()
185185
}
186186
}
187187
";
188-
var api = makeMockRequestMaker(data);
188+
var api = MakeMockRequestMaker(data);
189189
// Throws error when no Market Symbol
190190
var resp = await api.GetOrderDetailsAsync("558167000", "BTC-JPY");
191191
ExchangeOrderResult resp2 = await api.GetOrderDetailsAsync("58037954");
@@ -219,7 +219,7 @@ public async Task ShouldGetOrders()
219219
}
220220
}
221221
";
222-
var api = makeMockRequestMaker(data);
222+
var api = MakeMockRequestMaker(data);
223223
var orderBooks = await api.GetOpenOrderDetailsAsync();
224224
ExchangeOrderResult order = orderBooks.First();
225225
order.IsBuy.Should().BeFalse();

0 commit comments

Comments
 (0)