mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-04 16:41:19 +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
635 B
C#
25 lines
635 B
C#
namespace StockSharp.Tests;
|
|
|
|
[TestClass]
|
|
public class InMemoryPositionStorageTests : BaseTestClass
|
|
{
|
|
[TestMethod]
|
|
public void LookupByPortfolioName_NameInAnotherCase_FindsThePortfolio()
|
|
{
|
|
var storage = new InMemoryPositionStorage();
|
|
var portfolio = new Portfolio { Name = "Main" };
|
|
storage.Save(portfolio);
|
|
|
|
AreSame(portfolio, storage.LookupByPortfolioName("MAIN"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void LookupByPortfolioName_NameWithAnInvisibleCharacter_FindsNothing()
|
|
{
|
|
var storage = new InMemoryPositionStorage();
|
|
storage.Save(new Portfolio { Name = "Main" });
|
|
|
|
IsNull(storage.LookupByPortfolioName("Ma\u00ADin"));
|
|
}
|
|
}
|