# coding: cp1251 import sys import clr sys.path.append(r'c:\WORK\StockSharp\References') # harmless if there's no such path clr.AddReference('StockSharp.Quik') from StockSharp.Quik import QuikTerminal, QuikTrader clr.AddReference('StockSharp.BusinessEntities') from StockSharp.BusinessEntities import (Exchange, Currency, Security, Portfolio, Order, OrderDirections, ) clr.AddReference('StockSharp.Algo') from StockSharp.Algo.Testing import (EmulationTrader, TrendMarketDepthGenerator, RandomWalkTradeGenerator, ) from StockSharp.Algo.Logging import StrategyLogManager, FileLogListener from StockSharp.Algo.Storages import TradingStorage clr.AddReference('Ecng.Serialization') from Ecng.Serialization import InMemoryStorage from System.Collections.Generic import IEnumerable, List from System import TimeSpan, DateTime gen_securities = [ Security(Id="TST1", Code="TST1", Name="whatevername", MinStepSize=5, MinStepPrice=2, Decimals=0, Exchange=Exchange.Test), Security(Id="TST2", Code="TST2", Name="whatevername2", MinStepSize=5, MinStepPrice=2, Decimals=0, Exchange=Exchange.Test), ] logManager = StrategyLogManager() logManager.Listeners.Add(FileLogListener("log.txt")) portfolio = Portfolio(Name="twst account", BeginAmount=Currency(Value=1000000)) trader = EmulationTrader(List[Security](gen_securities), List[Portfolio]([portfolio]), MarketTimeChangedInterval=TimeSpan.FromMinutes(50)) for security in gen_securities: security.LastTrade.Price = 155000 trader.TradeGenerators[security] = RandomWalkTradeGenerator(security) trader.DepthGenerators[security] = TrendMarketDepthGenerator(security) def new_securities(securities): for security in securities: print "security", security trader.RegisterQuotes(security) def quotes_changed(depths): for depth in depths: print "Quotes: [{2}] {0} / {1}".format(depth.BestAsk.ToString(), depth.BestBid.ToString(), depth.Security) def connect_done(): print "connected" trader.NewSecurities += new_securities trader.QuotesChanged += quotes_changed trader.StartExport() trader.Start(DateTime(2009, 6, 1), DateTime(2009, 6, 2)) trader.Connected += connect_done trader.Connect() sys.stdin.readline()