Skip to content

Commit 9486d77

Browse files
authored
fix: bug fix on buy order results (#829)
1 parent 65f2427 commit 9486d77

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

src/ExchangeSharp/.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
// attach to running dotnet console app
9+
"name": ".NET Core Attach",
10+
"type": "coreclr",
11+
"request": "attach",
12+
"processId": "${command:pickProcess}"
13+
}
14+
]
15+
}

src/ExchangeSharp/API/Exchanges/OKGroup/ExchangeOKExAPI.cs

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -831,34 +831,44 @@ await GetNoncePayloadAsync()
831831
);
832832
}
833833

834-
private static ExchangeOrderResult ParseOrder(JToken token) =>
835-
new ExchangeOrderResult()
836-
{
837-
OrderId = token["ordId"].Value<string>(),
838-
OrderDate = DateTimeOffset
839-
.FromUnixTimeMilliseconds(token["cTime"].Value<long>())
840-
.DateTime,
841-
Result = token["state"].Value<string>() switch
842-
{
843-
"canceled" => ExchangeAPIOrderResult.Canceled,
844-
"live" => ExchangeAPIOrderResult.Open,
845-
"partially_filled" => ExchangeAPIOrderResult.FilledPartially,
846-
"filled" => ExchangeAPIOrderResult.Filled,
847-
_ => ExchangeAPIOrderResult.Unknown
848-
},
849-
IsBuy = token["side"].Value<string>() == "buy",
850-
IsAmountFilledReversed = false,
851-
Amount = token["sz"].Value<decimal>(),
852-
AmountFilled = token["accFillSz"].Value<decimal>(),
853-
AveragePrice =
854-
token["avgPx"].Value<string>() == string.Empty
855-
? default
856-
: token["avgPx"].Value<decimal>(),
857-
Price = token["px"].Value<decimal>(),
858-
ClientOrderId = token["clOrdId"].Value<string>(),
859-
FeesCurrency = token["feeCcy"].Value<string>(),
860-
MarketSymbol = token["instId"].Value<string>()
861-
};
834+
private static ExchangeOrderResult ParseOrder(JToken token)
835+
{
836+
var newResult = new ExchangeOrderResult();
837+
newResult.OrderId = token["ordId"].Value<string>();
838+
newResult.OrderDate = DateTimeOffset
839+
.FromUnixTimeMilliseconds(token["cTime"].Value<long>())
840+
.DateTime;
841+
newResult.Result = token["state"].Value<string>() switch
842+
{
843+
"canceled" => ExchangeAPIOrderResult.Canceled,
844+
"live" => ExchangeAPIOrderResult.Open,
845+
"partially_filled" => ExchangeAPIOrderResult.FilledPartially,
846+
"filled" => ExchangeAPIOrderResult.Filled,
847+
_ => ExchangeAPIOrderResult.Unknown
848+
};
849+
newResult.IsBuy = token["side"].Value<string>() == "buy";
850+
newResult.IsAmountFilledReversed = false;
851+
newResult.Amount = token["sz"].Value<decimal>();
852+
newResult.AmountFilled = token["accFillSz"].Value<decimal>();
853+
854+
var avgPrice = decimal.TryParse(token["avgPx"].Value<string>(), out var tempAvgPx) ? tempAvgPx : default;
855+
var price = decimal.TryParse(token["px"].Value<string>(), out var tempPx) ? tempPx : default;
856+
if (avgPrice == default && price != default)
857+
{
858+
avgPrice = price;
859+
}
860+
else if (price == default && avgPrice != default)
861+
{
862+
price = avgPrice;
863+
}
864+
newResult.Price = price;
865+
newResult.AveragePrice = avgPrice;
866+
newResult.ClientOrderId = token["clOrdId"].Value<string>();
867+
newResult.FeesCurrency = token["feeCcy"].Value<string>();
868+
newResult.MarketSymbol = token["instId"].Value<string>();
869+
870+
return newResult;
871+
}
862872

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

0 commit comments

Comments
 (0)