Ejemplo n.º 1
0
        /// <summary> 매수 후 종목 </summary>
        private void CheckSellProcessByRealData(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveRealDataEvent e, string code, int price)
        {
            if (_processErrorFlag)
            {
                return;
            }

            if (_boughtDataDict.ContainsKey(code))
            {
                if (_boughtDataDict[code].IsSell(price) && IsDelay() == false)
                {
                    if (_boughtDataDict[code].processCount > 1)
                    {
                        //익절이라면 최종 목표가로
                        TODAY_LIST_BUY_PRICE[code] = _boughtDataDict[code].gainPrice;
                    }
                    else
                    {
                        ////손절이라면 첫 목표가로
                        //TODAY_LIST_BUY_PRICE[code] = _boughtDataDict[code].boughtPrice;
                        //손절이라면 제거
                        TODAY_LIST_BUY_PRICE.Remove(code);
                        TODAY_LIST_FIRST_PRICE.Remove(code);
                        axKHOpenAPI2.SetRealRemove(REAL_DATA_NO, code);
                    }
                    //매도 주문
                    //axKHOpenAPI2.SendOrder(ORDER_NAME, ORDER_NO, MY_ACCOUNT, 2, code, _boughtDataDict[code].boughtCount, 0, "03", string.Empty);

                    float  gapMoney = (price - _boughtDataDict[code].boughtPrice) * _boughtDataDict[code].boughtCount;
                    string priceLog = string.Format("Sell -- Bought : {1}, Now : {0}, ProcessCount : {2}, Gap : {3}, Margine : {4}", price, _boughtDataDict[code].boughtPrice, _boughtDataDict[code].processCount, price - _boughtDataDict[code].boughtPrice, gapMoney);
                    if (gapMoney > 0)
                    {
                        _logManager.AddGainMoney(gapMoney);
                    }
                    else
                    {
                        _logManager.AddLossMoney(Math.Abs(gapMoney));
                    }

                    Console.WriteLine();
                    Console.WriteLine(priceLog);
                    Console.WriteLine();
                    _logManager.AddLog(code, priceLog);


                    _boughtDataDict.Remove(code);
                    ++_tickProcessCount;
                }
            }
            else
            {
                string log = string.Format("Error On CheckSellProcessByRealData.\nCode : {0}", code);
                Console.WriteLine(log);
                _processErrorFlag = true;
            }
        }