public async Task<long> CreateStopOrder(StopOrder stopOrder) { Transaction newStopOrderTransaction = new Transaction { ACTION = TransactionAction.NEW_STOP_ORDER, ACCOUNT = stopOrder.Account, CLASSCODE = stopOrder.ClassCode, SECCODE = stopOrder.SecCode, EXPIRY_DATE = "GTC",//до отмены STOPPRICE = stopOrder.ConditionPrice, PRICE = stopOrder.Price, QUANTITY = stopOrder.Quantity, STOP_ORDER_KIND = ConvertStopOrderType(stopOrder.StopOrderType), OPERATION = stopOrder.Operation == Operation.Buy?TransactionOperation.B : TransactionOperation.S }; //todo: Not implemented //["OFFSET"]=tostring(SysFunc.toPrice(SecCode,MaxOffset)), //["OFFSET_UNITS"]="PRICE_UNITS", //["SPREAD"]=tostring(SysFunc.toPrice(SecCode,DefSpread)), //["SPREAD_UNITS"]="PRICE_UNITS", //["MARKET_STOP_LIMIT"]="YES", //["MARKET_TAKE_PROFIT"]="YES", //["STOPPRICE2"]=tostring(SysFunc.toPrice(SecCode,StopLoss)), //["EXECUTION_CONDITION"] = "FILL_OR_KILL", return await Quik.Trading.SendTransaction(newStopOrderTransaction); }
private void ProcessCallbackMessage(IMessage message) { if (message == null) { throw new ArgumentNullException("message"); } EventNames eventName; var parsed = Enum.TryParse(message.Command, true, out eventName); if (parsed) { // TODO use as instead of assert+is+cast switch (eventName) { case EventNames.OnAccountBalance: Trace.Assert(message is Message <AccountBalance>); var accBal = ((Message <AccountBalance>)message).Data; Events.OnAccountBalanceCall(accBal); break; case EventNames.OnAccountPosition: Trace.Assert(message is Message <AccountPosition>); var accPos = ((Message <AccountPosition>)message).Data; Events.OnAccountPositionCall(accPos); break; case EventNames.OnAllTrade: Trace.Assert(message is Message <AllTrade>); var allTrade = ((Message <AllTrade>)message).Data; allTrade.LuaTimeStamp = message.CreatedTime; Events.OnAllTradeCall(allTrade); break; case EventNames.OnCleanUp: Trace.Assert(message is Message <string>); Events.OnCleanUpCall(); break; case EventNames.OnClose: Trace.Assert(message is Message <string>); Events.OnCloseCall(); break; case EventNames.OnConnected: Trace.Assert(message is Message <string>); Events.OnConnectedCall(); break; case EventNames.OnDepoLimit: Trace.Assert(message is Message <DepoLimitEx>); var dLimit = ((Message <DepoLimitEx>)message).Data; Events.OnDepoLimitCall(dLimit); break; case EventNames.OnDepoLimitDelete: Trace.Assert(message is Message <DepoLimitDelete>); var dLimitDel = ((Message <DepoLimitDelete>)message).Data; Events.OnDepoLimitDeleteCall(dLimitDel); break; case EventNames.OnDisconnected: Trace.Assert(message is Message <string>); Events.OnDisconnectedCall(); break; case EventNames.OnFirm: Trace.Assert(message is Message <Firm>); var frm = ((Message <Firm>)message).Data; Events.OnFirmCall(frm); break; case EventNames.OnFuturesClientHolding: Trace.Assert(message is Message <FuturesClientHolding>); var futPos = ((Message <FuturesClientHolding>)message).Data; Events.OnFuturesClientHoldingCall(futPos); break; case EventNames.OnFuturesLimitChange: Trace.Assert(message is Message <FuturesLimits>); var futLimit = ((Message <FuturesLimits>)message).Data; Events.OnFuturesLimitChangeCall(futLimit); break; case EventNames.OnFuturesLimitDelete: Trace.Assert(message is Message <FuturesLimitDelete>); var limDel = ((Message <FuturesLimitDelete>)message).Data; Events.OnFuturesLimitDeleteCall(limDel); break; case EventNames.OnInit: // Этот callback никогда не будет вызван так как на момент получения вызова OnInit в lua скрипте // соединение с библиотекой QuikSharp не будет еще установлено. То есть этот callback не имеет смысла. break; case EventNames.OnMoneyLimit: Trace.Assert(message is Message <MoneyLimitEx>); var mLimit = ((Message <MoneyLimitEx>)message).Data; Events.OnMoneyLimitCall(mLimit); break; case EventNames.OnMoneyLimitDelete: Trace.Assert(message is Message <MoneyLimitDelete>); var mLimitDel = ((Message <MoneyLimitDelete>)message).Data; Events.OnMoneyLimitDeleteCall(mLimitDel); break; case EventNames.OnNegDeal: break; case EventNames.OnNegTrade: break; case EventNames.OnOrder: Trace.Assert(message is Message <Order>); var ord = ((Message <Order>)message).Data; ord.LuaTimeStamp = message.CreatedTime; Events.OnOrderCall(ord); break; case EventNames.OnParam: Trace.Assert(message is Message <Param>); var data = ((Message <Param>)message).Data; Events.OnParamCall(data); break; case EventNames.OnQuote: Trace.Assert(message is Message <OrderBook>); var ob = ((Message <OrderBook>)message).Data; ob.LuaTimeStamp = message.CreatedTime; Events.OnQuoteCall(ob); break; case EventNames.OnStop: Trace.Assert(message is Message <string>); Events.OnStopCall(int.Parse(((Message <string>)message).Data)); break; case EventNames.OnStopOrder: Trace.Assert(message is Message <StopOrder>); StopOrder stopOrder = ((Message <StopOrder>)message).Data; StopOrders.RaiseNewStopOrderEvent(stopOrder); break; case EventNames.OnTrade: Trace.Assert(message is Message <Trade>); var trade = ((Message <Trade>)message).Data; trade.LuaTimeStamp = message.CreatedTime; Events.OnTradeCall(trade); break; case EventNames.OnTransReply: Trace.Assert(message is Message <TransactionReply>); var trReply = ((Message <TransactionReply>)message).Data; trReply.LuaTimeStamp = message.CreatedTime; Events.OnTransReplyCall(trReply); break; case EventNames.NewCandle: Trace.Assert(message is Message <Candle>); var candle = ((Message <Candle>)message).Data; Candles.RaiseNewCandleEvent(candle); break; default: throw new ArgumentOutOfRangeException(); } } else { switch (message.Command) { // an error from an event not request (from req is caught is response loop) case "lua_error": Trace.Assert(message is Message <string>); Trace.TraceError(((Message <string>)message).Data); break; default: throw new InvalidOperationException("Unknown command in a message: " + message.Command); } } }
internal void RaiseNewStopOrderEvent(StopOrder stopOrder) { NewStopOrder?.Invoke(stopOrder); }
private static void Events_OnStopOrder(StopOrder stopOrder) { Console.WriteLine("Events_OnStopOrder: " + stopOrder.ToJson()); }
public async Task<long> KillStopOrder(StopOrder stopOrder) { Transaction killStopOrderTransaction = new Transaction { ACTION = TransactionAction.KILL_STOP_ORDER, CLASSCODE = stopOrder.ClassCode, SECCODE = stopOrder.SecCode, STOP_ORDER_KEY = stopOrder.OrderNum.ToString() }; return await Quik.Trading.SendTransaction(killStopOrderTransaction); }
internal void RaiseNewStopOrderEvent(StopOrder stopOrder) { if (NewStopOrder != null) NewStopOrder(stopOrder); }
private void ProcessCallbackMessage(IMessage message) { if (message == null) { throw new ArgumentNullException("message"); } EventNames eventName; var parsed = Enum.TryParse(message.Command, true, out eventName); if (parsed) { switch (eventName) { case EventNames.OnAccountBalance: break; case EventNames.OnAccountPosition: break; case EventNames.OnAllTrade: Trace.Assert(message is Message <AllTrade>); var allTrade = ((Message <AllTrade>)message).Data; allTrade.LuaTimeStamp = message.CreatedTime; Events.OnAllTradeCall(allTrade); break; case EventNames.OnCleanUp: Trace.Assert(message is Message <string>); Events.OnCleanUpCall(); break; case EventNames.OnClose: Trace.Assert(message is Message <string>); Events.OnCloseCall(); break; case EventNames.OnConnected: Trace.Assert(message is Message <string>); Events.OnConnectedCall(); break; case EventNames.OnDepoLimit: break; case EventNames.OnDepoLimitDelete: break; case EventNames.OnDisconnected: Trace.Assert(message is Message <string>); Events.OnDisconnectedCall(); break; case EventNames.OnFirm: break; case EventNames.OnFuturesClientHolding: break; case EventNames.OnFuturesLimitChange: break; case EventNames.OnFuturesLimitDelete: break; case EventNames.OnInit: Trace.Assert(message is Message <string>); Events.OnInitCall(((Message <string>)message).Data, _callbackPort); break; case EventNames.OnMoneyLimit: break; case EventNames.OnMoneyLimitDelete: break; case EventNames.OnNegDeal: break; case EventNames.OnNegTrade: break; case EventNames.OnOrder: Trace.Assert(message is Message <Order>); var ord = ((Message <Order>)message).Data; ord.LuaTimeStamp = message.CreatedTime; Events.OnOrderCall(ord); break; case EventNames.OnParam: break; case EventNames.OnQuote: Trace.Assert(message is Message <OrderBook>); var ob = ((Message <OrderBook>)message).Data; ob.LuaTimeStamp = message.CreatedTime; Events.OnQuoteCall(ob); break; case EventNames.OnStop: Trace.Assert(message is Message <string>); Events.OnStopCall(int.Parse(((Message <string>)message).Data)); break; case EventNames.OnStopOrder: StopOrder stopOrder = (message as Message <StopOrder>).Data; StopOrders.RaiseNewStopOrderEvent(stopOrder); break; case EventNames.OnTrade: Trace.Assert(message is Message <Trade>); var trade = ((Message <Trade>)message).Data; trade.LuaTimeStamp = message.CreatedTime; Events.OnTradeCall(trade); break; case EventNames.OnTransReply: Trace.Assert(message is Message <TransactionReply>); var trReply = ((Message <TransactionReply>)message).Data; trReply.LuaTimeStamp = message.CreatedTime; Events.OnTransReplyCall(trReply); break; case EventNames.NewCandle: Candle candle = (message as Message <Candle>).Data; Candles.RaiseNewCandleEvent(candle); break; default: throw new ArgumentOutOfRangeException(); } } else { switch (message.Command) { // an error from an event not request (from req is caught is response loop) case "lua_error": Trace.Assert(message is Message <string>); Trace.TraceError(((Message <string>)message).Data); break; default: throw new InvalidOperationException("Unknown command in a message: " + message.Command); } } }