mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-04 00:21:31 +00:00
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.
25 lines
657 B
C#
25 lines
657 B
C#
namespace StockSharp.Tests;
|
|
|
|
[TestClass]
|
|
public class InMemoryPortfolioMessageAdapterProviderTests : BaseTestClass
|
|
{
|
|
[TestMethod]
|
|
public void TryGetAdapter_NameInAnotherCase_FindsTheAdapter()
|
|
{
|
|
var provider = new InMemoryPortfolioMessageAdapterProvider();
|
|
var adapterId = Guid.NewGuid();
|
|
provider.SetAdapter("Main", adapterId);
|
|
|
|
AreEqual<Guid?>(adapterId, provider.TryGetAdapter("MAIN"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TryGetAdapter_NameWithAnInvisibleCharacter_FindsNothing()
|
|
{
|
|
var provider = new InMemoryPortfolioMessageAdapterProvider();
|
|
provider.SetAdapter("Main", Guid.NewGuid());
|
|
|
|
IsNull(provider.TryGetAdapter("Ma\u00ADin"));
|
|
}
|
|
}
|