Skip to content

Commit 07ded61

Browse files
authored
Fix currency formatting (#7723)
* Replace currency string formatting with Lean currency symbols. Also clean up orders tags from having redundant information. * Setting default order tag only after price currency is properly set * Minor fixes and new unit tests * Minor fixes
1 parent 0cd979f commit 07ded61

32 files changed

+228
-141
lines changed

Algorithm.CSharp/AddBetaIndicatorRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
138138
{"Estimated Strategy Capacity", "$35000000.00"},
139139
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
140140
{"Portfolio Turnover", "1.51%"},
141-
{"OrderListHash", "e930f95771bc50dd2db1c353e054c4e7"}
141+
{"OrderListHash", "381bb9310f9dceb8a79a56849789bdab"}
142142
};
143143
}
144144
}

Algorithm.CSharp/BasicTemplateCryptoAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public override void OnEndOfAlgorithm()
237237
{"Estimated Strategy Capacity", "$0"},
238238
{"Lowest Capacity Asset", "BTCEUR 2XR"},
239239
{"Portfolio Turnover", "118.08%"},
240-
{"OrderListHash", "551b20736f4558a5af5c02b84451fb77"}
240+
{"OrderListHash", "77458586d24f1cd00623d63da8279be2"}
241241
};
242242
}
243243
}

Algorithm.CSharp/BybitCryptoRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public override void OnEndOfAlgorithm()
166166
{"Estimated Strategy Capacity", "₮560000.00"},
167167
{"Lowest Capacity Asset", "BTCUSDT 2UZ"},
168168
{"Portfolio Turnover", "44.04%"},
169-
{"OrderListHash", "fb30d137fffe2bc4195d261f0f195b69"}
169+
{"OrderListHash", "b3a9eb7392ba1eb7eb0cc387f7382b6c"}
170170
};
171171
}
172172
}

Algorithm.CSharp/CancelOpenOrdersRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public override void OnEndOfAlgorithm()
161161
{"Estimated Strategy Capacity", "$370000.00"},
162162
{"Lowest Capacity Asset", "ETHUSD 2XR"},
163163
{"Portfolio Turnover", "104.59%"},
164-
{"OrderListHash", "bd538acb61fa1fd91732212664c9bbed"}
164+
{"OrderListHash", "ec714d818fa30597e992d4c6e939e68c"}
165165
};
166166
}
167167
}

Algorithm.CSharp/ContinuousFutureLimitIfTouchedOrderRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public override void OnEndOfAlgorithm()
114114
{"Estimated Strategy Capacity", "$2600000000.00"},
115115
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
116116
{"Portfolio Turnover", "16.49%"},
117-
{"OrderListHash", "a8b0528aa2c4c2b8f013a06104ddb1d0"}
117+
{"OrderListHash", "a83211606af7216647acfd9b5f6907a5"}
118118
};
119119
}
120120
}

Algorithm.CSharp/ExtendedMarketTradingRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public bool InMarketHours()
136136
{"Estimated Strategy Capacity", "$14000000.00"},
137137
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
138138
{"Portfolio Turnover", "1.44%"},
139-
{"OrderListHash", "730d1d797bbe9449a6dc123990f5bd4b"}
139+
{"OrderListHash", "1ebbd6a077af944e04ee437a5219eef4"}
140140
};
141141
}
142142
}

Algorithm.CSharp/FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public override void OnEndOfAlgorithm()
149149
{"Estimated Strategy Capacity", "$3400000.00"},
150150
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
151151
{"Portfolio Turnover", "138.95%"},
152-
{"OrderListHash", "c85997dd5b7d9acda46ac9d11dd1a039"}
152+
{"OrderListHash", "b26a8ad66a8dc5af768a22fbf9a80cec"}
153153
};
154154
}
155155
}

Algorithm.CSharp/LimitFillRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
114114
{"Estimated Strategy Capacity", "$180000000.00"},
115115
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
116116
{"Portfolio Turnover", "9.86%"},
117-
{"OrderListHash", "14eaea4041585a9110df4b5861793f9e"}
117+
{"OrderListHash", "a5363ad9b8119f0e256a48efdc7acbb5"}
118118
};
119119
}
120120
}

Algorithm.CSharp/LimitIfTouchedRegressionAlgorithm.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public class LimitIfTouchedRegressionAlgorithm : QCAlgorithm, IRegressionAlgorit
3535
// We assert the following occur in FIFO order in OnOrderEvent
3636
private readonly Queue<string> _expectedEvents = new Queue<string>(new[]
3737
{
38-
"Time: 10/10/2013 13:31:00 OrderID: 72 EventID: 399 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: 144.6434 USD LimitPrice: 144.3551 TriggerPrice: 143.61 OrderFee: 1 USD",
39-
"Time: 10/10/2013 15:57:00 OrderID: 73 EventID: 156 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: 145.6636 USD LimitPrice: 145.6434 TriggerPrice: 144.89 OrderFee: 1 USD",
40-
"Time: 10/11/2013 15:37:00 OrderID: 74 EventID: 380 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: 146.7185 USD LimitPrice: 146.6723 TriggerPrice: 145.92 OrderFee: 1 USD" });
38+
"Time: 10/10/2013 13:31:00 OrderID: 72 EventID: 399 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: $144.6434 LimitPrice: $144.3551 TriggerPrice: $143.61 OrderFee: 1 USD",
39+
"Time: 10/10/2013 15:57:00 OrderID: 73 EventID: 156 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: $145.6636 LimitPrice: $145.6434 TriggerPrice: $144.89 OrderFee: 1 USD",
40+
"Time: 10/11/2013 15:37:00 OrderID: 74 EventID: 380 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: $146.7185 LimitPrice: $146.6723 TriggerPrice: $145.92 OrderFee: 1 USD" });
4141

4242
/// <summary>
4343
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
@@ -74,10 +74,10 @@ public override void OnData(Slice data)
7474
$"LIT - Quantity: {_negative * 10}");
7575
_request = Transactions.AddOrder(orderRequest);
7676
return;
77-
77+
7878
}
7979

80-
// Order updating if request exists
80+
// Order updating if request exists
8181
if (_request != null)
8282
{
8383
if (_request.Quantity == 1)
@@ -105,7 +105,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
105105

106106
if (orderEvent.ToString() != expected)
107107
{
108-
throw new Exception($"orderEvent {orderEvent.Id} differed from {expected}");
108+
throw new Exception($"orderEvent {orderEvent.Id} differed from {expected}. Actual {orderEvent}");
109109
}
110110
}
111111
}

Algorithm.CSharp/LimitOrdersAreFilledAfterHoursForFuturesRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
149149
{"Estimated Strategy Capacity", "$39000000.00"},
150150
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
151151
{"Portfolio Turnover", "33.59%"},
152-
{"OrderListHash", "170df706887bac7764441b9368887a1d"}
152+
{"OrderListHash", "8b3baab1411a6db34780601bdd68ef9e"}
153153
};
154154
}
155155
}

Algorithm.CSharp/OptionAssignmentStatisticsRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ private static bool AreEqual(decimal expected, decimal actual)
302302
{"Estimated Strategy Capacity", "$0"},
303303
{"Lowest Capacity Asset", "GOOCV VP83T1ZUHROL"},
304304
{"Portfolio Turnover", "50.31%"},
305-
{"OrderListHash", "92d006d828b582a7cc78eeb4c0161356"}
305+
{"OrderListHash", "eaa2b6ffada95de55b095ed2e9953e33"}
306306
};
307307
}
308308
}

Algorithm.CSharp/OptionEquityStrategyMatcherRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public override void OnData(Slice slice)
148148
{"Estimated Strategy Capacity", "$0"},
149149
{"Lowest Capacity Asset", "GOOCV W78ZFMEBBB2E|GOOCV VP83T1ZUHROL"},
150150
{"Portfolio Turnover", "274.86%"},
151-
{"OrderListHash", "0948e7066371a8aae356145cbac0741c"}
151+
{"OrderListHash", "9aa5e8c352571222f77407c62a5795c4"}
152152
};
153153
}
154154
}

Algorithm.CSharp/ScaledFillForwardDataRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public override void OnEndOfAlgorithm()
132132
{"Estimated Strategy Capacity", "$26000.00"},
133133
{"Lowest Capacity Asset", "AOL R735QTJ8XC9X"},
134134
{"Portfolio Turnover", "12.68%"},
135-
{"OrderListHash", "215c8a8ac308c82fb7b0b46f3be0972e"}
135+
{"OrderListHash", "0241913ee2f0fa5af72e311a09c39f4e"}
136136
};
137137
}
138138
}

Algorithm.CSharp/ShortableProviderOrdersRejectedRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public RegressionTestShortableProvider() : base("testbrokerage")
212212
{"Estimated Strategy Capacity", "$99000000.00"},
213213
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
214214
{"Portfolio Turnover", "0.23%"},
215-
{"OrderListHash", "32ac6dfd7b74518f14fb0210ce0360df"}
215+
{"OrderListHash", "7d60ef344c55973a95131cdeefdbaeb3"}
216216
};
217217
}
218218
}

Algorithm.CSharp/SplitEquityRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public override void OnEndOfAlgorithm()
184184
{"Estimated Strategy Capacity", "$0"},
185185
{"Lowest Capacity Asset", ""},
186186
{"Portfolio Turnover", "0%"},
187-
{"OrderListHash", "7eca64a29976e1c2f206dd92b0930522"}
187+
{"OrderListHash", "b1df545a12beb8868606e0da35c151d0"}
188188
};
189189
}
190190
}

Algorithm.CSharp/StopLimitOrderRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public override void OnEndOfAlgorithm()
178178
{"Estimated Strategy Capacity", "$2700000000.00"},
179179
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
180180
{"Portfolio Turnover", "0.02%"},
181-
{"OrderListHash", "60a73554224704136fff171dd50d8d28"}
181+
{"OrderListHash", "ebb6f711f14449c0cf8dcee645b34956"}
182182
};
183183
}
184184
}

Algorithm.CSharp/StopLossOnOrderEventRegressionAlgorithm.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public override void OnOrderEvent(OrderEvent orderEvent)
4444
{
4545
// Entry short $2 below
4646
var stopPrice = orderEvent.FillPrice - 2;
47-
Debug($"Enter short at {orderEvent.FillPrice} set STOPLOSS at {stopPrice:C}");
47+
var currencySymbol = Currencies.GetCurrencySymbol(order.PriceCurrency);
48+
Debug($"Enter short at {orderEvent.FillPrice} set STOPLOSS at {currencySymbol}{stopPrice}");
4849
StopMarketOrder(order.Symbol, -order.Quantity, stopPrice, "StopLoss");
4950
}
5051
}

Algorithm.CSharp/TimeInForceAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public override void OnEndOfAlgorithm()
184184
{"Estimated Strategy Capacity", "$44000000.00"},
185185
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
186186
{"Portfolio Turnover", "0.87%"},
187-
{"OrderListHash", "4f94db1e287d9dd7026bda8c93a62876"}
187+
{"OrderListHash", "9ce26e877ba1b5dbe19765fb5374334e"}
188188
};
189189
}
190190
}

Algorithm.CSharp/TrailingStopOrderRegressionAlgorithm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public override void OnOrderEvent(OrderEvent orderEvent)
176176
{"Estimated Strategy Capacity", "$36000000.00"},
177177
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
178178
{"Portfolio Turnover", "5.79%"},
179-
{"OrderListHash", "52f67285c3f5ecdc66f89cb1c0d08421"}
179+
{"OrderListHash", "fcfc3ecf4a3eff97be9f07305c97ad95"}
180180
};
181181
}
182182
}

Algorithm.Python/LimitIfTouchedRegressionAlgorithm.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
### <meta name="tag" content="limit if touched order"/>
2323
class LimitIfTouchedRegressionAlgorithm(QCAlgorithm):
2424
_expectedEvents = deque([
25-
"Time: 10/10/2013 13:31:00 OrderID: 72 EventID: 399 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: 144.6434 USD LimitPrice: 144.3551 TriggerPrice: 143.61 OrderFee: 1 USD",
26-
"Time: 10/10/2013 15:57:00 OrderID: 73 EventID: 156 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: 145.6636 USD LimitPrice: 145.6434 TriggerPrice: 144.89 OrderFee: 1 USD",
27-
"Time: 10/11/2013 15:37:00 OrderID: 74 EventID: 380 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: 146.7185 USD LimitPrice: 146.6723 TriggerPrice: 145.92 OrderFee: 1 USD" ])
25+
"Time: 10/10/2013 13:31:00 OrderID: 72 EventID: 399 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: $144.6434 LimitPrice: $144.3551 TriggerPrice: $143.61 OrderFee: 1 USD",
26+
"Time: 10/10/2013 15:57:00 OrderID: 73 EventID: 156 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: $145.6636 LimitPrice: $145.6434 TriggerPrice: $144.89 OrderFee: 1 USD",
27+
"Time: 10/11/2013 15:37:00 OrderID: 74 EventID: 380 Symbol: SPY Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: $146.7185 LimitPrice: $146.6723 TriggerPrice: $145.92 OrderFee: 1 USD" ])
2828

2929
def Initialize(self):
3030
self.SetStartDate(2013, 10, 7)
@@ -51,11 +51,11 @@ def OnData(self, data):
5151
return
5252

5353
new_quantity = int(self._request.Quantity - self._negative)
54-
self._request.UpdateQuantity(new_quantity, f"LIT - Quantity: {new_quantity}")
54+
self._request.UpdateQuantity(new_quantity, f"LIT - Quantity: {new_quantity}")
5555
self._request.UpdateTriggerPrice(Extensions.RoundToSignificantDigits(self._request.Get(OrderField.TriggerPrice), 5));
5656

5757
def OnOrderEvent(self, orderEvent):
5858
if orderEvent.Status == OrderStatus.Filled:
5959
expected = self._expectedEvents.popleft()
60-
if orderEvent.ToString() != expected:
61-
raise Exception(f"orderEvent {orderEvent.Id} differed from {expected}")
60+
if str(orderEvent) != expected:
61+
raise Exception(f"orderEvent {orderEvent.Id} differed from {expected}. Actual {orderEvent}")

Common/Currencies.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ public static class Currencies
145145
{"LSK", "Ⱡ"},
146146
{"NAV", "Ꞥ"}
147147
};
148-
148+
149149
/// <summary>
150150
/// Stable pairs in GDAX. We defined them because they have different fees in GDAX market
151151
/// </summary>
152152
[Obsolete("StablePairsGDAX is deprecated. Use StablePairsCoinbase instead.")]
153153
public static readonly HashSet<string> StablePairsGDAX = StablePairsCoinbase;
154-
154+
155155
/// <summary>
156156
/// Stable pairs in Coinbase. We defined them because they have different fees in Coinbase market
157157
/// </summary>
@@ -174,7 +174,7 @@ public static class Currencies
174174
"USTUSDT",
175175
"WBTCBTC"
176176
};
177-
177+
178178
/// <summary>
179179
/// Define some StableCoins that don't have direct pairs for base currencies in our SPDB in Coinbase market
180180
/// This is because some CryptoExchanges do not define direct pairs with the stablecoins they offer.
@@ -272,8 +272,12 @@ public static bool IsStableCoinWithoutPair(string symbol, string market)
272272
/// <returns>The currency symbol</returns>
273273
public static string GetCurrencySymbol(string currency)
274274
{
275-
string currencySymbol;
276-
return CurrencySymbols.TryGetValue(currency, out currencySymbol) ? currencySymbol : currency;
275+
if (string.IsNullOrEmpty(currency))
276+
{
277+
return string.Empty;
278+
}
279+
280+
return CurrencySymbols.TryGetValue(currency, out var currencySymbol) ? currencySymbol : currency;
277281
}
278282

279283
/// <summary>

0 commit comments

Comments
 (0)