Ejemplo n.º 1
0
 public override void OnReceiveBalance(string[] param)
 {
     if (param.Length == 0x13 && long.TryParse(param[7], out long active) &&
         double.TryParse(param[0xC].StartsWith("-") ? param[0xC].Substring(1) : param[0xC], out double offer) &&
         double.TryParse(param[0xD].StartsWith("-") ? param[0xD].Substring(1) : param[0xD], out double bid) &&
         double.TryParse(param[5].StartsWith("-") ? param[5].Substring(1) : param[5], out double unit) &&
         double.TryParse(param[0x10], out double transaction) && int.TryParse(param[4], out int amount) &&
         double.TryParse(param[3].StartsWith("-") ? param[3].Substring(1) : param[3], out double price))
     {
         var classification = param[9].Equals("1") ? -1 : 1;
         Current   = price;
         Quantity  = amount * classification;
         Purchase  = unit;
         Revenue   = (long)((price - unit) * classification * amount * transaction);
         Rate      = price / unit - 1;
         Bid       = bid;
         Offer     = offer;
         WaitOrder = true;
         SendBalance?.Invoke(this, new SendSecuritiesAPI((long)(active * transaction * MarginRate * classification * price)));
     }
     else if (long.TryParse(param[9], out long available) && int.TryParse(param[7], out int purchase) &&
              int.TryParse(param[5].StartsWith("-") ? param[5].Substring(1) : param[5], out int current) &&
              int.TryParse(param[6], out int quantity))
     {
         Current   = current;
         Quantity  = quantity;
         Purchase  = purchase;
         Revenue   = (current - purchase) * quantity;
         Rate      = current / (double)purchase - 1;
         WaitOrder = true;
         SendBalance?.Invoke(this, new SendSecuritiesAPI(available * current));
     }
     SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <string, string, int, dynamic, dynamic, long, double>(param[1].StartsWith("A") ? param[1].Substring(1) : param[1], param[param[1].Length == 8 ? 2 : 4], Quantity, Purchase, Current, Revenue, Rate)));
 }
Ejemplo n.º 2
0
        public override void OnReceiveEvent(string[] param)
        {
            if (int.TryParse(string.Concat(param[8], param[9]), out int volume))
            {
                SendConsecutive?.Invoke(this, new SendConsecutive(new Charts
                {
                    Date   = param[0],
                    Price  = param[4],
                    Volume = volume
                }));
            }
            if (double.TryParse(param[4], out double current))
            {
                Current = current;
                Revenue = (long)((current - (Purchase ?? 0D)) * Quantity * transactionMultiplier);
                Rate    = (Quantity > 0 ? current / (double)Purchase : Purchase / (double)current) - 1;

                if (OrderNumber.Count > 0 && strategics is TrendFollowingBasicFutures && OrderNumber.ContainsValue(Bid) == false && OrderNumber.ContainsValue(Offer) == false)
                {
                    foreach (var kv in OrderNumber)
                    {
                        if (kv.Value < Bid || kv.Value > Offer)
                        {
                            SendBalance?.Invoke(this, new SendSecuritiesAPI(new Catalog.XingAPI.Order
                            {
                                FnoIsuNo = Code,
                                OrgOrdNo = kv.Key,
                                OrdQty   = "1"
                            }));
                        }
                    }
                }
            }
            if (param[0].CompareTo(end) > 0 && uint.TryParse(param[0], out uint remain) && (RollOver == false || Temporary.RemainingDay.Contains(remain)))
            {
                var quantity = Math.Abs(Quantity);
                RollOver = Temporary.RemainingDay.Remove(remain);

                if (RollOver == false)
                {
                    RollOver = true;
                }

                while (quantity > 0)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Catalog.XingAPI.Order
                    {
                        FnoIsuNo         = Code,
                        BnsTpCode        = Quantity > 0 ? "1" : "2",
                        FnoOrdprcPtnCode = ((int)Catalog.XingAPI.FnoOrdprcPtnCode.시장가).ToString("D2"),
                        OrdPrc           = Purchase.ToString("F2"),
                        OrdQty           = "1"
                    }));
                    quantity--;
                }
            }
            SendStocks?.Invoke(this, new SendHoldingStocks(Code, Quantity, Purchase, Current, Revenue, Rate, Base, Secondary, AdjustTheColorAccordingToTheCurrentSituation(WaitOrder, OrderNumber.Count)));
        }
Ejemplo n.º 3
0
        internal void OnReceiveTrendsInPrices(SendConsecutive e, double gap, double peek)
        {
            switch (strategics)
            {
            case TrendsInValuation tv:
                var interval = e.Date.Length == 6 ? new DateTime(NextOrderTime.Year, NextOrderTime.Month, NextOrderTime.Day, int.TryParse(e.Date.Substring(0, 2), out int hour) ? hour : DateTime.Now.Hour, int.TryParse(e.Date.Substring(2, 2), out int minute) ? minute : DateTime.Now.Minute, int.TryParse(e.Date.Substring(4), out int second) ? second : DateTime.Now.Second) : DateTime.Now;

                if (tv.TradingAddtionalQuantity > 0 && Bid < peek * (1 - tv.AdditionalPosition) && gap > 0 && OrderNumber.ContainsValue(Bid) == false && WaitOrder && (tv.AddtionalInterval == 0 || tv.AddtionalInterval > 0 && interval.CompareTo(NextOrderTime) > 0))
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, tv.Code, tv.TradingAddtionalQuantity, Bid, string.Empty)));
                    WaitOrder = false;

                    if (tv.AddtionalInterval > 0)
                    {
                        NextOrderTime = MeasureTheDelayTime(tv.AddtionalInterval, interval);
                    }
                }
                else if (tv.TradingSubtractionalQuantity > 0 && Offer > peek * (1 + tv.SubtractionalPosition) && Offer > Purchase && gap < 0 && OrderNumber.ContainsValue(Offer) == false && WaitOrder && (tv.SubtractionalInterval == 0 || tv.SubtractionalInterval > 0 && interval.CompareTo(NextOrderTime) > 0))
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, tv.Code, tv.TradingSubtractionalQuantity, Offer, string.Empty)));
                    WaitOrder = false;

                    if (tv.SubtractionalInterval > 0)
                    {
                        NextOrderTime = MeasureTheDelayTime(tv.SubtractionalInterval, interval);
                    }
                }
                break;

            case TrendsInStockPrices ts:
                if (ts.Setting.Equals(Interface.Setting.Short) == false && Bid < peek * (1 - ts.AdditionalPurchase) && gap > 0 && OrderNumber.ContainsValue(Bid) == false && WaitOrder)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, ts.Code, ts.Quantity, Bid, string.Empty)));
                    WaitOrder = false;
                }
                else if (ts.Setting.Equals(Interface.Setting.Long) == false && Offer > peek * (1 + ts.RealizeProfit) && Offer > Purchase && gap < 0 && OrderNumber.ContainsValue(Offer) == false && WaitOrder)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, ts.Code, ts.Quantity, Offer, string.Empty)));
                    WaitOrder = false;
                }
                break;

            case TrendToCashflow tc:
                if (tc.TradingQuantity > 0 && Bid < peek * (1 - tc.PositionAddition) && gap > 0 && OrderNumber.ContainsValue(Bid) == false && WaitOrder)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, tc.Code, tc.TradingQuantity, Bid, string.Empty)));
                    WaitOrder = false;
                }
                else if (tc.TradingQuantity > 0 && Offer > peek * (1 + tc.PositionRevenue) && Offer > Purchase && gap < 0 && OrderNumber.ContainsValue(Offer) == false && WaitOrder)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, tc.Code, tc.TradingQuantity, Offer, string.Empty)));
                    WaitOrder = false;
                }
                break;
            }
            Base      = peek;
            Secondary = gap;
        }
Ejemplo n.º 4
0
 public override void OnReceiveBalance(string[] param)
 {
     if (long.TryParse(param[9], out long available) && int.TryParse(param[7], out int purchase) && int.TryParse(param[5].StartsWith("-") ? param[5].Substring(1) : param[5], out int current) && int.TryParse(param[6], out int quantity))
     {
         Current   = current;
         Quantity  = quantity;
         Purchase  = purchase;
         Revenue   = (current - purchase) * quantity;
         Rate      = current / (double)purchase - 1;
         WaitOrder = true;
         SendBalance?.Invoke(this, new SendSecuritiesAPI(available * current));
     }
     SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <string, string, int, dynamic, dynamic, long, double>(param[1].StartsWith("A") ? param[1].Substring(1) : param[1], param[4], Quantity, Purchase, Current, Revenue, Rate)));
 }
Ejemplo n.º 5
0
        public override void OnReceiveBalance(string[] param)
        {
            var cme = param.Length > 0x1C;

            if (param[cme ? 0x33 : 0xB].Length == 8 && int.TryParse(param[cme ? 0x53 : 0xE], out int quantity) && double.TryParse(param[cme ? 0x52 : 0xD], out double current) && int.TryParse(param[cme ? 0x2D : 9], out int number) && OrderNumber.Remove(number.ToString()))
            {
                var gb = param[cme ? 0x37 : 0x14];
                Current   = current;
                Purchase  = gb.Equals("2") && Quantity >= 0 ? (Purchase * Quantity + current * quantity) / (quantity + Quantity) : (gb.Equals("1") && Quantity <= 0 ? (current * quantity - Purchase * Quantity) / (quantity - Quantity) : Purchase);
                Quantity += gb.Equals("1") ? -quantity : quantity;
                Revenue   = (long)(current - Purchase) * Quantity * transactionMutiplier;
                Rate      = (Quantity > 0 ? current / (double)Purchase : Purchase / (double)current) - 1;
            }
            WaitOrder = true;
            SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <string, string, int, dynamic, dynamic, long, double>(param[cme ? 0x33 : 0xB], param[cme ? 0x34 : 0xB], Quantity, Purchase, Current, Revenue, Rate)));
        }
Ejemplo n.º 6
0
 internal void OnReceiveTrendsInPrices(SendConsecutive e, double gap, int minute)
 {
     switch (strategics)
     {
     case TrendFollowingBasicFutures tf:
         if (minute == 0x5A0)
         {
             if (WaitOrder && (e.Date.CompareTo(cme) > 0 || e.Date.CompareTo(eurex) < 0 || e.Date.CompareTo(start) > 0 && e.Date.CompareTo(end) < 0) &&
                 (gap > 0 ? tf.QuantityLong - Quantity > 0 : tf.QuantityShort + Quantity > 0) &&
                 (gap > 0 ? e.Volume > tf.ReactionLong : e.Volume < -tf.ReactionShort) &&
                 (gap > 0 ? e.Volume + Secondary > e.Volume : e.Volume + Secondary < e.Volume) && OrderNumber.Count == 0)
             {
                 SendBalance?.Invoke(this, new SendSecuritiesAPI(new Catalog.XingAPI.Order
                 {
                     FnoIsuNo  = Code,
                     BnsTpCode = gap > 0 ? "2" : "1",
                     FnoOrdprcPtnCode
                            = e.Date.CompareTo(start) > 0 && e.Date.CompareTo(end) < 0 ? ((int)Catalog.XingAPI.FnoOrdprcPtnCode.지정가).ToString("D2") : ((int)Catalog.XingAPI.ErxPrcCndiTpCode.지정가).ToString("D1"),
                     OrdPrc = (gap > 0 ? Offer : Bid).ToString("F2"),
                     OrdQty = "1"
                 }));
                 WaitOrder = false;
             }
             Base = gap;
         }
         else
         {
             if (WaitOrder && (e.Date.CompareTo(cme) > 0 || e.Date.CompareTo(eurex) < 0 || e.Date.CompareTo(start) > 0 && e.Date.CompareTo(end) < 0) &&
                 (tf.QuantityShort + Quantity < 0 && Base < 0 || Base > 0 && Quantity - tf.QuantityLong > 0) &&
                 Revenue / Math.Abs(Quantity) > 0x927C)
             {
                 SendBalance?.Invoke(this, new SendSecuritiesAPI(new Catalog.XingAPI.Order
                 {
                     FnoIsuNo  = Code,
                     BnsTpCode = Quantity > 0 ? "1" : "2",
                     FnoOrdprcPtnCode
                            = e.Date.CompareTo(start) > 0 && e.Date.CompareTo(end) < 0 ? ((int)Catalog.XingAPI.FnoOrdprcPtnCode.시장가).ToString("D2") : ((int)Catalog.XingAPI.ErxPrcCndiTpCode.시장가).ToString("D1"),
                     OrdPrc = (Quantity > 0 ? Bid : Offer).ToString("F2"),
                     OrdQty = "1"
                 }));
                 WaitOrder = false;
             }
             Secondary = gap;
         }
         break;
     }
 }
Ejemplo n.º 7
0
        public override void OnReceiveConclusion(string[] param)
        {
            if (param.Length == 0x2E && uint.TryParse(param[0xA], out uint order) && OrderNumber.Remove(order.ToString()) && param[0xD].Equals("2") && uint.TryParse(param[9], out uint number) && double.TryParse(param[0x10], out double price))
            {
                OrderNumber[number.ToString()] = price;
            }

            else if ((param[8].Equals(Enum.GetName(typeof(TR), TR.SONBT001)) || param[8].Equals(Enum.GetName(typeof(TR), TR.CONET801))) && double.TryParse(param[0x3C], out double nPrice))
            {
                OrderNumber[param[0x2D]] = nPrice;
                SendBalance?.Invoke(this, new SendSecuritiesAPI(param[0x67], param[0x6C]));
            }
            else if (uint.TryParse(param[0x2F], out uint oNum) && OrderNumber.Remove(oNum.ToString()) && param[0x38].Equals("1") && uint.TryParse(param[0x2D], out uint nNum) && double.TryParse(param[0x3C], out double oPrice))
            {
                OrderNumber[nNum.ToString()] = oPrice;
            }
        }
Ejemplo n.º 8
0
 internal void OnReceiveTrendsInPrices(double gap, double peek)
 {
     switch (strategics)
     {
     case TrendsInStockPrices ts:
         if (ts.Setting.Equals(Interface.Setting.Short) == false && Bid < peek * (1 - ts.AdditionalPurchase) && gap > 0 && OrderNumber.ContainsValue(Bid) == false && WaitOrder)
         {
             SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, ts.Code, ts.Quantity, Bid, string.Empty)));
             WaitOrder = false;
         }
         else if (ts.Setting.Equals(Interface.Setting.Long) == false && Offer > peek * (1 + ts.RealizeProfit) && Offer > Purchase && gap < 0 && OrderNumber.ContainsValue(Offer) == false && WaitOrder)
         {
             SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, ts.Code, ts.Quantity, Offer, string.Empty)));
             WaitOrder = false;
         }
         break;
     }
     Base      = peek;
     Secondary = gap;
 }
Ejemplo n.º 9
0
        private void OnReceiveChejanData(object sender, _DKHOpenAPIEvents_OnReceiveChejanDataEvent e)
        {
            sb = new StringBuilder(256);

            foreach (int fid in e.sGubun.Equals("0") ? catalog[5] : catalog[6])
            {
                sb.Append(axAPI.GetChejanData(fid)).Append(',');
            }

            if (e.sGubun.Equals("0"))
            {
                SendConclusion?.Invoke(this, new ConclusionEvent(sb));

                return;
            }
            if (e.sGubun.Equals("4"))
            {
                SendBalance?.Invoke(this, new BalanceEvent(sb));
            }
        }
Ejemplo n.º 10
0
        public override void OnReceiveBalance(string[] param)
        {
            var cme  = param.Length > 0x1C;
            var span = DateTime.Now;

            if (param[cme ? 0x33 : 0xB].Length == 8 && int.TryParse(param[cme ? 0x53 : 0xE], out int quantity) && double.TryParse(param[cme ? 0x52 : 0xD], out double current) && int.TryParse(param[cme ? 0x2D : 9], out int number) && OrderNumber.Remove(number.ToString()))
            {
                var gb = param[cme ? 0x37 : 0x14];
                Current   = current;
                Purchase  = gb.Equals("2") && Quantity >= 0 ? ((Purchase ?? 0D) * Quantity + current * quantity) / (quantity + Quantity) : (gb.Equals("1") && Quantity <= 0 ? (current * quantity - (Purchase ?? 0D) * Quantity) / (quantity - Quantity) : (Purchase ?? 0D));
                Quantity += gb.Equals("1") ? -quantity : quantity;
                Revenue   = (long)(current - Purchase) * Quantity * transactionMultiplier;
                Rate      = (Quantity > 0 ? current / (double)Purchase : Purchase / (double)current) - 1;
            }
            SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <string, string, int, dynamic, dynamic, long, double>(param[cme ? 0x33 : 0xB], param[cme ? 0x34 : 0xB], Quantity, Purchase, Current, Revenue, Rate)));

            if (Span == null || Span.AddMilliseconds(0x3ED).CompareTo(span) < 0)
            {
                SendBalance?.Invoke(this, new SendSecuritiesAPI(true));
                Span = span;
            }
        }
Ejemplo n.º 11
0
        public override void OnReceiveConclusion(string[] param)
        {
            switch (param[param.Length - 1])
            {
            case "EU0":
            case "EU1":
                switch (param[37])
                {
                case "HO01":
                    Console.WriteLine(param[37] + "_" + param.Length);
                    break;

                case "CH01":
                    Console.WriteLine(param[37] + "_" + param.Length);
                    break;
                }
                break;
            }
            if (param.Length == 0x2E && uint.TryParse(param[0xA], out uint order) && OrderNumber.Remove(order.ToString()) &&
                param[0xD].Equals("2") && uint.TryParse(param[9], out uint number) && double.TryParse(param[0x10], out double price))
            {
                OrderNumber[number.ToString()] = price;
            }

            else if ((param[8].Equals(Enum.GetName(typeof(TR), TR.SONBT001)) || param[8].Equals(Enum.GetName(typeof(TR), TR.CONET801))) &&
                     double.TryParse(param[0x3C], out double nPrice))
            {
                OrderNumber[param[0x2D]] = nPrice;
                SendBalance?.Invoke(this, new SendSecuritiesAPI(param[0x67], param[0x6C]));
                WaitOrder = true;
            }
            else if (param.Length > 0x38 && uint.TryParse(param[0x2F], out uint oNum) && OrderNumber.Remove(oNum.ToString()) &&
                     param[0x38].Equals("1") && uint.TryParse(param[0x2D], out uint nNum) && double.TryParse(param[0x3C], out double oPrice))
            {
                OrderNumber[nNum.ToString()] = oPrice;
            }
        }
Ejemplo n.º 12
0
        internal void OnReceiveTrendsInPrices(SendConsecutive e, double gap, double peek)
        {
            DateTime interval;

            switch (strategics)
            {
            case SatisfyConditionsAccordingToTrends sc:
                interval
                    = e.Date.Length == 6 ? new DateTime(NextOrderTime.Year, NextOrderTime.Month, NextOrderTime.Day, int.TryParse(e.Date.Substring(0, 2), out int cHour) ? cHour : DateTime.Now.Hour, int.TryParse(e.Date.Substring(2, 2), out int cMinute) ? cMinute : DateTime.Now.Minute, int.TryParse(e.Date.Substring(4), out int cSecond) ? cSecond : DateTime.Now.Second) : DateTime.Now;

                if (sc.TradingBuyQuantity > 0 && Bid < peek * (1 - sc.TradingBuyRate) && gap > 0 && OrderNumber.ContainsValue(Bid) == false &&
                    WaitOrder && (sc.TradingBuyInterval == 0 || sc.TradingBuyInterval > 0 && interval.CompareTo(NextOrderTime) > 0))
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, sc.Code, sc.TradingBuyQuantity, Bid, string.Empty)));
                    WaitOrder = false;

                    if (sc.TradingBuyInterval > 0)
                    {
                        NextOrderTime = MeasureTheDelayTime(sc.TradingBuyInterval * (Purchase > 0 && Bid > 0 ? Purchase / (double)Bid : 1), interval);
                    }
                }
                else if (Quantity > 0)
                {
                    if (sc.TradingSellQuantity > 0 && Offer > peek * (1 + sc.TradingSellRate) && Offer > Purchase + tax * Offer &&
                        gap < 0 && OrderNumber.ContainsValue(Offer) == false && WaitOrder &&
                        (sc.TradingSellInterval == 0 || sc.TradingSellInterval > 0 && interval.CompareTo(NextOrderTime) > 0))
                    {
                        SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, sc.Code, sc.TradingSellQuantity, Offer, string.Empty)));
                        WaitOrder = false;

                        if (sc.TradingSellInterval > 0)
                        {
                            NextOrderTime = MeasureTheDelayTime(sc.TradingSellInterval * (Purchase > 0 && Offer > 0 ? Offer / (double)Purchase : 1), interval);
                        }
                    }
                    else if (SellPrice > 0 && sc.ReservationSellQuantity > 0 && Offer > SellPrice && OrderNumber.ContainsValue(Offer) == false && WaitOrder)
                    {
                        for (int i = 0; i < sc.ReservationSellUnit; i++)
                        {
                            SellPrice += GetQuoteUnit(SellPrice, Market);
                        }

                        SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, sc.Code, sc.ReservationSellQuantity, Offer, string.Empty)));
                        WaitOrder = false;
                    }
                    else if (BuyPrice > 0 && sc.ReservationBuyQuantity > 0 && Bid < BuyPrice && OrderNumber.ContainsValue(Bid) == false && WaitOrder)
                    {
                        for (int i = 0; i < sc.ReservationBuyUnit; i++)
                        {
                            BuyPrice -= GetQuoteUnit(BuyPrice, Market);
                        }

                        SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, sc.Code, sc.ReservationBuyQuantity, Bid, string.Empty)));
                        WaitOrder = false;
                    }
                    else if (SellPrice == 0 && Purchase > 0)
                    {
                        SellPrice = GetStartingPrice((int)((1 + sc.ReservationSellRate) * Purchase), Market);
                    }

                    else if (BuyPrice == 0 && Purchase > 0)
                    {
                        BuyPrice = GetStartingPrice((int)(Purchase * (1 - sc.ReservationBuyRate)), Market);
                    }
                }
                break;

            case TrendsInValuation tv:
                interval
                    = e.Date.Length == 6 ? new DateTime(NextOrderTime.Year, NextOrderTime.Month, NextOrderTime.Day, int.TryParse(e.Date.Substring(0, 2), out int hour) ? hour : DateTime.Now.Hour, int.TryParse(e.Date.Substring(2, 2), out int minute) ? minute : DateTime.Now.Minute, int.TryParse(e.Date.Substring(4), out int second) ? second : DateTime.Now.Second) : DateTime.Now;

                if (tv.TradingAddtionalQuantity > 0 && Bid < peek * (1 - tv.AdditionalPosition) && gap > 0 && OrderNumber.ContainsValue(Bid) == false &&
                    WaitOrder && (tv.AddtionalInterval == 0 || tv.AddtionalInterval > 0 && interval.CompareTo(NextOrderTime) > 0))
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, tv.Code, tv.TradingAddtionalQuantity, Bid, string.Empty)));
                    WaitOrder = false;

                    if (tv.AddtionalInterval > 0)
                    {
                        NextOrderTime = MeasureTheDelayTime(tv.AddtionalInterval, interval);
                    }
                }
                else if (tv.TradingSubtractionalQuantity > 0 && Offer > peek * (1 + tv.SubtractionalPosition) && Offer > Purchase &&
                         gap < 0 && OrderNumber.ContainsValue(Offer) == false && WaitOrder &&
                         (tv.SubtractionalInterval == 0 || tv.SubtractionalInterval > 0 && interval.CompareTo(NextOrderTime) > 0))
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, tv.Code, tv.TradingSubtractionalQuantity, Offer, string.Empty)));
                    WaitOrder = false;

                    if (tv.SubtractionalInterval > 0)
                    {
                        NextOrderTime = MeasureTheDelayTime(tv.SubtractionalInterval, interval);
                    }
                }
                break;

            case TrendsInStockPrices ts:
                if (ts.Setting.Equals(Interface.Setting.Short) == false && Bid < peek * (1 - ts.AdditionalPurchase) && gap > 0 &&
                    OrderNumber.ContainsValue(Bid) == false && WaitOrder)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, ts.Code, ts.Quantity, Bid, string.Empty)));
                    WaitOrder = false;
                }
                else if (ts.Setting.Equals(Interface.Setting.Long) == false && Offer > peek * (1 + ts.RealizeProfit) && Offer > Purchase &&
                         gap < 0 && OrderNumber.ContainsValue(Offer) == false && WaitOrder)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, ts.Code, ts.Quantity, Offer, string.Empty)));
                    WaitOrder = false;
                }
                break;

            case TrendToCashflow tc:
                if (tc.TradingQuantity > 0 && Bid < peek * (1 - tc.PositionAddition) && gap > 0 && OrderNumber.ContainsValue(Bid) == false && WaitOrder)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매수, tc.Code, tc.TradingQuantity, Bid, string.Empty)));
                    WaitOrder = false;
                }
                else if (tc.TradingQuantity > 0 && Offer > peek * (1 + tc.PositionRevenue) && Offer > Purchase && gap < 0 &&
                         OrderNumber.ContainsValue(Offer) == false && WaitOrder)
                {
                    SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <int, string, int, int, string>((int)OpenOrderType.신규매도, tc.Code, tc.TradingQuantity, Offer, string.Empty)));
                    WaitOrder = false;
                }
                break;

            case TrendFollowingBasicFutures tf:
                if (0x5A0 == (int)peek)
                {
                    if (WaitOrder && e.Date.CompareTo(start) > 0 && e.Date.CompareTo(end) < 0 &&
                        (gap > 0 ? tf.QuantityLong - Quantity > 0 : tf.QuantityShort + Quantity > 0) &&
                        (gap > 0 ? e.Volume > tf.ReactionLong : e.Volume < -tf.ReactionShort) &&
                        (gap > 0 ? e.Volume + Secondary > e.Volume : e.Volume + Secondary < e.Volume) && OrderNumber.Count == 0)
                    {
                        SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <string, int, string, string, int, string, string>(Code, 1, gap > 0 ? "2" : "1", ((int)Catalog.OpenAPI.OrderType.지정가).ToString(), 1, (gap > 0 ? Offer : Bid).ToString("F2"), string.Empty)));
                        WaitOrder = false;
                    }
                    Base = gap;
                }
                else
                {
                    if (WaitOrder && e.Date.CompareTo(start) > 0 && e.Date.CompareTo(end) < 0 &&
                        (tf.QuantityShort + Quantity < 0 && Base < 0 || Base > 0 && Quantity - tf.QuantityLong > 0) &&
                        Revenue / Math.Abs(Quantity) > 0x927C)
                    {
                        SendBalance?.Invoke(this, new SendSecuritiesAPI(new Tuple <string, int, string, string, int, string, string>(Code, 1, Quantity > 0 ? "1" : "2", ((int)Catalog.OpenAPI.OrderType.시장가).ToString(), 1, string.Empty, string.Empty)));
                        WaitOrder = false;
                    }
                    Secondary = gap;
                }
                return;
            }
            Base      = peek;
            Secondary = gap;
        }
Ejemplo n.º 13
0
        private void OnReceiveData(string szTrCode)
        {
            Sb = new StringBuilder(128);

            foreach (var block in Array.Find(catalog, o => o.ToString().Contains(szTrCode.Substring(1))).GetOutBlock(Query.GetResData()))
            {
                for (int i = 0; i < Query.GetBlockCount(block.Name); i++)
                {
                    Sb.Append(Query.GetFieldData(block.Name, block.Field, i)).Append(';');
                }
            }

            switch (szTrCode)
            {
            case "t9943":
                foreach (var str in Sb.ToString().Split(';'))
                {
                    if (str.Substring(0, 3).Equals("101"))
                    {
                        new Secret(str);
                        SendCount?.Invoke(this, new NotifyIconText(Query.GetAccountName(Secret.Account), Query.GetAcctDetailName(Secret.Account), Query.GetAcctNickname(Secret.Account), str));
                        SellOrder = new Dictionary <string, double>();
                        BuyOrder  = new Dictionary <string, double>();
                        Trend     = new Dictionary <string, string>();
                        Real      = new Dictionary <string, XARealClass>();
                        Total     = new Queue <string>();

                        if (Query.LoadFromResFile(string.Concat(Path, "t2105.res")))
                        {
                            foreach (var block in new T2105().GetInBlock(Query.GetResData()))
                            {
                                Query.SetFieldData(block.Name, block.Field, block.Occurs, block.Property);
                            }

                            Delay.delay = 1000 / Query.GetTRCountPerSec("t2105");
                            request.RequestTrData(new Task(() => SendErrorMessage(Query.Request(false))));
                        }
                        if (TimerBox.Show(Secret.OnReceiveData, Secret.GoblinBat, MessageBoxButtons.OK, MessageBoxIcon.Information, 13579).Equals(DialogResult.OK))
                        {
                            foreach (var kv in real)
                            {
                                SetAPI(kv);
                            }

                            LookUpTheBalance();
                            SendCount?.Invoke(this, new NotifyIconText(7));
                        }
                        return;
                    }
                }
                return;

            case "t2105":
                LookUpTheDeposit();
                var quotes = Sb.ToString().Split(';');
                Name = quotes[0];
                SendQuotes?.Invoke(this, new Quotes(new string[]
                {
                    quotes[32],
                    quotes[26],
                    quotes[20],
                    quotes[14],
                    quotes[8],
                    quotes[9],
                    quotes[15],
                    quotes[21],
                    quotes[27],
                    quotes[33]
                }, new string[]
                {
                    quotes[34],
                    quotes[28],
                    quotes[22],
                    quotes[16],
                    quotes[10],
                    quotes[11],
                    quotes[17],
                    quotes[23],
                    quotes[29],
                    quotes[35]
                }, new string[]
                {
                    quotes[36],
                    quotes[30],
                    quotes[24],
                    quotes[18],
                    quotes[12],
                    quotes[13],
                    quotes[19],
                    quotes[25],
                    quotes[31],
                    quotes[37]
                }, quotes[42], SellOrder, BuyOrder, string.Empty));
                return;

            case "CFOBQ10500":
                var temp = Sb.ToString().Split(';');
                SendDeposit?.Invoke(this, new Deposit(new string[]
                {
                    temp[5],
                    temp[6],
                    temp[7],
                    temp[14],
                    temp[15],
                    string.Empty,
                    temp[16],
                    temp[17],
                    string.Empty,
                    temp[18],
                    temp[19],
                    string.Empty,
                    temp[23],
                    temp[20],
                    temp[21],
                    temp[11],
                    temp[12],
                    temp[13],
                    temp[8],
                    temp[9],
                    temp[24],
                    string.Empty,
                    temp[10],
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty,
                    string.Empty
                }));
                return;

            case "t0441":
                if (Query.IsNext)
                {
                    Console.WriteLine(Secret.Account + "\t" + Sb);
                    var bal = Sb.ToString().Split(';');
                    SendBalance?.Invoke(this, new Balance(new string[]
                    {
                        bal[10],
                        Name,
                        bal[11],
                        bal[12],
                        bal[14],
                        bal[19],
                        bal[21],
                        bal[13],
                        bal[15],
                        bal[20]
                    }));
                }
                else
                {
                    var cts = Sb.ToString().Split(';');

                    if (cts[1].Equals(string.Empty) && cts[2].Equals(string.Empty))
                    {
                        return;
                    }

                    new Secret(cts[1], cts[2]);

                    foreach (var block in new T0441().GetInBlock(Query.GetResData()))
                    {
                        Query.SetFieldData(block.Name, block.Field, block.Occurs, block.Property);
                    }

                    Delay.delay = 1000 / Query.GetTRCountPerSec("t0441");
                    request.RequestTrData(new Task(() => SendErrorMessage(Query.Request(true))));
                }
                return;
            }
        }
Ejemplo n.º 14
0
        public void StartProgress(double commission)
        {
            switch (strategics)
            {
            case ScenarioAccordingToTrend st:
                Commission = commission > 0 ? commission : 1.5e-4;

                if (StartProgress(strategics.Code as string) > 0)
                {
                    var price    = SendMessage.Price;
                    var estimate = EstimatedPrice.Where(o => o.Key.ToString(format.Substring(0, 6)).CompareTo(SendMessage.Date) > 0);
                    var find     = FindTheNearestQuarter(SendMessage.Date);
                    var key      = string.Concat("ST.", st.Calendar.Substring(0, 4), "15.", st.Trend, '.', st.CheckSales.ToString().Substring(0, 1), '.', st.Sales * 0x64, '.', st.CheckOperatingProfit.ToString().Substring(0, 1), '.', st.OperatingProfit * 0x64, '.', st.CheckNetIncome.ToString().Substring(0, 1), '.', st.NetIncome * 0x64);

                    if (client.PutContext(new Catalog.Request.Consensus
                    {
                        Code = st.Code,
                        Strategics = key,
                        Date = SendMessage.Date,
                        FirstQuarter = (estimate.Last(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[0])).Value - price) / price,
                        SecondQuarter = (estimate.Last(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[1])).Value - price) / price,
                        ThirdQuarter = (estimate.Last(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[2])).Value - price) / price,
                        Quarter = (estimate.Last(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[find.Length - 2])).Value - price) / price,
                        TheNextYear = (estimate.LastOrDefault(o => o.Key.ToString(format.Substring(0, 6)).Equals(find[find.Length - 1])).Value - price) / price,
                        TheYearAfterNext = (estimate.Last().Value - price) / price
                    }).Result > 0)
                    {
                        consecutive.Dispose();
                    }

                    SendMessage = new Statistics
                    {
                        Base       = SendMessage.Base,
                        Cumulative = SendMessage.Cumulative,
                        Date       = SendMessage.Date,
                        Statistic  = SendMessage.Statistic,
                        Price      = (int)estimate.Max(o => o.Value),
                        Key        = key
                    };
                    SendStocks?.Invoke(this, new SendHoldingStocks(EstimatedPrice, SendMessage.Date));
                }
                break;

            case TrendsInStockPrices ts:
                Commission = commission > 0 ? commission : 1.5e-4;

                if (StartProgress(strategics.Code as string) > 0)
                {
                    SendMessage = new Statistics
                    {
                        Base       = SendMessage.Base,
                        Cumulative = SendMessage.Cumulative,
                        Date       = SendMessage.Date,
                        Statistic  = SendMessage.Statistic,
                        Key        = string.Concat("TS.", ts.Short, '.', ts.Long, '.', ts.Trend, '.', (int)(ts.RealizeProfit * 0x2710), '.', (int)(ts.AdditionalPurchase * 0x2710), '.', ts.QuoteUnit, '.', (char)ts.LongShort, '.', (char)ts.TrendType, '.', (char)ts.Setting)
                    };
                    consecutive.Dispose();
                }
                break;

            case TrendFollowingBasicFutures _:
                Commission = commission > 0 ? commission : 3e-5;
                IsDebugging();

                if (StartProgress(strategics.Code as string) > 0)
                {
                    foreach (var con in Consecutive)
                    {
                        con.Dispose();
                    }
                }

                break;

            default:
                return;
            }
            SendBalance?.Invoke(this, new SendSecuritiesAPI(strategics, SendMessage));
        }
Ejemplo n.º 15
0
        void OnReceiveTrData(object sender, _DKHOpenAPIEvents_OnReceiveTrDataEvent e)
        {
            int index = Array.FindIndex(catalogTR, o => o.ToString().Contains(e.sTrCode.Substring(1)));

            if (index < 1)
            {
                new ExceptionMessage(e.sTrCode);

                return;
            }
            if (index < 5 && index > 0)
            {
                var temp = API.GetCommDataEx(e.sTrCode, e.sRQName);

                if (temp != null)
                {
                    string[,] ts = new string[((object[, ])temp).GetUpperBound(0) + 1, ((object[, ])temp).GetUpperBound(1) + 1];
                    int x, y, lx = ((object[, ])temp).GetUpperBound(0), ly = ((object[, ])temp).GetUpperBound(1);

                    for (x = 0; x <= lx; x++)
                    {
                        var sb = new StringBuilder(64);

                        for (y = 0; y <= ly; y++)
                        {
                            ts[x, y] = (string)((object[, ])temp)[x, y];

                            if (ts[x, y].Length > 13 && e.sRQName.Split(';')[1].Equals(ts[x, y].Substring(2)))
                            {
                                sb          = Exists;
                                e.sPrevNext = "0";

                                break;
                            }
                            sb.Append(ts[x, y]).Append(';');
                        }
                        if (Exists.Equals(sb) == false)
                        {
                            SendMemorize?.Invoke(this, new Memorize(sb));

                            continue;
                        }
                        if (Exists.Equals(sb))
                        {
                            break;
                        }
                    }
                    if (DeadLine && (e.sRQName.Split(';')[1].Length == 8 || e.sRQName.Split(';')[1].Equals("DoesNotExist")) && e.sPrevNext.Equals("2"))
                    {
                        request.RequestTrData(new Task(() => InputValueRqData(new Opt10081
                        {
                            Value    = e.sRQName.Split(';')[0],
                            RQName   = e.sRQName,
                            PrevNext = 2
                        })));
                        return;
                    }
                    if (DeadLine == false && e.sRQName.Split(';')[0].Length == 6 && e.sPrevNext.Equals("2"))
                    {
                        request.RequestTrData(new Task(() => InputValueRqData(new Opt10079
                        {
                            Value    = e.sRQName.Split(';')[0],
                            RQName   = e.sRQName,
                            PrevNext = 2
                        })));
                        return;
                    }
                    if (DeadLine == false && e.sRQName.Substring(5, 3).Equals("000") && e.sPrevNext.Equals("2"))
                    {
                        request.RequestTrData(new Task(() => InputValueRqData(new Opt50028
                        {
                            Value    = e.sRQName.Substring(0, 8),
                            RQName   = e.sRQName,
                            PrevNext = 2
                        })));
                        return;
                    }
                    if (DeadLine == false && e.sRQName.Split(';')[0].Length == 8 && e.sPrevNext.Equals("2"))
                    {
                        request.RequestTrData(new Task(() => InputValueRqData(new Opt50066
                        {
                            Value    = e.sRQName.Substring(0, 8),
                            RQName   = e.sRQName,
                            PrevNext = 2
                        })));
                        return;
                    }
                    if (e.sPrevNext.Equals("0"))
                    {
                        SendMemorize?.Invoke(this, new Memorize(e.sPrevNext, e.sRQName.Split(';')[0]));
                    }
                }
                SetScreenNumber(9000, 9031);
                SendMemorize?.Invoke(this, new Memorize("Clear"));
                Request(GetRandomCode(new Random().Next(0, CodeList.Count)));

                return;
            }
            var str = new StringBuilder(512);
            int i, cnt = API.GetRepeatCnt(e.sTrCode, e.sRQName);

            for (i = 0; i < (cnt > 0 ? cnt : cnt + 1); i++)
            {
                foreach (string item in Array.Find(catalogTR, o => o.ToString().Contains(e.sTrCode.Substring(1))))
                {
                    str.Append(API.GetCommData(e.sTrCode, e.sRQName, i, item).Trim()).Append(';');
                }

                if (cnt > 0)
                {
                    str.Append("*");
                }
            }
            switch (Array.FindIndex(catalogTR, o => o.ToString().Contains(e.sTrCode.Substring(1))))
            {
            case 5:
                FixUp(str.ToString().Split(';'), e.sRQName);
                return;

            case 6:
                foreach (string info in str.ToString().Split('*'))
                {
                    FixUp(info.Split(';'));
                }

                return;

            case 7:
            case 8:
                if (str.Length > 1 && e.sRQName.Equals("DoNotRollOver") == false)
                {
                    if (e.sScrNo.Substring(0, 1).Equals("1"))
                    {
                        SellOrder[str.ToString().Split(';')[0]] = double.Parse(e.sRQName.Split(';')[0]);
                    }

                    else if (e.sScrNo.Substring(0, 1).Equals("2"))
                    {
                        BuyOrder[str.ToString().Split(';')[0]] = double.Parse(e.sRQName.Split(';')[0]);
                    }
                }
                SendState?.Invoke(this, new State(OnReceiveBalance, SellOrder.Count, Quantity, BuyOrder.Count, ScreenNumber));
                return;

            case 9:
                SendState?.Invoke(this, new State(OnReceiveBalance, SellOrder.Count, Quantity, BuyOrder.Count, ScreenNumber));
                return;

            case 10:
                SendDeposit?.Invoke(this, new Deposit(str.ToString().Split(';')));
                break;

            case 11:
                new Task(() =>
                {
                    var temporary = str.ToString().Split('*');

                    for (i = 0; i < temporary.Length; i++)
                    {
                        if (temporary[i].Length > 0 && temporary[i].Substring(0, 8).Equals(API.GetFutureCodeByIndex(0)))
                        {
                            var quantity = temporary[i].Split(';');
                            Quantity     = quantity[2].Equals("1") ? -int.Parse(quantity[3]) : int.Parse(quantity[3]);
                            AvgPurchase  = (double.Parse(quantity[4]) / 100).ToString("F2");
                        }
                    }
                    SendBalance?.Invoke(this, new Balance(temporary));
                }).Start();
                break;
            }
        }