Пример #1
0
        // 일반 주문
        public void axKHOpenAPI_OnReceiveTrData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent apiEvent)
        {
            try {
                string key = apiEvent.sRQName + apiEvent.sScrNo;

                StockStatement statement = this.getStockStatement(key);
                if (statement != null)
                {
                    statement.receive(sender, apiEvent);
                }
                else
                {
                    TradingStatement stat = this.getTradingStatement(apiEvent.sScrNo);
                    if (stat != null)
                    {
                        stat.receive(sender, apiEvent);
                    }
                    else
                    {
                        Logger.getInstance.print(Log.StockAPI콜백, "[이 주문표 데이터가 삭제되었음. {0}", key);
                    }
                }
            }
            catch (AccessViolationException execption) {
                Logger.getInstance.print(Log.에러, "[주문 콜백 에러] {0}\n{1}\n{2}", execption.Message, execption.StackTrace, execption.InnerException);
            }
            this.runNextOrderFlag();
        }
Пример #2
0
        private TradingStatement popTradingStatement(string key)
        {
            lock (tradingPoolLock_) {
                TradingStatement statement = null;

                if (tradingReceivePool_.TryGetValue(key, out statement))
                {
                    tradingReceivePool_.Remove(key);
                    return(statement);
                }
            }
            return(null);
        }
Пример #3
0
        private void processStockOrder()
        {
            if (!this.runLoop())
            {
                return;
            }
            long now = DateTime.Now.Ticks;

            if (tickCount_ + (TimeSpan.TicksPerSecond * 3) < now)
            {
                tickCount_        = now;
                runNextOrderFlag_ = true;       // 3초이내 응답이 없으면 강제로 flag 켜준다.
            }

            // 다음 요청이 올때까지 hold (COM 모듈 내부가 꼬이는듯 ㅡㅡ..)
            if (!runNextOrderFlag_)
            {
                return;
            }

            StockStatement statement = null;

            if (statmentOrderPool_.TryDequeue(out statement))
            {
                statement.request();

                //이걸 recv 쪽에 받아놓고 있다가 실제 삭제는 recv
                if ((statement.GetType() != typeof(BuyStock)) &&
                    (statement.GetType() != typeof(SellStock)))
                {
                    this.addStatmentReceive(statement);
                }
                else
                {
                    TradingStatement tradingStat = (TradingStatement)statement;
                    this.addTradingReceive(tradingStat);
                }

                runNextOrderFlag_ = false;
            }
            // 키움증권 제한 1초에 5번만 요청 가능
            Thread.Sleep(5 / 1000);
        }
Пример #4
0
 private void addTradingReceive(TradingStatement statement)
 {
     lock (tradingPoolLock_) {
         tradingReceivePool_[statement.getKey()] = statement;
     }
 }