From 441ed11fa479fbf1257a73cf491403bfdc98ee3c Mon Sep 17 00:00:00 2001 From: Tomas Bezouska Date: Mon, 13 Sep 2021 16:15:13 +0200 Subject: [PATCH 1/2] Fix parsing Bitfinex ticker symbol --- src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs | 2 +- src/ExchangeSharp/ExchangeSharp.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs b/src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs index becf8316..f74c8c12 100644 --- a/src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs @@ -123,7 +123,7 @@ protected internal override async Task> OnGetMarketS protected override async Task OnGetTickerAsync(string marketSymbol) { JToken ticker = await MakeJsonRequestAsync("/ticker/t" + marketSymbol); - return await this.ParseTickerAsync(ticker, marketSymbol, 2, 0, 6, 7); + return await this.ParseTickerAsync(ticker, NormalizeMarketSymbolV1(marketSymbol), 2, 0, 6, 7); } protected override async Task>> OnGetTickersAsync() diff --git a/src/ExchangeSharp/ExchangeSharp.csproj b/src/ExchangeSharp/ExchangeSharp.csproj index b8ce8a88..324b2882 100644 --- a/src/ExchangeSharp/ExchangeSharp.csproj +++ b/src/ExchangeSharp/ExchangeSharp.csproj @@ -8,7 +8,7 @@ 8 DigitalRuby.ExchangeSharp ExchangeSharp - C# API for cryptocurrency exchanges - 0.8.2 + 0.8.3 jjxtra ExchangeSharp is a C# API for working with various cryptocurrency exchanges. Web sockets are also supported for some exchanges. Supported exchanges: Binance BitMEX Bitfinex Bithumb Bitstamp Bittrex BL3P Bleutrade BTSE Cryptopia Coinbase(GDAX) Digifinex Gemini Gitbtc Huobi Kraken Kucoin Livecoin NDAX OKCoin OKEx Poloniex TuxExchange Yobit ZBcom. Pull requests welcome. From dbe38735d7a9400b588b890b627401e54d2fb4ad Mon Sep 17 00:00:00 2001 From: Tomas Bezouska Date: Tue, 14 Sep 2021 21:39:16 +0200 Subject: [PATCH 2/2] Set order status --- .../Exchanges/Bitstamp/ExchangeBitstampAPI.cs | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs b/src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs index 27c10050..e88b8674 100644 --- a/src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs @@ -244,11 +244,24 @@ protected override async Task OnGetOrderDetailsAsync(string payload["id"] = orderId; JObject result = await MakeJsonRequestAsync(url, null, payload, "POST"); - // status can be 'In Queue', 'Open' or 'Finished' - JArray transactions = result["transactions"] as JArray; + var transactions = result["transactions"] as JArray; + var anyTransaction = transactions.Any(); + + // status can be 'Canceled', 'Open' or 'Finished' + var statusCode = result.Value("status"); + var status = GetOrderResultFromStatus(statusCode, anyTransaction); + // empty transaction array means that order is InQueue or Open and AmountFilled == 0 // return empty order in this case. no any additional info available at this point - if (!transactions.Any()) { return new ExchangeOrderResult() { OrderId = orderId }; } + if (!anyTransaction) + { + return new ExchangeOrderResult + { + OrderId = orderId, + Result = status, + ResultCode = statusCode + }; + } JObject first = transactions.First() as JObject; List excludeStrings = new List() { "tid", "price", "fee", "datetime", "type", "btc", "usd", "eur" }; @@ -291,7 +304,9 @@ protected override async Task OnGetOrderDetailsAsync(string MarketSymbol = _symbol, AveragePrice = spentQuoteCurrency / amountFilled, Price = price, - }; + Result = status, + ResultCode = statusCode + }; } protected override async Task> OnGetOpenOrderDetailsAsync(string marketSymbol = null) @@ -322,7 +337,20 @@ protected override async Task> OnGetOpenOrderDe return orders; } - public class BitstampTransaction + private ExchangeAPIOrderResult GetOrderResultFromStatus(string status, bool anyTransactions) + { + switch (status?.ToLower()) + { + case "finished": return ExchangeAPIOrderResult.Filled; + case "open": return anyTransactions + ? ExchangeAPIOrderResult.FilledPartially + : ExchangeAPIOrderResult.Pending; + case "canceled": return ExchangeAPIOrderResult.Canceled; + default: return ExchangeAPIOrderResult.Unknown; + } + } + + public class BitstampTransaction { public BitstampTransaction(string id, DateTime dateTime, int type, string symbol, decimal fees, string orderId, decimal quantity, decimal price, bool isBuy) {