Ejemplo n.º 1
0
        private void UpdateBalances()
        {
            OpenApi.UpdateBalances(GetAccount(), delegate(_DKHOpenAPIEvents_OnReceiveTrDataEvent e)
            {
                string 예수금     = OpenApi.GetTrNum(e, "예수금");
                string D2추정예수금 = OpenApi.GetTrNum(e, "D+2추정예수금");
                string 가잔고평가액  = OpenApi.GetTrNum(e, "유가잔고평가액");
                string 예탁자산평가액 = OpenApi.GetTrNum(e, "예탁자산평가액");
                string 총매입금액   = OpenApi.GetTrNum(e, "총매입금액");

                var row = dataGridView_Balance.Rows[0];
                row.SetValues(예수금, D2추정예수금, 가잔고평가액, 예탁자산평가액, 총매입금액);


                int count = OpenApi.GetRepeatCnt(e);
                dataGridView_Stocks.RowCount = count;

                for (int i = 0; i < count; ++i)
                {
                    string 종목명  = OpenApi.GetTrData(e, "종목명", i);
                    string 보유수량 = OpenApi.GetTrNum(e, "보유수량", i);
                    string 평균단가 = OpenApi.GetTrNum(e, "평균단가", i);
                    string 현재가  = OpenApi.GetTrNum(e, "현재가", i);
                    string 평가금액 = OpenApi.GetTrNum(e, "평가금액", i);
                    string 손익금액 = OpenApi.GetTrNum(e, "손익금액", i);

                    row = dataGridView_Stocks.Rows[i];
                    row.SetValues(종목명, 보유수량, 평균단가, 현재가, 평가금액, 손익금액);
                }
            });
        }
Ejemplo n.º 2
0
        private void OnBalance()
        {
            _wait = true;

            OpenApi.UpdateBalances(_account, delegate(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
            {
                int count = OpenApi.GetRepeatCnt(e);
                for (int i = 0; i < count; ++i)
                {
                    string 종목명  = OpenApi.GetTrData(e, "종목명", i);
                    string 보유수량 = OpenApi.GetTrData(e, "보유수량", i);
                    foreach (var stock in _stockInfos)
                    {
                        if (stock.Stock.ToString() == 종목명)
                        {
                            int quantity;
                            if (int.TryParse(보유수량, out quantity))
                            {
                                stock.Quantity = quantity;
                            }
                            else
                            {
                                // something wrong;
                                Error = "보유수량 오류: " + 보유수량;
                                return;
                            }
                            break;
                        }
                    }
                }

                _wait = false;
                MoveState(EPhase.Price);
            });
        }
Ejemplo n.º 3
0
        private void OnOrderConfirm()
        {
            _wait = true;

            OpenApi.SetInputValue("계좌번호", _account);
            OpenApi.SetInputValue("전체종목구분", "0");
            OpenApi.SetInputValue("매매구분", "0");
            OpenApi.SetInputValue("체결구분", "1");
            OpenApi.CommRqData("실시간미체결요청", "opt10075", delegate(_DKHOpenAPIEvents_OnReceiveTrDataEvent e)
            {
                int count      = OpenApi.GetRepeatCnt(e);
                bool hasRemain = false;
                for (int i = 0; i < count; ++i)
                {
                    var name   = OpenApi.GetTrData(e, "종목명", i);
                    var remain = OpenApi.GetTrData(e, "미체결수량", i).ToInt();
                    if (remain > 0)
                    {
                        hasRemain = true;
                        break;
                    }
                }

                _wait = false;
                MoveState(hasRemain ? EPhase.Begin : EPhase.Balance);
            });
        }
Ejemplo n.º 4
0
        private void PriceCallback(AxKHOpenAPILib._DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            bool continued = true;

            int count = OpenApi.GetRepeatCnt(e);

            for (int i = 0; i < count; ++i)
            {
                string date       = OpenApi.GetTrData(e, IsDaily() ? "일자" : "체결시간", i);
                string startPrice = OpenApi.GetTrData(e, "시가", i);
                string highPrice  = OpenApi.GetTrData(e, "고가", i);
                string lowPrice   = OpenApi.GetTrData(e, "저가", i);
                string price      = OpenApi.GetTrData(e, "현재가", i);

                var stock = new StockPrice();

                if (IsDaily())
                {
                    DateTime.TryParseExact(date, "yyyyMMdd", CultureInfo.CurrentCulture, DateTimeStyles.None, out stock.Time);
                }
                else
                {
                    DateTime.TryParseExact(date, "yyyyMMddHHmmss", CultureInfo.CurrentCulture, DateTimeStyles.None, out stock.Time);
                }

                long.TryParse(startPrice, out stock.StartPrice);
                stock.StartPrice = Math.Abs(stock.StartPrice);

                long.TryParse(highPrice, out stock.HighPrice);
                stock.HighPrice = Math.Abs(stock.HighPrice);

                long.TryParse(lowPrice, out stock.LowPrice);
                stock.LowPrice = Math.Abs(stock.LowPrice);

                long.TryParse(price, out stock.Price);
                stock.Price = Math.Abs(stock.Price);

                if (stock.Time < _begin)
                {
                    continued = false;
                    break;
                }

                var nextEnd = _end.AddDays(1);
                if (stock.Time >= nextEnd)
                {
                    continue;
                }

                Items.Add(stock);

                if (_progress != null)
                {
                    _progress.Report(Items.Count);
                }
            }

            int seq;

            int.TryParse(e.sPrevNext, out seq);
            if (seq != 0 && continued)
            {
                Thread.Sleep(300);
                Request(_code, _begin, _end, this, _interval, _progress, seq);
            }
            else
            {
                Items.Reverse();
                _source.SetResult(this);
            }
        }