Base algorithms |
Along with Quoting, the S# contains the TraderHelper class, which includes a variety of simple trading algorithms methods:
To clear the order book from its own orders through the GetFilteredQuotes(IEnumerableQuote, IEnumerableOrder, IEnumerableOrder) method (to register the orders in relation to other market players and to prevent own algorithms to fight each other):
// the sample security var someSecurity = _connector.Securities.First(); var someOrders = new List<Order>(); // fill the collection by own orders // to get the best big price Console.WriteLine(_connector.GetMarketDepth(someSecurity).GetFilteredQuotes(Sides.Buy, someOrders, null).Max(q => q.Price));
To adjust the price through the ShrinkPrice(Security, Decimal, ShrinkRules) method, so it become a multiple of price increment and trading system accepts the order:
// the sample security var someSecurity = _connector.Securities.First(); Console.WriteLine(someSecurity.ShrinkPrice(13453.65342));
To get the position on closed trades through the GetPosition method:
Console.WriteLine(_connector.GetPosition(Portfolio,Security, clientCode, depoName);
To check whether the current time traded (is session closed? is clearing started?) through the IsTradeTime method:
// the sample security var someSecurity = _connector.Securities.First(); Console.WriteLine(someSecurity.Board.IsTradeTime(currentTime));
The rest of the TraderHelper class methods are described in the Order cancel and Order replace sections.