Example #1
0
        public static void EchoTransaction() {
            var _df = new DebugFunctions(Quik.DefaultPort);

            var sw = new Stopwatch();
            Console.WriteLine("Started");
            for (int round = 0; round < 10; round++) {
                sw.Reset();
                sw.Start();

                var count = 10000;
                var t = new Transaction();

                var array = new Task<Transaction>[count];
                for (int i = 0; i < array.Length; i++) {
                    array[i] = _df.Echo(t);
                }
                for (int i = 0; i < array.Length; i++) {
                    var res = array[i].Result;
                    array[i] = null;
                }

                sw.Stop();
                Console.WriteLine("MultiPing takes msecs: " + sw.ElapsedMilliseconds);
            }
            Console.WriteLine("Finished");
            Console.ReadKey();
        }
        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);
        }
 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);
 }
Example #4
0
        /// <summary>
        /// Send a single transaction to Quik server
        /// </summary>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public async Task<long> SendTransaction(Transaction transaction) {
            Trace.Assert(!transaction.TRANS_ID.HasValue, "TRANS_ID should be assigned automatically in SendTransaction functions");

            transaction.TRANS_ID = QuikService.GetNewUniqueId();

            //    Console.WriteLine("Trans Id from function = {0}", transaction.TRANS_ID);

            Trace.Assert(transaction.CLIENT_CODE == null,
                "Currently we use Comment to store correlation id for a transaction, " +
                "its reply, trades and orders. Support for comments will be added later if needed");
            // TODO Comments are useful to kill all orders with a single KILL_ALL_ORDERS
            // But see e.g. this http://www.quik.ru/forum/import/27073/27076/

            transaction.CLIENT_CODE = QuikService.PrependWithSessionId(transaction.TRANS_ID.Value);

            try {
                var response = await QuikService.Send<Message<bool>>(
                (new Message<Transaction>(transaction, "sendTransaction")));
                Trace.Assert(response.Data);

                // store transaction
                QuikService.Storage.Set(transaction.CLIENT_CODE, transaction);


                return transaction.TRANS_ID.Value;
            } catch (TransactionException e) {
                transaction.ErrorMessage = e.Message;
                // dirty hack: if transaction was sent we return its id,
                // else we return negative id so the caller will know that
                // the transaction was not sent
                return (-transaction.TRANS_ID.Value);
            }

        }