Exemplo n.º 1
0
 public object this[int index]
 {
     get
     {
         if (m_isHpData)
         {
             if (index == 0)
             {
                 if (m_values[0] is byte[])
                 {
                     m_values[0] = HpData.DeserializeHp((byte[])m_values[0]);
                 }
                 return(m_values[0]);
             }
             else if (index == 1)
             {
                 if (m_values[1] is byte[])
                 {
                     m_values[1] = HpData.DeserializeHpTimes((byte[])m_values[1]);
                 }
                 return(m_values[1]);
             }
             else
             {
                 throw new AssertException("hp data has only 2 data");
             }
         }
         else
         {
             return(m_values[index]);
         }
     }
 }
Exemplo n.º 2
0
        public void UpdateUnclosedDeals(DateTime nowDate)
        {
            Dictionary <DateTime, System.Data.DataRow> dictHp = new Dictionary <DateTime, System.Data.DataRow>();

            foreach (var kvp in m_classifierInfos)
            {
                foreach (var i in kvp.Value.Deals.Deals)
                {
                    if (i.CloseTime.HasValue)
                    {
                        continue;
                    }

                    if (!dictHp.ContainsKey(i.OpenTime))
                    {
                        var sql = string.Format("SELECT * FROM {0}_HP WHERE TIME = {1}", this.CandidateParameter.MainSymbol, WekaUtils.GetTimeFromDate(i.OpenTime));
                        var dt  = Feng.Data.DbHelper.Instance.ExecuteDataTable(sql);
                        if (dt.Rows.Count > 0)
                        {
                            dictHp[i.OpenTime] = dt.Rows[0];
                        }
                    }
                    if (!dictHp.ContainsKey(i.OpenTime))
                    {
                        continue;
                    }
                    var row = dictHp[i.OpenTime];

                    int tpMinDelta = TestParameters.GetTpSlMinDelta(this.CandidateParameter.MainSymbol);
                    int slMinDelta = TestParameters.GetTpSlMinDelta(this.CandidateParameter.MainSymbol);

                    int d = i.DealType == 'B' ? 0 : 1;
                    sbyte?[, ,] hps    = HpData.DeserializeHp((byte[])row["hp"]);
                    long?[, ,] hpsTime = HpData.DeserializeHpTimes((byte[])row["hp_date"]);
                    var hp = hps[d, kvp.Value.Tp / tpMinDelta - 1, kvp.Value.Sl / slMinDelta - 1];
                    if (hp.HasValue &&
                        hp.Value != -1)
                    {
                        i.CloseTime = WekaUtils.GetDateFromTime(hpsTime[d, kvp.Value.Tp / tpMinDelta - 1, kvp.Value.Sl / slMinDelta - 1].Value);
                        i.Cost      = hp.Value == 1 ? -kvp.Value.Tp : kvp.Value.Sl;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private bool?Do(DateTime openDate, double openPrice, out DateTime?closeDate, int dealType)
        {
            closeDate = DateTime.MinValue;
            var dt = Feng.Data.DbHelper.Instance.ExecuteDataTable(string.Format("SELECT * FROM {0}_HP WHERE Time = {1}", m_symbol, WekaUtils.GetTimeFromDate(openDate)));

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            sbyte?[, ,] hp    = HpData.DeserializeHp((byte[])dt.Rows[0]["hp"]);
            long?[, ,] hpTime = HpData.DeserializeHpTimes((byte[])dt.Rows[0]["hp_date"]);

            int ix = (int)m_tp / TestParameters.GetTpSlMinDelta(m_symbol) - 1;
            int iy = (int)m_sl / TestParameters.GetTpSlMinDelta(m_symbol) - 1;

            if (hp[dealType, ix, iy].HasValue)
            {
                closeDate = WekaUtils.GetDateFromTime(hpTime[dealType, ix, iy].Value);
                return(hp[dealType, ix, iy].Value == 1);
            }
            return(null);
        }
Exemplo n.º 4
0
        public Tuple <int[, , , ], long[, , ]> GetHpData(DateTime date)
        {
            int n = m_buffer.Count - 5 * 15 * 20000;

            if (n > 0)
            {
                List <long> delete = new List <long>();
                foreach (var kvp in m_buffer)
                {
                    delete.Add(kvp.Key);
                    if (delete.Count >= n)
                    {
                        break;
                    }
                }
                foreach (var i in delete)
                {
                    m_buffer.Remove(i);
                }
            }

            Tuple <int[, , , ], long[, , ]> ret = null;
            long time = WekaUtils.GetTimeFromDate(date);

            if (!m_buffer.ContainsKey(time))
            {
                var sql = string.Format("SELECT * FROM {0}_HP WHERE TIME = {1}", m_symbol, time);
                var dt  = Feng.Data.DbHelper.Instance.ExecuteDataTable(sql);
                if (dt.Rows.Count > 0)
                {
                    ret = HpData.SumHp(dt.Select());
                }
                m_buffer[time] = ret;
            }

            return(m_buffer[time]);
        }