diff --git a/src/ExchangeSharp/.vscode/launch.json b/src/ExchangeSharp/.vscode/launch.json new file mode 100644 index 00000000..b3f051c9 --- /dev/null +++ b/src/ExchangeSharp/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + // attach to running dotnet console app + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} diff --git a/src/ExchangeSharp/API/Exchanges/OKGroup/ExchangeOKExAPI.cs b/src/ExchangeSharp/API/Exchanges/OKGroup/ExchangeOKExAPI.cs index 8acfcd65..3218b623 100644 --- a/src/ExchangeSharp/API/Exchanges/OKGroup/ExchangeOKExAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/OKGroup/ExchangeOKExAPI.cs @@ -831,34 +831,44 @@ await GetNoncePayloadAsync() ); } - private static ExchangeOrderResult ParseOrder(JToken token) => - new ExchangeOrderResult() - { - OrderId = token["ordId"].Value(), - OrderDate = DateTimeOffset - .FromUnixTimeMilliseconds(token["cTime"].Value()) - .DateTime, - Result = token["state"].Value() switch - { - "canceled" => ExchangeAPIOrderResult.Canceled, - "live" => ExchangeAPIOrderResult.Open, - "partially_filled" => ExchangeAPIOrderResult.FilledPartially, - "filled" => ExchangeAPIOrderResult.Filled, - _ => ExchangeAPIOrderResult.Unknown - }, - IsBuy = token["side"].Value() == "buy", - IsAmountFilledReversed = false, - Amount = token["sz"].Value(), - AmountFilled = token["accFillSz"].Value(), - AveragePrice = - token["avgPx"].Value() == string.Empty - ? default - : token["avgPx"].Value(), - Price = token["px"].Value(), - ClientOrderId = token["clOrdId"].Value(), - FeesCurrency = token["feeCcy"].Value(), - MarketSymbol = token["instId"].Value() - }; + private static ExchangeOrderResult ParseOrder(JToken token) + { + var newResult = new ExchangeOrderResult(); + newResult.OrderId = token["ordId"].Value(); + newResult.OrderDate = DateTimeOffset + .FromUnixTimeMilliseconds(token["cTime"].Value()) + .DateTime; + newResult.Result = token["state"].Value() switch + { + "canceled" => ExchangeAPIOrderResult.Canceled, + "live" => ExchangeAPIOrderResult.Open, + "partially_filled" => ExchangeAPIOrderResult.FilledPartially, + "filled" => ExchangeAPIOrderResult.Filled, + _ => ExchangeAPIOrderResult.Unknown + }; + newResult.IsBuy = token["side"].Value() == "buy"; + newResult.IsAmountFilledReversed = false; + newResult.Amount = token["sz"].Value(); + newResult.AmountFilled = token["accFillSz"].Value(); + + var avgPrice = decimal.TryParse(token["avgPx"].Value(), out var tempAvgPx) ? tempAvgPx : default; + var price = decimal.TryParse(token["px"].Value(), out var tempPx) ? tempPx : default; + if (avgPrice == default && price != default) + { + avgPrice = price; + } + else if (price == default && avgPrice != default) + { + price = avgPrice; + } + newResult.Price = price; + newResult.AveragePrice = avgPrice; + newResult.ClientOrderId = token["clOrdId"].Value(); + newResult.FeesCurrency = token["feeCcy"].Value(); + newResult.MarketSymbol = token["instId"].Value(); + + return newResult; + } private static IEnumerable ParseOrders(JToken token) => token.Select(ParseOrder);