Beispiel #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();
        }
Beispiel #2
0
        private void processOrderCleanup()
        {
            // 주식 명령을 내린뒤, receive를 여러번 받을 수 있음.
            // 그래서 지연 삭제를 구현함.
            long now  = DateTime.Now.Ticks;
            long turn = TimeSpan.TicksPerSecond * 60;

            lock (receivePoolLock_) {
                ArrayList deleteOrder = new ArrayList();

                foreach (KeyValuePair <string, StockStatement> data in statmentReceivePool_)
                {
                    StockStatement stat = data.Value;
                    if (stat.orderTick_ + turn < now)
                    {
                        deleteOrder.Add(data.Key);
                    }
                }

                foreach (string deleteKey in deleteOrder)
                {
                    orderCount_--;
                    statmentReceivePool_.Remove(deleteKey);
                }
            }
        }
Beispiel #3
0
        private StockStatement popStockStatement(string key)
        {
            lock (receivePoolLock_) {
                StockStatement statement = null;

                if (statmentReceivePool_.TryGetValue(key, out statement))
                {
                    statmentReceivePool_.Remove(key);
                    return(statement);
                }
            }
            return(null);
        }
Beispiel #4
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);
        }
Beispiel #5
0
 private void addStatmentReceive(StockStatement statement)
 {
     lock (receivePoolLock_) {
         statmentReceivePool_[statement.getKey()] = statement;
     }
 }
Beispiel #6
0
 //---------------------------------------------------------------------
 // 주식 주문을 쌓아 두는 곳
 public void addOrder(StockStatement statement)
 {
     statmentOrderPool_.Enqueue(statement);
 }