Skip to content

Commit

Permalink
fix: bug fix on buy order results (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Mutt authored Feb 8, 2024
1 parent 65f2427 commit 9486d77
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 28 deletions.
15 changes: 15 additions & 0 deletions src/ExchangeSharp/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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}"
}
]
}
66 changes: 38 additions & 28 deletions src/ExchangeSharp/API/Exchanges/OKGroup/ExchangeOKExAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,34 +831,44 @@ await GetNoncePayloadAsync()
);
}

private static ExchangeOrderResult ParseOrder(JToken token) =>
new ExchangeOrderResult()
{
OrderId = token["ordId"].Value<string>(),
OrderDate = DateTimeOffset
.FromUnixTimeMilliseconds(token["cTime"].Value<long>())
.DateTime,
Result = token["state"].Value<string>() switch
{
"canceled" => ExchangeAPIOrderResult.Canceled,
"live" => ExchangeAPIOrderResult.Open,
"partially_filled" => ExchangeAPIOrderResult.FilledPartially,
"filled" => ExchangeAPIOrderResult.Filled,
_ => ExchangeAPIOrderResult.Unknown
},
IsBuy = token["side"].Value<string>() == "buy",
IsAmountFilledReversed = false,
Amount = token["sz"].Value<decimal>(),
AmountFilled = token["accFillSz"].Value<decimal>(),
AveragePrice =
token["avgPx"].Value<string>() == string.Empty
? default
: token["avgPx"].Value<decimal>(),
Price = token["px"].Value<decimal>(),
ClientOrderId = token["clOrdId"].Value<string>(),
FeesCurrency = token["feeCcy"].Value<string>(),
MarketSymbol = token["instId"].Value<string>()
};
private static ExchangeOrderResult ParseOrder(JToken token)
{
var newResult = new ExchangeOrderResult();
newResult.OrderId = token["ordId"].Value<string>();
newResult.OrderDate = DateTimeOffset
.FromUnixTimeMilliseconds(token["cTime"].Value<long>())
.DateTime;
newResult.Result = token["state"].Value<string>() switch
{
"canceled" => ExchangeAPIOrderResult.Canceled,
"live" => ExchangeAPIOrderResult.Open,
"partially_filled" => ExchangeAPIOrderResult.FilledPartially,
"filled" => ExchangeAPIOrderResult.Filled,
_ => ExchangeAPIOrderResult.Unknown
};
newResult.IsBuy = token["side"].Value<string>() == "buy";
newResult.IsAmountFilledReversed = false;
newResult.Amount = token["sz"].Value<decimal>();
newResult.AmountFilled = token["accFillSz"].Value<decimal>();

var avgPrice = decimal.TryParse(token["avgPx"].Value<string>(), out var tempAvgPx) ? tempAvgPx : default;
var price = decimal.TryParse(token["px"].Value<string>(), 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<string>();
newResult.FeesCurrency = token["feeCcy"].Value<string>();
newResult.MarketSymbol = token["instId"].Value<string>();

return newResult;
}

private static IEnumerable<ExchangeOrderResult> ParseOrders(JToken token) =>
token.Select(ParseOrder);
Expand Down

0 comments on commit 9486d77

Please sign in to comment.