@@ -831,34 +831,44 @@ await GetNoncePayloadAsync()
831
831
) ;
832
832
}
833
833
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
+ }
862
872
863
873
private static IEnumerable < ExchangeOrderResult > ParseOrders ( JToken token ) =>
864
874
token . Select ( ParseOrder ) ;
0 commit comments