ADR 0009 records the Phase 3 choices; API-NOTES gains the verified trading facts and what Anubis does with each; ROADMAP and STATE mark the phase done with the live-demo conformance waiting for the user's keys. Two defects found while writing the notes: - The positions CSV used dot decimals; SPEC 13 asks for decimal commas. Trailing zeros are dropped so both engines give the same text. - Alpaca's catalogue has no tick, so limit and stop prices were sent unrounded and would get 422 "sub-penny". OrderRules.TickOf applies Alpaca's rule (2 decimals from 1 $, 4 below) to orders, stops and the simulator's own check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4c4f848d80
commit
60d5ebbc05
10 files changed
+169
-30
No files matched your search
@@ -151,7 +151,7 @@ internal sealed record AccountsView(
|
||||
return new AccountsView(cards, rows.Select(r => r.Row).ToList(), pending, others, alpacaStops, residueRows, slices, fx?.Rate, fx?.Date, fxEffect, market.Open, market.Next);
|
||||
}
|
||||
|
||||
/// <summary>The positions as CSV for a spreadsheet: semicolons, dot decimals, one row per position.</summary>
|
||||
/// <summary>The positions as CSV for an Italian spreadsheet (SPEC 13): semicolons, decimal commas, no thousands separator, one row per position.</summary>
|
||||
public string Csv(string? broker)
|
||||
{
|
||||
var text = new StringBuilder("strumento;nome;conto;strategia;quantita;prezzo_medio;prezzo_ora;valuta;valore_eur;risultato_eur;stop;aperta_il\n");
|
||||
@@ -164,7 +164,8 @@ internal sealed record AccountsView(
|
||||
|
||||
return text.ToString();
|
||||
|
||||
static string Number(decimal value) => value.ToString(CultureInfo.InvariantCulture);
|
||||
// Trailing zeros dropped, so both database engines give the same text.
|
||||
static string Number(decimal value) => (value / 1.000000000000000000000000000000000m).ToString(CultureInfo.InvariantCulture).Replace('.', ',');
|
||||
|
||||
static string Clean(string value) => value.Replace(';', ',').Replace('\n', ' ');
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public sealed partial class OrderManager
|
||||
return;
|
||||
}
|
||||
|
||||
var level = OrderRules.StopPrice(position.StopPrice.Value, instrument.Spec.TickSize);
|
||||
var level = OrderRules.StopPrice(position.StopPrice.Value, OrderRules.TickOf(instrument.Spec, position.StopPrice.Value));
|
||||
var desired = DesiredStops(instrument, position.Quantity);
|
||||
var current = open.Select(o => (o.Quantity - o.Filled, o.TimeInForce)).OrderBy(x => x.Item1).ToList();
|
||||
if (open.All(o => o.Stop == level) && current.SequenceEqual(desired.OrderBy(x => x.Quantity)))
|
||||
|
||||
@@ -201,6 +201,21 @@ public static class OrderRules
|
||||
return spec.MinNotional ?? (spec.Venue == Venues.Alpaca ? AlpacaMinimumNotional : 0m);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The price step at a price: the venue's tick, or Alpaca's rule when the catalogue has none (2 decimals from 1 $,
|
||||
/// 4 below; otherwise 422 "sub-penny increment", API-NOTES Fase 3).
|
||||
/// </summary>
|
||||
public static decimal? TickOf(InstrumentSpec spec, decimal price)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(spec);
|
||||
if (spec.TickSize is > 0m)
|
||||
{
|
||||
return spec.TickSize;
|
||||
}
|
||||
|
||||
return spec.Venue == Venues.Alpaca ? (price >= 1m ? 0.01m : 0.0001m) : null;
|
||||
}
|
||||
|
||||
public static decimal RoundDown(decimal value, decimal step) => step <= 0m ? value : Math.Floor(value / step) * step;
|
||||
|
||||
public static decimal RoundUp(decimal value, decimal step) => step <= 0m ? value : Math.Ceiling(value / step) * step;
|
||||
@@ -242,8 +257,8 @@ public static class OrderRules
|
||||
return new(rounded, null, null, OrderReasons.BelowMinimumSize);
|
||||
}
|
||||
|
||||
var limit = limitPrice is null ? (decimal?)null : LimitPrice(limitPrice.Value, side, spec.TickSize);
|
||||
var stop = stopPrice is null ? (decimal?)null : StopPrice(stopPrice.Value, spec.TickSize);
|
||||
var limit = limitPrice is null ? (decimal?)null : LimitPrice(limitPrice.Value, side, TickOf(spec, limitPrice.Value));
|
||||
var stop = stopPrice is null ? (decimal?)null : StopPrice(stopPrice.Value, TickOf(spec, stopPrice.Value));
|
||||
var price = limit ?? stop ?? referencePrice;
|
||||
if (price <= 0m)
|
||||
{
|
||||
|
||||
@@ -682,7 +682,7 @@ public sealed class PaperBroker : IBrokerAccount, IDisposable
|
||||
return "stop_must_be_sell";
|
||||
}
|
||||
|
||||
if (spec.TickSize is > 0m && price is { } p && OrderRules.RoundDown(p, spec.TickSize.Value) != p)
|
||||
if (price is { } p && OrderRules.TickOf(spec, p) is { } tick && OrderRules.RoundDown(p, tick) != p)
|
||||
{
|
||||
return "price_not_on_tick";
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user