示例#1
0
        private void CancelTrailing()
        {
            if (Item == null)
            {
                return;
            }
            CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! CancelBeforeBuyOrder cancel code : " + Item.itemCode);
            CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! CancelBeforeBuyOrder cancel orderNum : " + Item.buyOrderNum);
            CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! CancelBeforeBuyOrder cancel quantity : " + (Item.buyQnt - Item.curQnt).ToString());
            //form1.CancelBuyOrder(Item.itemCode, Item.buyOrderNum);
            if (tradingStrategy != null)
            {
                List <TradingItem> tradeItemListAll = tradingStrategy.tradingItemList.FindAll(o => (o.itemCode == Item.itemCode));

                foreach (TradingItem tradeItem in tradeItemListAll)
                {
                    if (tradeItem.state == TRADING_ITEM_STATE.AUTO_TRADING_STATE_SEARCH_AND_CATCH)
                    {
                        tradeItem.SetBuyCancelComplete();
                        PopMartinGailItem(0);
                        return;
                    }
                }
            }
        }
示例#2
0
        private void OnReceiveConditionResult(object sender, OnReceiveStrateyStateResultArgs e)
        {
            Item = new MartinGailItem();

            Item.itemState = e.State;
            Item.itemCode  = e.ItemCode;
            startOrderTime = DateTime.Now;
            CoreEngine.GetInstance().SendLogMessage("!!!!! 마틴게일 아이템 :" + e.State.ToString());
        }
示例#3
0
        void Update()
        {
            if (Item != null)
            {
                if (Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_SEARCH_AND_CATCH)
                {
                    if ((DateTime.Now - startOrderTime).TotalSeconds > Wait_And_CancelValue)
                    {
                        CoreEngine.GetInstance().SendLogMessage("트레일링 취소");
                        CancelTrailing();
                    }
                }
                if (Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_BUY_NOT_COMPLETE ||
                    Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_BUY_NOT_COMPLETE_OUTCOUNT)
                {
                    //Console.WriteLine((DateTime.Now - startOrderTime).ToString());
                    //Console.WriteLine(tradingStrategyGridView.GetProfitRate((double)Item.curPrice, (double)Item.buyPrice).ToString());

                    if (Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_BUY_NOT_COMPLETE_OUTCOUNT)
                    {
                        if (using_Outstand_UpAndCancel && Form1.GetProfitRate((double)Item.curPrice, (double)Item.buyPrice) > OutStand_And_CancelValue)
                        {
                            CoreEngine.GetInstance().SendLogWarningMessage("!!!!!!!!!!!!using_Outstand_UpAndCancel!!!!!!!!!!!!!!");
                            CancelBuyOrderAll();
                            SellAllClear(); //청산
                        }
                    }
                    else
                    {
                        if (using_Up_And_Cancel && Form1.GetProfitRate((double)Item.curPrice, (double)Item.buyPrice) > Up_And_CancelValue)
                        {
                            CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!!using_Up_And_Cancel Pop MartinGail Item!!!!!!!!!!!!!!");
                            CancelBuyOrderAll();
                        }
                    }

                    if (using_WaitAndCancel && (DateTime.Now - startOrderTime).TotalSeconds > Wait_And_CancelValue)
                    {
                        CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!!using_WaitAndCancel Pop MartinGail Item!!!!!!!!!!!!!!");
                        CancelBuyOrderAll();
                    }
                }

                if (Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_BUY_BEFORE_ORDER)
                {
                    //Console.WriteLine("주문접수성공 대기 : " + (DateTime.Now - startOrderTime).ToString());
                    if ((DateTime.Now - startOrderTime).TotalSeconds > Wait_And_CancelValue)
                    {
                        CoreEngine.GetInstance().SendLogMessage("주문접수성공 실패");
                        CancelBeforeBuyOrder();
                    }
                }
            }
        }
示例#4
0
 private void SellAllClear()
 {
     if (Item == null)
     {
         return;
     }
     CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! SellAllClear code : " + Item.itemCode);
     CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! SellAllClear orderNum : " + Item.buyOrderNum);
     CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! SellAllClear quantity : " + Item.curQnt.ToString());
     form1.SellAllClear(Item.itemCode, (int)Item.curQnt, form1.ReceiveSellAllClear);
 }
示例#5
0
 private void CancelBuyOrderAll()
 {
     if (Item == null)
     {
         return;
     }
     CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! cancel code : " + Item.itemCode);
     CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! cancel orderNum : " + Item.buyOrderNum);
     CoreEngine.GetInstance().SendLogMessage("!!!!!!!!!!!! cancel quantity : " + (Item.buyQnt - Item.curQnt).ToString());
     form1.CancelBuyOrder(Item.itemCode, Item.buyOrderNum);
 }
示例#6
0
        public void PopMartinGailItem(long profit)
        {
            CoreEngine.GetInstance().SendLogMessage("PopMartinGailItem");
            Item = null;
            if (martinGailStack.Count == 0)
            {
                CoreEngine.GetInstance().SendLogWarningMessage("!!!!!!!!!!empty stack!!!!!!");
                RestartSameStep();
                return;
            }
            MartinGailItem itempop = martinGailStack.Pop();

            TodayAllTry++;

            if (profit > 0)
            {
                if (itempop != null)
                {
                    itempop.martinState = MARTIN_RESULT.WIN;
                    winCount++;
                    Restart();
                }
            }
            else if (profit == 0)
            {
                drawCount++;
                if (itempop != null)
                {
                    itempop.martinState = MARTIN_RESULT.DRAW;
                    RestartSameStep();
                }
            }
            else
            {
                loseCount++;
                if (itempop != null)
                {
                    itempop.martinState = MARTIN_RESULT.LOSE;

                    if (itempop.step >= MARTIN_MAX_STEP)
                    {
                        Restart();
                    }
                    else
                    {
                        GoNext();
                    }
                }
            }
        }
示例#7
0
 public void AddPrice(double _price)
 {
     if (curSaveIndex >= saveCount)
     {
         CoreEngine.GetInstance().SendLogErrorMessage("저장갯수초과");
         return;
     }
     sumPrice += _price;
     curSaveIndex++;
     if (lowest == 0 || lowest > _price)
     {
         lowest = _price;
     }
     average = CalAverage();
 }
示例#8
0
        private void OnReceiveSellOrderTryResult(object sender, OnReceiveStrateyStateResultArgs e)
        {
            if (Item != null)
            {
                CoreEngine.GetInstance().SendLogMessage("!!!!! 마틴게일 아이템 :" + e.State.ToString());

                Item.itemState = e.State;
                Item.sellQnt   = e.Qnt;
                if (Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_SELL_BEFORE_ORDER ||
                    Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_SELL_NOT_COMPLETE)
                {
                    //주문접수 시도 완료
                    startOrderTime = DateTime.Now;
                }
            }
        }
示例#9
0
        public void PushMartinGailItem(string itemCode)
        {
            CoreEngine.GetInstance().SendLogMessage("Push Martin GailItem Try");
            step++;

            if (Item != null && Item.itemCode == itemCode)
            {
                CoreEngine.GetInstance().SendLogWarningMessage("Push Martin GailItem");
                Item.martinState = MARTIN_RESULT.HAVE_ITEM;
                Item.step        = step;
                Item.TodayIndex  = todayAllItems.Count;

                todayAllCode.Add(itemCode);
                martinGailStack.Push(Item);
                todayAllItems.Add(Item);
            }
        }
示例#10
0
        public void OnReceiveSellChejanResult(object sender, OnReceiveStrateyStateResultArgs e)
        {
            if (Item != null)
            {
                CoreEngine.GetInstance().SendLogMessage("!!!!! 마틴게일 아이템 :" + e.State.ToString());

                Item.itemState = e.State;


                if (Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_SELL_NOT_COMPLETE_OUTCOUNT ||
                    Item.itemState == TRADING_ITEM_STATE.AUTO_TRADING_STATE_SELL_COMPLETE)
                {
                    //일부 매수, 매수완료 일때
                    startOrderTime = DateTime.Now;
                }
            }
        }
示例#11
0
文件: Form2.cs 项目: segara/singijeon
        public Form2(AxKHOpenAPILib.AxKHOpenAPI _axKHOpenAPI1)
        {
            InitializeComponent();
            LogListBox.DrawItem        += LogListBox_DrawItem;
            warningLogListBox.DrawItem += WarningLogListBox_DrawItem;
            coreEngine = CoreEngine.GetInstance();
            coreEngine.OnReceivedLogMessage        += OnReceiveLogMessage;
            coreEngine.OnReceivedLogWarningMessage += OnReceiveLogWarningMessage;
            coreEngine.OnReceivedLogErrorMessage   += OnReceiveLogErrorMessage;
            axKHOpenAPI1 = _axKHOpenAPI1;
            axKHOpenAPI1.OnReceiveTrData += AxKHOpenAPI_OnReceiveTrData;

            this.FormClosing += Form_FormClosing;

            logMessage = coreEngine.logMessage;

            setting.Load();
            profit_label.Text = string.Format("{0:n0}", curProfit);
            Start();
        }
示例#12
0
        private double CalAverage()
        {
            double returnValue = 0;

            if (curSaveIndex > 0)
            {
                returnValue = (double)sumPrice / (double)curSaveIndex;
            }

            if (returnValue == 0)
            {
                CoreEngine.GetInstance().SendLogErrorMessage("평균값 0");
            }

            if (sumPrice == 0)
            {
                CoreEngine.GetInstance().SendLogErrorMessage("저장가격 " + sumPrice);
            }


            return(returnValue);
        }
示例#13
0
        private void API_OnReceiveChejanData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveChejanDataEvent e)
        {
            CoreEngine.GetInstance().SendLogMessage("API_OnReceiveChejanData");
            if (e.sGubun.Equals(ConstName.RECEIVE_CHEJAN_DATA_SUBMIT_OR_CONCLUSION))
            {
                CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_SUBMIT_OR_CONCLUSION");
                string orderState  = axKHOpenAPI1.GetChejanData(913).Trim();
                string outstanding = axKHOpenAPI1.GetChejanData(902).Trim();
                string orderType   = axKHOpenAPI1.GetChejanData(905).Replace("+", "").Replace("-", "").Trim();
                string ordernum    = axKHOpenAPI1.GetChejanData(9203).Trim();
                string itemCode    = axKHOpenAPI1.GetChejanData(9001).Replace("A", "");

                string conclusionPrice    = axKHOpenAPI1.GetChejanData(910).Trim();
                string conclusionQuantity = axKHOpenAPI1.GetChejanData(911).Trim();

                if (orderState.Equals(ConstName.RECEIVE_CHEJAN_DATA_SUBMIT))
                {
                    CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_SUBMIT");
                    if (orderType.Equals(ConstName.RECEIVE_CHEJAN_DATA_BUY))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_BUY : " + ordernum);
                        CoreEngine.GetInstance().SendLogWarningMessage("conclusionQuantity : " + conclusionQuantity);
                        if (tradingStrategy == null)
                        {
                            return;
                        }

                        List <TradingItem> tradeItemArray = tradingStrategy.tradingItemList.FindAll(o => o.itemCode.Equals(itemCode));
                        if (tradeItemArray.Count > 0)
                        {
                            foreach (var item in tradeItemArray)
                            {
                                if (Item != null && Item.itemCode == itemCode && string.IsNullOrEmpty(item.buyOrderNum) == false)
                                {
                                    Item.buyOrderNum = item.buyOrderNum;
                                }
                            }
                        }
                    }
                    else if (orderType.Equals(ConstName.RECEIVE_CHEJAN_DATA_SELL))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_SELL");
                    }
                    else if (orderType.Equals(ConstName.RECEIVE_CHEJAN_CANCEL_BUY_ORDER))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_CANCEL_BUY_ORDER");
                    }
                    else if (orderType.Equals(ConstName.RECEIVE_CHEJAN_CANCEL_SELL_ORDER))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_CANCEL_SELL_ORDER");
                    }
                }
                else if (orderState.Equals(ConstName.RECEIVE_CHEJAN_DATA_CONCLUSION))
                {
                    CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_CONCLUSION");
                    if (orderType.Contains(ConstName.RECEIVE_CHEJAN_DATA_BUY))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_BUY");
                        if (tradingStrategy == null)
                        {
                            return;
                        }
                        CoreEngine.GetInstance().SendLogWarningMessage("RECEIVE_CHEJAN_DATA_BUY ORDER NUM : " + ordernum);
                        CoreEngine.GetInstance().SendLogWarningMessage("conclusionQuantity : " + conclusionQuantity);

                        TradingItem tradeItem = tradingStrategy.tradingItemList.Find(o => o.buyOrderNum.Equals(ordernum));

                        if (tradeItem != null && string.IsNullOrEmpty(conclusionQuantity) == false)
                        {
                            if (Item != null)
                            {
                                CoreEngine.GetInstance().SendLogMessage(Item.curQnt + "/" + Item.buyQnt);

                                Item.curQnt      = long.Parse(conclusionQuantity);
                                Item.buyPrice    = tradeItem.buyingPrice;
                                Item.buyOrderNum = tradeItem.buyOrderNum;
                                if (Item.curQnt == Item.buyQnt)
                                {
                                    PushMartinGailItem(itemCode);
                                }
                            }
                        }
                        else
                        {
                            CoreEngine.GetInstance().SendLogWarningMessage("tradeItem is null ");
                        }
                    }
                    else if (orderType.Contains(ConstName.RECEIVE_CHEJAN_DATA_SELL))
                    {
                        if (tradingStrategy == null)
                        {
                            return;
                        }

                        TradingItem tradeItem = tradingStrategy.tradingItemList.Find(o => o.sellOrderNum.Equals(ordernum));
                        if (tradeItem != null && string.IsNullOrEmpty(outstanding) == false && string.IsNullOrEmpty(conclusionPrice) == false)
                        {
                            long buyingPrice = tradeItem.buyingPrice;
                            long sellPrice   = long.Parse(conclusionPrice.Replace("+", ""));

                            if (long.Parse(outstanding) == 0)
                            {
                                CoreEngine.GetInstance().SendLogMessage("Outstanding 0 : Profit : " + (sellPrice - buyingPrice) * tradeItem.buyingQnt);
                                TodayAllProfitAmount += (sellPrice - buyingPrice) * tradeItem.buyingQnt;
                                PopMartinGailItem((sellPrice - buyingPrice));
                            }
                            else
                            {
                                if (Item != null)
                                {
                                    Item.curQnt       = long.Parse(outstanding);
                                    Item.sellOrderNum = tradeItem.sellOrderNum;
                                }
                            }
                        }
                    }
                }
                else if (orderState.Equals(ConstName.RECEIVE_CHEJAN_DATA_OK))
                {
                    CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_OK");
                    if (orderType.Contains(ConstName.RECEIVE_CHEJAN_CANCEL_BUY_ORDER))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_CANCEL_BUY_ORDER");
                        if (int.Parse(outstanding) == 0)
                        {
                            if (Item != null)
                            {
                                PopMartinGailItem(0);
                            }
                        }
                    }
                    else if (orderType.Contains(ConstName.RECEIVE_CHEJAN_CANCEL_SELL_ORDER))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_CANCEL_SELL_ORDER");
                        if (int.Parse(outstanding) == 0)
                        {
                            if (Item != null)
                            {
                                PopMartinGailItem(0);
                            }
                        }
                    }
                }
            }
            else if (e.sGubun.Equals(ConstName.RECEIVE_CHEJAN_DATA_BALANCE))
            {
            }
        }
示例#14
0
        private void API_OnReceiveChejanData(object sender, AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveChejanDataEvent e)
        {
            CoreEngine.GetInstance().SendLogMessage("API_OnReceiveChejanData");
            if (e.sGubun.Equals(ConstName.RECEIVE_CHEJAN_DATA_SUBMIT_OR_CONCLUSION))
            {
                CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_SUBMIT_OR_CONCLUSION");
                string orderState    = axKHOpenAPI1.GetChejanData(913).Trim();
                string orderQuantity = axKHOpenAPI1.GetChejanData(900).Trim();
                string outstanding   = axKHOpenAPI1.GetChejanData(902).Trim();
                string orderType     = axKHOpenAPI1.GetChejanData(905).Replace("+", "").Replace("-", "").Trim();
                string ordernum      = axKHOpenAPI1.GetChejanData(9203).Trim();
                string itemCode      = axKHOpenAPI1.GetChejanData(9001).Replace("A", "");

                string conclusionPrice    = axKHOpenAPI1.GetChejanData(910).Trim();
                string conclusionQuantity = axKHOpenAPI1.GetChejanData(911).Trim();

                if (orderState.Equals(ConstName.RECEIVE_CHEJAN_DATA_SUBMIT))
                {
                    CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_SUBMIT");
                    if (orderType.Equals(ConstName.RECEIVE_CHEJAN_DATA_BUY))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_BUY : " + ordernum);
                        CoreEngine.GetInstance().SendLogWarningMessage("conclusionQuantity : " + conclusionQuantity);
                    }
                    else if (orderType.Equals(ConstName.RECEIVE_CHEJAN_DATA_SELL))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_SELL");
                    }
                    else if (orderType.Equals(ConstName.RECEIVE_CHEJAN_CANCEL_BUY_ORDER))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_CANCEL_BUY_ORDER");
                    }
                    else if (orderType.Equals(ConstName.RECEIVE_CHEJAN_CANCEL_SELL_ORDER))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_CANCEL_SELL_ORDER");
                    }
                }
                else if (orderState.Equals(ConstName.RECEIVE_CHEJAN_DATA_CONCLUSION))
                {
                    CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_CONCLUSION");
                    if (orderType.Contains(ConstName.RECEIVE_CHEJAN_DATA_BUY))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_BUY");

                        CoreEngine.GetInstance().SendLogWarningMessage("RECEIVE_CHEJAN_DATA_BUY ORDER NUM : " + ordernum);
                        CoreEngine.GetInstance().SendLogWarningMessage("conclusionQuantity : " + conclusionQuantity);
                    }
                    else if (orderType.Contains(ConstName.RECEIVE_CHEJAN_DATA_SELL))
                    {
                    }
                }
                else if (orderState.Equals(ConstName.RECEIVE_CHEJAN_DATA_OK))
                {
                    CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_DATA_OK");
                    if (orderType.Contains(ConstName.RECEIVE_CHEJAN_CANCEL_BUY_ORDER))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_CANCEL_BUY_ORDER");
                        if (int.Parse(outstanding) == 0)
                        {
                        }
                    }
                    else if (orderType.Contains(ConstName.RECEIVE_CHEJAN_CANCEL_SELL_ORDER))
                    {
                        CoreEngine.GetInstance().SendLogMessage("RECEIVE_CHEJAN_CANCEL_SELL_ORDER");
                        if (int.Parse(outstanding) == 0)
                        {
                        }
                    }
                }
            }
            else if (e.sGubun.Equals(ConstName.RECEIVE_CHEJAN_DATA_BALANCE))
            {
            }
        }