Skip to content

fix: buy order results bug in OKEx #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +854 to +865
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems there was an expectation that the inverse was true previously. I made it a bit safer parsing and use the other value if there is missing data one way or the other.

i.e. if we don't have avgPx use px, if we don't have px use avgPx, if we have both, Great!

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