Ejemplo n.º 1
0
        public FiveLevelQuote[] GetQuote(string[] securityCodes, out string[] errors)
        {
            TabulateData[] data;
            bool[]         succeeds = GetQuote(securityCodes, out data, out errors);


            FiveLevelQuote[] quotes = new FiveLevelQuote[securityCodes.Length];

            for (int i = 0; i < securityCodes.Length; ++i)
            {
                if (!succeeds[i])
                {
                    quotes[i] = null;
                }
                else
                {
                    var results = FiveLevelQuote.ExtractFrom(data[i]);

                    if (results == null || results.Count() == 0)
                    {
                        errors[i] = "GetQuote succeeded, but not result";
                        quotes[i] = null;
                    }
                    else
                    {
                        quotes[i] = results.First();
                    }
                }
            }

            return(quotes);
        }
Ejemplo n.º 2
0
        public static IEnumerable <FiveLevelQuote> ExtractFrom(TabulateData data, DateTime timestamp)
        {
            if (columnIndices == null)
            {
                columnIndices = columns.Select(c => data.GetColumnIndex(c)).ToArray();
            }

            var subData = data.GetSubColumns(columnIndices);

            foreach (var row in subData.Rows)
            {
                FiveLevelQuote quote = new FiveLevelQuote(timestamp);

                int index = 0;
                quote.SecurityCode        = row[index++];
                quote.SecurityName        = row[index++];
                quote.YesterdayClosePrice = TradingHelper.SafeParseFloat(row[index++]);
                quote.TodayOpenPrice      = TradingHelper.SafeParseFloat(row[index++]);
                quote.CurrentPrice        = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices           = new float[5];
                quote.BuyVolumesInHand    = new int[5];
                quote.SellPrices          = new float[5];
                quote.SellVolumesInHand   = new int[5];

                quote.BuyPrices[0] = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices[1] = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices[2] = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices[3] = TradingHelper.SafeParseFloat(row[index++]);
                quote.BuyPrices[4] = TradingHelper.SafeParseFloat(row[index++]);

                quote.BuyVolumesInHand[0] = TradingHelper.SafeParseInt(row[index++]);
                quote.BuyVolumesInHand[1] = TradingHelper.SafeParseInt(row[index++]);
                quote.BuyVolumesInHand[2] = TradingHelper.SafeParseInt(row[index++]);
                quote.BuyVolumesInHand[3] = TradingHelper.SafeParseInt(row[index++]);
                quote.BuyVolumesInHand[4] = TradingHelper.SafeParseInt(row[index++]);

                quote.SellPrices[0] = TradingHelper.SafeParseFloat(row[index++]);
                quote.SellPrices[1] = TradingHelper.SafeParseFloat(row[index++]);
                quote.SellPrices[2] = TradingHelper.SafeParseFloat(row[index++]);
                quote.SellPrices[3] = TradingHelper.SafeParseFloat(row[index++]);
                quote.SellPrices[4] = TradingHelper.SafeParseFloat(row[index++]);

                quote.SellVolumesInHand[0] = TradingHelper.SafeParseInt(row[index++]);
                quote.SellVolumesInHand[1] = TradingHelper.SafeParseInt(row[index++]);
                quote.SellVolumesInHand[2] = TradingHelper.SafeParseInt(row[index++]);
                quote.SellVolumesInHand[3] = TradingHelper.SafeParseInt(row[index++]);
                quote.SellVolumesInHand[4] = TradingHelper.SafeParseInt(row[index++]);

                yield return(quote);
            }
        }
        private bool ShouldStoploss(FiveLevelQuote quote, float maxBuyPrice, float minBuyPrice, int totalBuyVolume, StoplossOrder order)
        {
            bool shouldStoploss = false;

            if (order.StoplossPrice < minBuyPrice)
            {
                if (totalBuyVolume > order.ExistingVolume)
                {
                }
                else
                {
                    // no solution yet, need to predicate volume.
                    // TODO: predicate volume
                }
            }
            else
            {
                if (order.StoplossPrice >= maxBuyPrice)
                {
                    // need to stop loss immediately.
                    shouldStoploss = true;
                }
                else
                {
                    // order stop loss price is between minBuyPrice and maxBuyPrice
                    // we count the buy volume above stop loss price.
                    int aboveStoplossBuyVolume =
                        ChinaStockHelper.ConvertHandToVolume(
                            Enumerable
                            .Range(0, quote.BuyPrices.Length)
                            .Where(index => quote.BuyPrices[index] >= order.StoplossPrice)
                            .Sum(index => quote.BuyVolumesInHand[index]));

                    if (aboveStoplossBuyVolume <= order.ExistingVolume * 5)
                    {
                        shouldStoploss = true;
                    }
                    else
                    {
                        // there is enough buy volume now, so don't be rush.
                    }
                }
            }

            return(shouldStoploss);
        }
Ejemplo n.º 4
0
        public FiveLevelQuote GetQuote(string securityCode, out string error)
        {
            TabulateData data;

            if (!GetQuote(securityCode, out data, out error))
            {
                return(null);
            }

            var results = FiveLevelQuote.ExtractFrom(data);

            if (results == null || results.Count() == 0)
            {
                error = "GetQuote succeeded, but not result";
                return(null);
            }

            return(results.First());
        }