diff --git a/src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs b/src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs index bd6098b1..ffbf223b 100644 --- a/src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs @@ -236,16 +236,19 @@ private async Task ParseHistoryOrder(string orderId, JToken //} // } - ExchangeOrderResult orderResult = new ExchangeOrderResult { OrderId = orderId }; - orderResult.Result = ExchangeAPIOrderResult.Filled; - orderResult.Message = ""; - orderResult.MarketSymbol = order["pair"].ToStringInvariant(); - orderResult.IsBuy = (order["type"].ToStringInvariant() == "buy"); - orderResult.Amount = order["vol"].ConvertInvariant(); - orderResult.Fees = order["fee"].ConvertInvariant(); - orderResult.Price = order["price"].ConvertInvariant(); - orderResult.AveragePrice = order["price"].ConvertInvariant(); - orderResult.TradeId = order["postxid"].ToStringInvariant(); //verify which is orderid & tradeid + ExchangeOrderResult orderResult = new ExchangeOrderResult + { + OrderId = orderId, + Result = ExchangeAPIOrderResult.Filled, + Message = "", + MarketSymbol = order["pair"].ToStringInvariant(), + IsBuy = order["type"].ToStringInvariant() == "buy", + Amount = order["vol"].ConvertInvariant(), + Fees = order["fee"].ConvertInvariant(), + Price = order["price"].ConvertInvariant(), + AveragePrice = order["price"].ConvertInvariant(), + TradeId = order["postxid"].ToStringInvariant() //verify which is orderid & tradeid + }; orderResult.OrderId = order["ordertxid"].ToStringInvariant(); //verify which is orderid & tradeid orderResult.AmountFilled = order["vol"].ConvertInvariant(); // orderResult.OrderDate - not provided here. ideally would be null but ExchangeOrderResult.OrderDate is not nullable @@ -258,6 +261,21 @@ private async Task ParseHistoryOrder(string orderId, JToken return orderResult; } + internal ExchangeOrderResult ExtendResultsWithOrderDescr(ExchangeOrderResult result, string orderStr) + { + //"buy 0.00000001 XBTUSD @ limit 1000000" + //"buy 58.00000000 ADAUSDT @ market" + string[] orderStrParts = orderStr.Split(' '); + result.IsBuy = string.Equals(orderStrParts[0], "buy", StringComparison.InvariantCultureIgnoreCase); + result.Amount = orderStrParts[1].ConvertInvariant(); + result.MarketSymbol = orderStrParts[2]; + var isMarket = string.Equals(orderStrParts[4], "market", StringComparison.InvariantCultureIgnoreCase); + if (!isMarket) { + result.Price = orderStrParts[5].ConvertInvariant(); + } + return result; + } + private async Task> QueryOrdersAsync(string symbol, string path) { await PopulateLookupTables(); @@ -496,12 +514,12 @@ protected override async Task>> { tickers.Add(new KeyValuePair(marketSymbol, await ConvertToExchangeTickerAsync(marketSymbol, ticker))); } - catch(Exception e) + catch (Exception e) { Logger.Error(e); } } - if(unfoundSymbols.Count > 0) + if (unfoundSymbols.Count > 0) { Logger.Warn($"Of {marketSymbols.Count()} symbols, tickers could not be found for {unfoundSymbols.Count}: [{String.Join(", ", unfoundSymbols)}]"); } @@ -700,12 +718,17 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd JToken token = await MakeJsonRequestAsync("/0/private/AddOrder", null, payload); ExchangeOrderResult result = new ExchangeOrderResult { - OrderDate = CryptoUtility.UtcNow + OrderDate = CryptoUtility.UtcNow, + Result = ExchangeAPIOrderResult.Open }; if (token["txid"] is JArray array) { result.OrderId = array[0].ToStringInvariant(); } + if (token["descr"] is JObject descrArray) + { + result = ExtendResultsWithOrderDescr(result, descrArray["order"].ToStringInvariant()); + } return result; } @@ -869,7 +892,7 @@ [3]pair string Asset pair string marketSymbol = token[3].ToStringInvariant(); //Kraken updates the candle open time to the current time, but we want it as open-time i.e. close-time - interval token[1][0] = token[1][1].ConvertInvariant() - interval * 60; - var candle = this.ParseCandle(token[1], marketSymbol, interval * 60, 2, 3, 4, 5, 0, TimestampType.UnixSeconds, 7, null, 6,8); + var candle = this.ParseCandle(token[1], marketSymbol, interval * 60, 2, 3, 4, 5, 0, TimestampType.UnixSeconds, 7, null, 6, 8); await callbackAsync(candle); } }, connectCallback: async (_socket) => @@ -895,7 +918,7 @@ protected override async Task OnGetPositionsWebSocketAsync(Action(); + return; + } + + [TestMethod] + public void ExtendResultsWithOrderDescrTest() + { + string toParse = "buy 58.00000000 ADAUSDT @ market"; + var extendedOrder = api.ExtendResultsWithOrderDescr(new ExchangeOrderResult(), toParse); + + extendedOrder.IsBuy.Should().BeTrue(); + extendedOrder.Amount.Should().Be(58); + extendedOrder.MarketSymbol.Should().Be("ADAUSDT"); + } + + [TestMethod] + public void ExtendResultsWithOrderDescrAndPriceTest() + { + string toParse = "buy 0.001254 BTCUSDT @ limit 1000"; + var extendedOrder = api.ExtendResultsWithOrderDescr(new ExchangeOrderResult(), toParse); + + extendedOrder.IsBuy.Should().BeTrue(); + extendedOrder.Amount.Should().Be(0.001254); + extendedOrder.MarketSymbol.Should().Be("BTCUSDT"); + extendedOrder.Price.Should().Be(1000); + } + } +}