コード例 #1
0
ファイル: QuikTrader.cs プロジェクト: alexevil1979/alexevil
        // **********************************************************************
        // *                               Сделки                               *
        // **********************************************************************

        void TradeStatusCallback(
            int nMode,
            double trade_id,
            double order_id,
            string classCode,
            string secCode,
            double price,
            int quantity,
            double msum,
            int isSell,
            int tradeDescriptor)
        {
            string comment = Marshal.PtrToStringAnsi(Trans2Quik.TRADE_BROKERREF(tradeDescriptor));

            if ((comment != null && comment.EndsWith(cfg.FullProgName)) || cfg.u.AcceptAllTrades)
            {
                if (isSell == 0)
                {
                    if (lastBuyId >= trade_id)
                    {
                        return;
                    }
                    else
                    {
                        lastBuyId = trade_id;
                    }
                }
                else
                {
                    if (lastSellId >= trade_id)
                    {
                        return;
                    }
                    else
                    {
                        lastSellId = trade_id;
                    }

                    quantity = -quantity;
                }

                if (nMode == 0 && OwnTradeHandler != null)
                {
                    int date = Trans2Quik.TRADE_DATE(tradeDescriptor);
                    int time = Trans2Quik.TRADE_TIME(tradeDescriptor);

                    int year, month, day;
                    int hour, min, sec;

                    year  = date / 10000;
                    month = (day = date - year * 10000) / 100;
                    day  -= month * 100;

                    hour = time / 10000;
                    min  = (sec = time - hour * 10000) / 100;
                    sec -= min * 100;

                    OwnTradeHandler(new OwnTrade((long)order_id,
                                                 new DateTime(year, month, day, hour, min, sec),
                                                 Price.GetInt(price), quantity));
                }
            }
        }