Skip to content

Commit af6c978

Browse files
committed
Reporting: emit report dates as clean invariant ISO-8601
The CSV and XML report generators format DateTime through FormatExtensions.Format, which previously delegated to Ecng's Converter.To<string>. After the Ecng update that started returning a culture-invariant string the old culture-dependent golden fixtures (1/1/2024 12:00:00 AM) stopped matching, and the full round-trip form it produced (2024-01-01T00:00:00.0000000Z) was verbose and inconsistent with the JSON report. Format the value explicitly as invariant ISO-8601 with "yyyy-MM-ddTHH:mm:ss.FFFFFFFK": the leading '.' and the fractional digits are emitted only for a non-zero fraction, so whole-second values render as 2024-01-15T10:00:00Z and all three report formats agree. Regenerate the CSV and XML golden fixtures accordingly; the JSON fixture already used ISO and is unchanged.
1 parent 19ebb88 commit af6c978

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

Reporting/FormatExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace StockSharp.Reporting;
22

3+
using System.Globalization;
4+
35
/// <summary>
46
/// Format extensions.
57
/// </summary>
@@ -27,5 +29,8 @@ public static string Format(this TimeSpan time)
2729
/// <param name="time"><see cref="DateTime"/> value.</param>
2830
/// <returns><see cref="string"/>.</returns>
2931
public static string Format(this DateTime time)
30-
=> time.To<string>();
32+
// Invariant ISO-8601. The leading '.' before the 'F' specifiers is emitted only when the
33+
// fractional part is non-zero, and trailing zero digits are trimmed, so whole-second values
34+
// render as 2024-01-15T10:00:00Z - matching the JSON report representation.
35+
=> time.ToString("yyyy-MM-ddTHH:mm:ss.FFFFFFFK", CultureInfo.InvariantCulture);
3136
}

Tests/Resources/Reports/expected_report.csv

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ Strategy,Working time,Position,P&L,Commission,Slippage,Latency
22
TestStrategy,08:00:00,100,5000,25,1.5,00:00:00
33
Parameters
44
Symbol,TimeFrame,StartDate,Volume,IsLong,MaxPositions
5-
BTCUSD,00:05:00,1/1/2024 12:00:00 AM,100,True,5
5+
BTCUSD,00:05:00,2024-01-01T00:00:00Z,100,True,5
66
Statistics
77
WinRate,MaxDrawdown,TradesCount,AverageTradeTime,BestTradeDate,SharpeRatio
8-
0.65,-500,42,00:15:00,1/15/2024 2:30:00 PM,1.85
8+
0.65,-500,42,00:15:00,2024-01-15T14:30:00Z,1.85
99
Orders
1010
Identifier,Transaction,Security,Direction,Time,Price,Status,Balance,Volume,Type
11-
1,100,BTCUSD@CRYPTO,Buy,1/15/2024 10:00:00 AM,50000,Done,0,1,Limit
12-
2,101,BTCUSD@CRYPTO,Sell,1/15/2024 11:00:00 AM,50500,Done,0,1,Limit
11+
1,100,BTCUSD@CRYPTO,Buy,2024-01-15T10:00:00Z,50000,Done,0,1,Limit
12+
2,101,BTCUSD@CRYPTO,Sell,2024-01-15T11:00:00Z,50500,Done,0,1,Limit
1313
Trades
1414
Identifier,Transaction,Security,Time,Price,Volume,Direction,Order ID,P&L,Slippage
15-
1001,100,BTCUSD@CRYPTO,1/15/2024 10:00:00 AM,50000,1,Buy,1,0,0
16-
1002,101,BTCUSD@CRYPTO,1/15/2024 11:00:00 AM,50500,1,Sell,2,500,0
15+
1001,100,BTCUSD@CRYPTO,2024-01-15T10:00:00Z,50000,1,Buy,1,0,0
16+
1002,101,BTCUSD@CRYPTO,2024-01-15T11:00:00Z,50500,1,Sell,2,500,0
1717
Positions
1818
Security,Portfolio,Entry Time,Opening Price,Exit Time,Closing Price,Max volume
19-
BTCUSD@CRYPTO,TestPortfolio,1/15/2024 10:00:00 AM,50000,1/15/2024 11:00:00 AM,50500,1
19+
BTCUSD@CRYPTO,TestPortfolio,2024-01-15T10:00:00Z,50000,2024-01-15T11:00:00Z,50500,1

Tests/Resources/Reports/expected_report.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parameters>
44
<parameter name="Symbol" value="BTCUSD" />
55
<parameter name="TimeFrame" value="00:05:00" />
6-
<parameter name="StartDate" value="1/1/2024 12:00:00 AM" />
6+
<parameter name="StartDate" value="2024-01-01T00:00:00Z" />
77
<parameter name="Volume" value="100" />
88
<parameter name="IsLong" value="True" />
99
<parameter name="MaxPositions" value="5" />
@@ -13,18 +13,18 @@
1313
<parameter name="MaxDrawdown" value="-500" />
1414
<parameter name="TradesCount" value="42" />
1515
<parameter name="AverageTradeTime" value="00:15:00" />
16-
<parameter name="BestTradeDate" value="1/15/2024 2:30:00 PM" />
16+
<parameter name="BestTradeDate" value="2024-01-15T14:30:00Z" />
1717
<parameter name="SharpeRatio" value="1.85" />
1818
</statistics>
1919
<orders>
20-
<order id="1" transactionId="100" securityId="BTCUSD@CRYPTO" direction="Buy" time="1/15/2024 10:00:00 AM" price="50000" state="Done" balance="0" volume="1" type="Limit" />
21-
<order id="2" transactionId="101" securityId="BTCUSD@CRYPTO" direction="Sell" time="1/15/2024 11:00:00 AM" price="50500" state="Done" balance="0" volume="1" type="Limit" />
20+
<order id="1" transactionId="100" securityId="BTCUSD@CRYPTO" direction="Buy" time="2024-01-15T10:00:00Z" price="50000" state="Done" balance="0" volume="1" type="Limit" />
21+
<order id="2" transactionId="101" securityId="BTCUSD@CRYPTO" direction="Sell" time="2024-01-15T11:00:00Z" price="50500" state="Done" balance="0" volume="1" type="Limit" />
2222
</orders>
2323
<trades>
24-
<trade id="1001" transactionId="100" securityId="BTCUSD@CRYPTO" time="1/15/2024 10:00:00 AM" price="50000" volume="1" order="1" PnL="0" slippage="0" />
25-
<trade id="1002" transactionId="101" securityId="BTCUSD@CRYPTO" time="1/15/2024 11:00:00 AM" price="50500" volume="1" order="2" PnL="500" slippage="0" />
24+
<trade id="1001" transactionId="100" securityId="BTCUSD@CRYPTO" time="2024-01-15T10:00:00Z" price="50000" volume="1" order="1" PnL="0" slippage="0" />
25+
<trade id="1002" transactionId="101" securityId="BTCUSD@CRYPTO" time="2024-01-15T11:00:00Z" price="50500" volume="1" order="2" PnL="500" slippage="0" />
2626
</trades>
2727
<positions>
28-
<position securityId="BTCUSD@CRYPTO" portfolio="TestPortfolio" openTime="1/15/2024 10:00:00 AM" openPrice="50000" closeTime="1/15/2024 11:00:00 AM" closePrice="50500" maxPosition="1" />
28+
<position securityId="BTCUSD@CRYPTO" portfolio="TestPortfolio" openTime="2024-01-15T10:00:00Z" openPrice="50000" closeTime="2024-01-15T11:00:00Z" closePrice="50500" maxPosition="1" />
2929
</positions>
3030
</strategy>

0 commit comments

Comments
 (0)