Production hardening: kill switch, circuit breaker, trailing stops, log level, holiday calendar
Some checks failed
Build and Test / build (push) Has been cancelled

This commit is contained in:
2026-02-24 15:00:41 -05:00
parent 0e36fe5d23
commit a87152effb
50 changed files with 12849 additions and 752 deletions

View File

@@ -1,88 +1,126 @@
# C# 5.0 Syntax Requirements
# C# 5.0 Syntax Required for NT8 SDK
You are working on a .NET Framework 4.8 project that MUST use C# 5.0 syntax only.
This project targets **.NET Framework 4.8** and must use **C# 5.0 syntax only**.
NinjaTrader 8's NinjaScript compiler does not support C# 6+ features.
## Forbidden C# 6+ Features
---
## Forbidden Patterns (with fixes)
### String Interpolation (C# 6)
❌ NEVER use: `$"Order {orderId} at {price}"`
✅ ALWAYS use: `string.Format("Order {0} at {1}", orderId, price)`
### Null-Conditional Operators (C# 6)
❌ NEVER use: `var name = order?.Name`
❌ NEVER use: `var value = dict?[key]`
✅ ALWAYS use explicit null checks:
```csharp
var name = order != null ? order.Name : null;
if (dict != null && dict.ContainsKey(key)) { }
// ❌ NEVER
_logger.LogInformation($"Order {orderId} filled at {price}");
// ✅ ALWAYS
_logger.LogInformation("Order {0} filled at {1}", orderId, price);
```
### Null-Conditional Operator (C# 6)
```csharp
// ❌ NEVER
var name = order?.Symbol;
// ✅ ALWAYS
var name = order != null ? order.Symbol : null;
```
### Null-Coalescing Assignment (C# 8)
❌ NEVER use: `value ??= defaultValue;`
✅ ALWAYS use: `if (value == null) value = defaultValue;`
```csharp
// ❌ NEVER
value ??= defaultValue;
// ✅ ALWAYS
if (value == null) value = defaultValue;
```
### Expression-Bodied Members (C# 6)
❌ NEVER use: `public int Property => value;`
❌ NEVER use: `public void Method() => DoSomething();`
✅ ALWAYS use full syntax:
```csharp
public int Property
{
get { return value; }
}
// ❌ NEVER
public int Contracts => _contracts;
public void Reset() => _contracts = 0;
public void Method()
{
DoSomething();
}
// ✅ ALWAYS
public int Contracts { get { return _contracts; } }
public void Reset() { _contracts = 0; }
```
### nameof Operator (C# 6)
❌ NEVER use: `throw new ArgumentNullException(nameof(param));`
✅ ALWAYS use: `throw new ArgumentNullException("param");`
```csharp
// ❌ NEVER
throw new ArgumentNullException(nameof(intent));
// ✅ ALWAYS
throw new ArgumentNullException("intent");
```
### Auto-Property Initializers (C# 6)
❌ NEVER use: `public int Property { get; set; } = 10;`
✅ ALWAYS use constructor initialization:
```csharp
public int Property { get; set; }
// ❌ NEVER
public bool IsEnabled { get; set; } = true;
public ClassName()
{
Property = 10;
}
// ✅ ALWAYS — initialize in constructor
public bool IsEnabled { get; set; }
public MyClass() { IsEnabled = true; }
```
### Using Static (C# 6)
❌ NEVER use: `using static System.Math;`
✅ ALWAYS use: `System.Math.Floor(...)`
### Inline Out Variable Declaration (C# 7)
```csharp
// ❌ NEVER
if (_orders.TryGetValue(id, out var status)) { ... }
### Tuple Syntax (C# 7)
❌ NEVER use: `var tuple = (name: "test", value: 1);`
✅ ALWAYS use: `Tuple<string, int>` or custom classes
// ✅ ALWAYS
OrderStatus status;
if (_orders.TryGetValue(id, out status)) { ... }
```
### Pattern Matching (C# 7+)
❌ NEVER use: `if (obj is string str)`
✅ ALWAYS use: `if (obj is string) { var str = (string)obj; }`
### Pattern Matching (C# 7)
```csharp
// ❌ NEVER
if (obj is string s) { ... }
// ✅ ALWAYS
if (obj is string) { var s = (string)obj; ... }
```
### Local Functions (C# 7)
❌ NEVER use functions inside methods
✅ ALWAYS use private methods
### Out Variables (C# 7)
❌ NEVER use: `if (dict.TryGetValue(key, out var value))`
✅ ALWAYS use:
```csharp
OrderStatus value;
if (dict.TryGetValue(key, out value))
{
// Use value
// ❌ NEVER — function inside a method
public void Execute() {
void Helper() { ... }
Helper();
}
// ✅ ALWAYS — use private methods
private void Helper() { ... }
public void Execute() { Helper(); }
```
## Verification
After writing ANY code, verify C# 5.0 compliance:
- No `$` signs except in string literals
- No `?.` or `?[` operators
- No `=>` except in lambda expressions
- No inline variable declarations in out parameters
### Tuple Literals (C# 7)
```csharp
// ❌ NEVER
var result = (price: 100.0, qty: 5);
// ✅ ALWAYS — use Tuple<T1,T2> or a named class
var result = Tuple.Create(100.0, 5);
```
### using static (C# 6)
```csharp
// ❌ NEVER
using static System.Math;
// ✅ ALWAYS
System.Math.Floor(x);
Math.Floor(x); // (via standard using System;)
```
---
## Quick Self-Check Before Saving
- Search your code for `$"` — if found, replace every occurrence
- Search for `?.` — if found, replace with null check
- Search for `=>` — if on a property or method, rewrite as full block
- Search for `nameof` — replace with string literal
- Search for `out var` — split into declaration + assignment