делаю так protected override bool OnProcess() { // если наша стратегия в процессе остановки if (base.ProcessState == StrategyProcessStates.Stopping) { // отменяем стратегию base.Orders.Where(o => o.State == OrderStates.Active).ForEach(base.Trader.GuarantyCancelOrder); return false; } var direction = OrderDirections.Buy; base.Volume = 1; var order = base.CreateOrder(direction, base.Security.GetMarketPrice(direction, MarketPriceTypes.Following), base.Volume); // регистрируем на котирование var strategy = new MarketQuotingStrategy(base.Trader, order, base.Interval, false, MarketPriceTypes.Following, new Unit()); strategy.Start(); base.ChildStrategies.Add(strategy);
return true;
//end
}
собирается без ошибок, но при нажатии на кнопку "старт" выскакивает
Kommentare (14)
Anmelden oder Konto erstellen, Melden Sie sich an oder registrieren Sie sich, um einen Kommentar zu hinterlassen
СтокШарп 1,6 на примере симплСМА
если сделать так
то исключение все равно не перехватывается :(
куда копать?
Сорри, отвечу по позднее. С ходу не могу понять.
Это говорит о том, что стакан пустой, и нет возможности его проанализировать. Котировки по ДДДЕ текут?
Насчет перехвата, не совсем понял. Раз MessageBox выводится - значит перехватывается. Думаю, через событие Strategy.Log
квик-джуниор - рулит :)
стакана вообще не было :) судя по описанию MarketQuotingStrategy можно было сделать не выходя за пределы таблицы "инструменты", а вот с другими стратегиями такой фокус не пройдет теперь буду знать что нужен стакан и выводить нужно так
а просто _trader.StartDde(lkoh); не идет, говорит что "окно LKOH не найдено"
сейчас переделал OnLog, там такое все разговорчивое оказывается private void OnLog(Strategy strategy, StrategyErrorStates errorState, string message) { // если стратегия вывела не просто сообщение, то вывести на экран. //if (errorState != StrategyErrorStates.None) // this.Sync(() => MessageBox.Show(this, message)); Console.WriteLine("[{0}] {1} => {2}", strategy.Id, errorState, message); }
[0] None => Quoting new order Buy with id 788915243 price 1566,99 volume 1 transaction 76 [0] Warning => Order 788915243 doesn't have a state [0] None => Quoting renewing order Buy with id 788915243 price 1566,99 volume 1 transaction 76 [0] None => Quoting renewed order Buy with id 788915281 price 1566,99 volume 1 transaction 77 [0] Warning => Order 788915281 doesn't have a state [0] Warning => Order 788915281 doesn't have a state [0] Warning => Order 788915281 doesn't have a state [0] None => Quoting renewing order Buy with id 788915281 price 1566,99 volume 1 transaction 77 [0] None => Quoting renewed order Buy with id 788915320 price 1566,99 volume 1 transaction 78 [0] Warning => Order 788915320 doesn't have a state [0] Warning => Order 788915320 doesn't have a state [0] None => Quoting renewing order Buy with id 788915320 price 1566,99 volume 1 transaction 78 [0] None => Quoting renewed order Buy with id 788915341 price 1566,99 volume 1 transaction 79 [0] Warning => Order 788915341 doesn't have a state [0] Warning => Order 788915341 doesn't have a state [0] None => Quoting renewing order Buy with id 788915341 price 1566,99 volume 1 transaction 79 [0] None => Quoting renewed order Buy with id 788915367 price 1566,99 volume 1 transaction 80 [0] Warning => Order 788915367 doesn't have a state [0] Warning => Order 788915367 doesn't have a state [0] Warning => Order 788915367 doesn't have a state [0] Warning => Order 788915367 doesn't have a state [0] Warning => Order 788915367 doesn't have a state [0] None => Quoting renewing order Buy with id 788915367 price 1566,99 volume 1 transaction 80 [0] None => Quoting renewed order Buy with id 788915436 price 1566,99 volume 1 transaction 81 [0] Warning => Order 788915436 doesn't have a state [0] Warning => Order 788915436 doesn't have a state [0] None => Quoting renewing order Buy with id 788915436 price 1566,99 volume 1 transaction 81 [0] None => Quoting renewed order Buy with id 788915468 price 1566,99 volume 1 transaction 82 [0] Warning => Order 788915468 doesn't have a state [0] Warning => Order 788915468 doesn't have a state [0] None => Quoting renewing order Buy with id 788915468 price 1566,99 volume 1 transaction 82 [0] None => Quoting renewed order Buy with id 788915490 price 1566,99 volume 1 transaction 83 [0] Warning => Order 788915490 doesn't have a state [0] Warning => Order 788915490 doesn't have a state [0] None => Quoting renewing order Buy with id 788915490 price 1566,99 volume 1 transaction 83 [0] None => Quoting renewed order Buy with id 788915524 price 1566,99 volume 1 transaction 84 [0] None => Quoting renewing order Buy with id 788915524 price 1566,99 volume 1 transaction 84 [0] None => Quoting renewed order Buy with id 788915538 price 1566,99 volume 1 transaction 85 [0] Warning => Order 788915538 doesn't have a state [0] Warning => Order 788915538 doesn't have a state [0] Warning => Order 788915538 doesn't have a state [0] None => Quoting renewing order Buy with id 788915538 price 1566,99 volume 1 transaction 85 [0] None => Quoting renewed order Buy with id 788915562 price 1566,99 volume 1 transaction 86 [0] Warning => Order 788915562 doesn't have a state [0] None => Quoting renewing order Buy with id 788915562 price 1566,99 volume 1 transaction 86 [0] None => Quoting renewed order Buy with id 788915581 price 1566,99 volume 1 transaction 87 [0] Warning => Order 788915581 doesn't have a state [0] Warning => Order 788915581 doesn't have a state [0] None => Quoting renewing order Buy with id 788915581 price 1566,99 volume 1 transaction 87
Вот что мне не понятно, так это почему происходит выставление и снятие по одной и той же цене? При неизменном стакане и спреде. Когда произошло изменение, то выставляется все верно и опять начинает скакать.
Да, надо дописать в доку, что нужен стакан.
Стакан полезнее просто лучший котировок потому что: 1) он быстрее 2) котирование учитывает другие потоки, чтобы предотвратить борьбу между ними. без стакана такое не вычислить.
Не встречал такого... Попробуйте перегрузить метод IsNeedReRegister и посмотреть, почему он так считает. Его текущая логика return this.Order.Price != GetNewPrice();
про борьбу я не подумал :) теперь про перегрузки: могзи сначало закипели, потом сварились, а когда стали поджариваться получилось это class my_MarketQuotingStrategy : MarketQuotingStrategy { public my_MarketQuotingStrategy(ITrader trader, Order order, TimeSpan interval, bool isForts, MarketPriceTypes priceType, Unit priceDelta) : base(trader, order, interval, isForts, priceType, priceDelta) { Console.WriteLine("dgdfg"); } protected override bool IsNeedReRegister() { Console.WriteLine("this.Order.Price={0}, GetNewPrice()={1}", this.Order.Price, GetNewPrice()); return this.Order.Price != GetNewPrice(); } } поскольку я полный чайник, то даже не могу понять чего я сделал, но на вывод получил это [0] None => ChStrategy runned "SampleSMA.vshost.exe" (управляемый): "C:\WINDOWS\assembly\GAC_MSIL \System.Runtime.Serialization \3.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" загружен, загрузка символов пропущена. Модуль оптимизирован, включен режим отладки "Только мой код". dgdfg this.Order.Price=1595, GetNewPrice()=1595 this.Order.Price=1595, GetNewPrice()=1595 this.Order.Price=1595, GetNewPrice()=1595 this.Order.Price=1595, GetNewPrice()=1595 this.Order.Price=1595, GetNewPrice()=1595 ...скип... this.Order.Price=1595, GetNewPrice()=1595 this.Order.Price=1595, GetNewPrice()=1595 this.Order.Price=1595, GetNewPrice()=1595 this.Order.Price=1595, GetNewPrice()=1602,32 [0] None => Quoting new order Buy price 1602,31 volume 1 [0] None => Quoting new order Buy with id 789112783 price 1602,31 volume 1 transaction 1 this.Order.Price=1602,31, GetNewPrice()=1595 [0] Warning => Order 789112783 doesn't have a state this.Order.Price=1602,31, GetNewPrice()=1595 [0] None => Quoting renewing order Buy with id 789112783 price 1602,31 volume 1 transaction 1 [0] None => Quoting renewed order Buy with id 789112810 price 1602,3 volume 1 transaction 2 this.Order.Price=1602,3, GetNewPrice()=1595 [0] None => Quoting renewing order Buy with id 789112810 price 1602,3 volume 1 transaction 2 [0] None => Quoting renewed order Buy with id 789112839 price 1594,99 volume 1 transaction 3 this.Order.Price=1594,99, GetNewPrice()=1595 [0] Warning => Order 789112839 doesn't have a state this.Order.Price=1594,99, GetNewPrice()=1595 [0] None => Quoting renewing order Buy with id 789112839 price 1594,99 volume 1 transaction 3 [0] None => Quoting renewed order Buy with id 789112856 price 1594,99 volume 1 transaction 4 this.Order.Price=1594,99, GetNewPrice()=1595 [0] None => Quoting renewing order Buy with id 789112856 price 1594,99 volume 1 transaction 4 [0] None => Quoting renewed order Buy with id 789112872 price 1594,99 volume 1 transaction 5 this.Order.Price=1594,99, GetNewPrice()=1595 [0] Warning => Order 789112872 doesn't have a state this.Order.Price=1594,99, GetNewPrice()=1595 [0] Warning => Order 789112872 doesn't have a state this.Order.Price=1594,99, GetNewPrice()=1595 [0] None => Quoting renewing order Buy with id 789112872 price 1594,99 volume 1 transaction 5 [0] None => Quoting renewed order Buy with id 789112893 price 1594,99 volume 1 transaction 6 this.Order.Price=1594,99, GetNewPrice()=1595 [0] Warning => Order 789112893 doesn't have a state this.Order.Price=1594,99, GetNewPrice()=1595 [0] None => Quoting renewing order Buy with id 789112893 price 1594,99 volume 1 transaction 6 [0] None => Quoting renewed order Buy with id 789112913 price 1594,99 volume 1 transaction 7 this.Order.Price=1594,99, GetNewPrice()=1595 [0] Warning => Order 789112913 doesn't have a state this.Order.Price=1594,99, GetNewPrice()=1595 [0] None => Quoting renewing order Buy with id 789112913 price 1594,99 volume 1 transaction 7 [0] None => Quoting renewed order Buy with id 789112935 price 1594,99 volume 1 transaction 8 this.Order.Price=1594,99, GetNewPrice()=1595 [0] None => Quoting renewing order Buy with id 789112935 price 1594,99 volume 1 transaction 8 [0] None => Quoting renewed order Buy with id 789112948 price 1594,99 volume 1 transaction 9 this.Order.Price=1594,99, GetNewPrice()=1595 [0] Warning => Order 789112948 doesn't have a state this.Order.Price=1594,99, GetNewPrice()=1595 [0] Warning => Order 789112948 doesn't have a state this.Order.Price=1594,99, GetNewPrice()=1595
и так далее, много-много раз т.е. выставление купли происходит на тик хуже лучшего бида, а поскольку оно не равно, то надо переставить... задать отступ не могу, там только на чтение // регистрируем на котирование var strategy = new my_MarketQuotingStrategy(base.Trader, order, base.Interval, false, MarketPriceTypes.Following, new Unit());
Агалогично, не сразу могу въехать. Требуется Ваша помощь. Можете сказать чему равны MinStepSize и Decimals для данного инструмента?
Плюс, могли бы Вы дополнительно выводить и вермя в лог, чтобы проследить, сколько времени прошло между теми, или иными строчками.
S# 1.6 на лукойле не знаю что такое Decimals (десятичные), а мин шаг = 0,01 рубля лог прикреплен к группе, там видно что первая заявка выставляется верно, но после изменения стакана, выставляется на MinStepSize ниже лучшей купли период вызова поставлен 0,3сек
Decimals - это точность цены. Под периодом я имел ввиду сам лог. Каждая запись имеет дату вывода. Например, через DateTime.Now.
лог тут
http://stocksharp.googlegroups.com/web/bot-log.txt?gda=I8UhmD4AAAD7ujiFr5Ha_HYNmvj19TvywXObw61_wlnOs-pFneTU11NG6vPM9pifSUoS6asTACPjsKXVs-X7bdXZc5buSfmx
прикреплен к группе
вывод сделан так private void OnLog(Strategy strategy, StrategyErrorStates errorState, string message) { // если стратегия вывела не просто сообщение, то вывести на экран. //if (errorState != StrategyErrorStates.None) // this.Sync(() => MessageBox.Show(this, message)); //else Console.WriteLine("{3} [{0}] {1} => {2}", strategy.Id, errorState, message, DateTime.Now.ToString("o"));//.ToString("o") ToLongTimeString } из этого protected override bool IsNeedReRegister() { //Console.WriteLine("{2} this.Order.Price={0}, GetNewPrice()={1}", this.Order.Price, GetNewPrice()); AddLog(Ecng.Trading.Algo.StrategyErrorStates.None, "this.Order.Price= " + this.Order.Price + " GetNewPrice()= " + GetNewPrice()); return this.Order.Price != GetNewPrice(); }
вот еще логи с MarketPriceTypes.Middle
http://stocksharp.googlegroups.com/web/bot-middle.txt?gda=b4DjV0EAAAD7ujiFr5Ha_HYNmvj19TvyqYLFUoA7S8O2fXDdlj4_8eCRmxtWo_ZylMcdYO3kGVRTCT_pCLcFTwcI3Sro5jAzlXFeCn-cdYleF-vtiGpWAA&gsc=3mZFCwsAAABUkaX7Cd6y5wy29deX8sae
и с MarketPriceTypes.Opposite
http://stocksharp.googlegroups.com/web/bot-opposite.txt?gda=_R4AykMAAAD7ujiFr5Ha_HYNmvj19TvyqYLFUoA7S8O2fXDdlj4_8XxREgZSFh1zkfZTN8MQdB8ytiJ-HdGYYcPi_09pl8N7FWLveOaWjzbYnpnkpmxcWg&gsc=3mZFCwsAAABUkaX7Cd6y5wy29deX8sae
При Middle купля ставится и снимается при неизменном в течении 10-15 сек стакане. При Opposite купля ставится на тик хуже офера и тоже может прыгать. когда проходят такие длинные листинги: 2010-03-14T16:45:16.2656250+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:16.5937500+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:16.9843750+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:17.2968750+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:17.7187500+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:18.0625000+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:18.4062500+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:18.7968750+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:19.2187500+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:19.5625000+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7 2010-03-14T16:45:19.8750000+03:00 [0] None => this.Order.Price= 1574,7 GetNewPrice()= 1574,7
то в это время заявка не выставлена
Послал на мыло.