A run whose market data was all refused for lack of history waited for
its first subscription forever. It ends now when it starts with all the
market data asked for refused. Whether any is left is decided when the
run starts, never at a refusal: a strategy asks for one series after
another, so the refusal of a pair's first leg comes before its second
is asked for, and stopping there ended a run that had the second leg's
history. A run with nothing asked for yet keeps waiting, as a host may
start the strategy after the run, as the Studio runner does.
Such a run ends with an error rather than as a finished one: Connector.
Error says the market data is missing, StopError keeps it for a host
that looks once the run has stopped, and the progress does not reach
100. A run stopped on a failed subscription (StopOnSubscriptionError)
ends the same way. A strategy that asks for no market data, or whose
market data was all refused, is stopped with that error by
StrategyHelper.StopIfNoMarketDataAsync once it has started, which
ExecAsync and the optimizer use: ExecAsync reported such a run as
completed or waited for it forever, and the optimizer's check ran
before the connector was connected and left the iteration waiting.
Partial history, which the tests never fed a run, had more of the same:
- a refused subscription kept the strategy offline for the whole run,
so a run that went on with the data it had sent no order. Only a
subscription refused before it got going is left out; one that fails
after it went online still takes the strategy offline, its data gone;
- ticks only a generator made never started the replay;
- a series stored only outside the run's dates stood in for the run's
own data, so five-minute candles were not built from the run's
one-minute candles and none arrived;
- a subscription added during the run made the replay send again what
it had already sent at that moment, and with the cache of days it got
nothing until the next day, the cache knowing a day by its date alone;
- history that ended before the run's stop left its progress at a
fifth. A run that runs out of history reports the whole way now; one
disconnected halfway still reports where it stopped, which the
optimizer goes by to stop the strategy of an iteration it cancels;
- an instrument whose history ended before the run's kept its last bid
and ask, so orders on it filled in any volume at a day-old price. Once
its last bar is handed over its market closes: a market order finds
no price, a limit waits, a position keeps the value of the quotes the
market closed with, and more history opens the market again;
- a day without history moved the strategy's clock twice, just after
midnight, and the clock reached the stop only after the run had
stopped. The replay walks such a day at the pace of the time-frame
candles and generators it still replays, the emulator hands the clock
on with every bar it releases, and the run's last moment is its stop
date, so timers and time rules fire through the gaps. Ticks, quotes
and the order log keep no pace, and the days after every history has
ended are marked only where they begin, so a long stop after the
history costs no more than it did.
Instrument lookups, configuration, credentials, CSV entities, snapshots and
the alert processing service are read and written asynchronously; the
blocking synchronous forms are obsolete wrappers.
IAsyncPersistable replaces IPersistable: every type that saves and loads its
settings has LoadAsync and SaveAsync only, and nested objects are read with
GetValueAsync, LoadEntireAsync and LoadAllAsync. The synchronous Load and Save
are the obsolete Ecng extensions. The MultiConnect sample keeps IPersistable
for two settings classes, because the settings window of the published
StockSharp.Xaml package takes it.
Copies that were made by saving and loading are made asynchronously.
IMessageAdapter, IIndicator, the risk, commission, PnL, latency, slippage and
position managers, IStorageBuffer, Strategy, DiagramElement, ICompositionModel
and its nodes get CloneAsync and no longer implement ICloneable; Clone is an
obsolete blocking wrapper. A strategy copy keeps every security and portfolio
parameter the original holds. Messages, FieldMapping, BankDetails and
WithdrawInfo are copied in memory. A CommissionRuleMessage shares its rule and
the emulator takes a copy of it. Envelope gets a constructor that takes all
three lines and CreateAsync.
ToBruteForce and ToBruteForceRandom become ToBruteForceAsync and
ToBruteForceRandomAsync and return IAsyncEnumerable; BruteForceOptimizer runs
over it and takes the next strategy through an asynchronous delegate.
Diagram elements keep their own state in SaveState, OnLoading and LoadState.
Undo restores an in-memory snapshot; a chart element holds its series and
axes in it by reference. An alert rule keeps its value in the form a message
carries it. A diagram strategy applies composition settings that were loaded
before the composition was set in SetCompositionAsync or at the start, and
saves them while they wait.
Strategies get an OnStartedAsync hook; diagram strategies resolve securities,
underlyings and strikes before the start so value processing never looks up
instruments. Paths.Serialize, SerializeInvariant, AppStartSettings.TrySave,
ICredentialsProvider.Save, ISnapshotSerializer.Serialize and the composition
registry gain async forms.
ICredentialsProvider.Delete becomes DeleteAsync, so loading, saving and
deleting the credentials wait for one another. Paths.InstalledVersion and
AppNameWithVersion are obsolete in favour of GetInstalledVersionAsync and
GetAppNameWithVersionAsync.
A file is opened for writing only after the last cancellation check, because
opening it empties it; a cancelled read reports the cancellation instead of
an empty result. A snapshot flush that failed leaves what it took due for the
next one.
The indicator templates for C#, F# and Python override LoadAsync and
SaveAsync.
A venue tells an account what it holds: money, positions, their entry
prices and what each position has gained or lost. The emulator reported
only the account total, and only when an order changed something - and
in a backtest even that never arrived. A position adapter recounting
positions from trades answered the portfolio lookup itself, so the
emulator had no portfolio subscription and every report it made about
the account was dropped. A strategy that manages a basket by the
floating profit of its positions could not work in a backtest.
- The matching engine reports a position with its floating profit,
marked at the price it could be closed at, with every fill and again
whenever the market moves that price. The market emulator of a
backtest reports it with every fill and revalues open positions
before each bar it hands over, so a subscriber acting on a bar reads
the positions that bar produced, without a report for every price in
between.
- Positions are no longer recounted around the emulator, and the
portfolio lookup reaches it. An account the emulator opens starts
with the money of the portfolio it stands for instead of zero.
- An order a subscriber sends in reaction to a message runs before the
rest of that message's batch is delivered, so the account reports the
batch still holds about an account the order changed are dropped
instead of arriving after the newer ones.
Reporting the positions on every bar sends portfolio names and security
ids through lookups that compared them by the invariant culture, which
on .NET runs through ICU: hashing a portfolio name and checking whether
a security is the all-securities placeholder took more time than the
rest of handling a position report. They are identifiers and now ignore
case ordinally, so names that differ by a character the culture skips,
such as a soft hyphen, are no longer taken for the same name. This
covers the emulator's portfolios, the in-memory position storage, the
portfolio-to-adapter map, the optimizer's portfolio copies,
Security.ToSecurityId and IsAllSecurity.
A backtest now raises PortfolioReceived as live trading does.
A bar covering five minutes reached a strategy stamped with the minute it
began - so the strategy learned that bar's high, low and close at the instant
the bar started. Knowledge of the future, in the data itself, before any
question of matching.
The emulator already had this right and its work was being thrown away. It
clones each stored bar at the close, stamps it with that moment and replays the
bar's prices into the book right there; but the stored copy travelled straight
through to the connector at the bar's open, and the subscription manager keeps
only the first copy of a bar it sees finished. The strategy got the early one
and the correct one was dropped.
In a run the emulator owns the clock, so the stored copy no longer goes past:
the bar is handed over once, at its close, with its prices already in the book.
That makes the first bar of a run tradeable - it used to meet an empty book -
and it is what a live connector has always done, where a finished bar is stamped
with the value that closed it.
The run's last bar closes after the last data message, so the emulator is given
the stopping marker as well and hands that bar over on it, rather than losing it
at the edge.
Ticks go exclusively through the emulator path (not the parent wrapper
chain). MarketEmulator now forwards ticks via results so they reach
CandleBuilderMessageAdapter through the emulator output.
Move 9 core matching engine files (OrderBook, OrderMatcher, PortfolioManager,
MarginController, OrderLifecycleManager) into standalone MatchingEngine project
with namespace StockSharp.MatchingEngine. MarketEmulator stays in Algo.Testing
and references MatchingEngine. Update all solution files and test references.
- EmulationMessageAdapter: forward messages to base when OwnInnerAdapter
- BacktestingTests: start strategy before connect (like BaseOptimizer)
- Add skip if history data not available