Exemple #1
0
        /// <summary>
        /// 新增交易信息
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="t"></param>
        public void AddTrade(string symbol, CommonLab.Trade t)
        {
            DateTime timeStamp = CommonLab.TimerHelper.ConvertStringToDateTime(t.ExchangeTimeStamp);
            string   key       = "";

            if (timeStamp.Year < 2018)
            {
                return;
            }
            int count = 0;

            try
            {
                foreach (CommonLab.TimePeriodType type in Enum.GetValues(typeof(CommonLab.TimePeriodType)))
                {
                    key = CommonLab.RedisKeyConvert.GetRedisKey(CommonLab.RedisKeyType.Trade, type, CommonLab.ExchangeNameConvert.GetShortExchangeName("binance"), symbol, timeStamp);
                    //if (DateTime.Now.Hour == 0 && DateTime.Now.Minute < 5)
                    //{
                    //    log.log("key:" + key + "  TradeData:"+ TradeData.Count);
                    //}
                    //count++;
                    lock (TradeData)
                    {
                        count++;
                        if (TradeData.ContainsKey(key))
                        {
                            count++;
                            TradeData[key].Update(t, GetLegalCurrency(symbol));
                        }
                        else
                        {
                            count++;
                            CommonLab.TradePeriod tpm = new CommonLab.TradePeriod(symbol, t, GetLegalCurrency(symbol));
                            count++;
                            TradeData.TryAdd(key, tpm);
                        }
                    }
                }
            }
            catch (IndexOutOfRangeException e)
            {
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(TradeData);
                log.log(count + "key:" + key + "\r\nORE" + e.Message + e.StackTrace + e.Source + "\r\n" + json);
                Console.WriteLine("key:" + key + "\r\nORE" + e.Message + e.StackTrace + e.Source + "\r\n" + json);
                //Console.ReadKey();
            }
        }
Exemple #2
0
        private void Updateinfo()
        {
            timestart = CommonLab.TimerHelper.GetStartTimeStampByPreiod(timeperiodtype, DateTime.UtcNow);
            timeend   = CommonLab.TimerHelper.GetEndTimeStampByPreiod(timeperiodtype, timestart);
            string key = CommonLab.RedisKeyConvert.GetRedisKey(CommonLab.RedisKeyType.Trade, timeperiodtype, CommonLab.ExchangeNameConvert.GetShortExchangeName("binance"), symbol, timestart);

            if (db.KeyExists(key))
            {
                string json = db.StringGet(key);
                CommonLab.TradePeriod tp = JsonConvert.DeserializeObject <CommonLab.TradePeriod>(json);
                label20.Text = symbol;
                label19.Text = timestart.ToString() + "--" + timeend.ToString();
                label18.Text = tp.tradecountBuy.ToString();
                label17.Text = tp.baseSymbolVolumBuy.ToString();
                label16.Text = tp.quoteSymbolVolumBuy.ToString();
                label15.Text = tp.tradecountSell.ToString();
                label14.Text = tp.baseSymbolVolumSell.ToString();
                label13.Text = tp.quoteSymbolVolumSell.ToString();
                label12.Text = tp.CNYVolumBuy.ToString();
                label11.Text = tp.CNYVolumSell.ToString();
                double cnydiff = tp.CNYVolumBuy - tp.CNYVolumSell;
                if (cnydiff > 0)
                {
                    label21.ForeColor = Color.Green;
                }
                else if (cnydiff < 0)
                {
                    label21.ForeColor = Color.Red;
                }
                chart1.Series[0].Points.Clear();
                chart1.Series[0].Points.AddY(tp.CNYVolumBuy);
                chart1.Series[0].Points.AddY(tp.CNYVolumSell);
                chart1.Series[0].Points[0].Color = Color.Green;
                chart1.Series[0].Points[1].Color = Color.Red;
                label21.Text = cnydiff.ToString();
            }
            else
            {
                MessageBox.Show("Data not found!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #3
0
        private void UpdateRedis()
        {
            while (true)
            {
                List <string> keys = new List <string>();
                // string key = "TradePerMin@" + symbol + "@" + CommonLab.TimerHelper.ConvertStringToDateTime(t.ExchangeTimeStamp).ToString("yyMMddHHmm") + "@" + direction;
                lock (TradeData)
                {
                    try
                    {
                        foreach (KeyValuePair <string, CommonLab.TradePeriod> item in TradeData)
                        {
                            string   Key          = item.Key.ToString();
                            DateTime t            = Convert.ToDateTime(Key.Split('@')[4]);
                            string   type         = Key.Split('@')[0];
                            string   period       = Key.Split('@')[1];
                            string   exchangename = CommonLab.ExchangeNameConvert.GetLongExchangeName(Key.Split('@')[2]);
                            string   symbol       = Key.Split('@')[3];
                            CommonLab.TimePeriodType periodType = (CommonLab.TimePeriodType)Enum.Parse(typeof(CommonLab.TimePeriodType), period);
                            switch (periodType)
                            {
                            case CommonLab.TimePeriodType.m1:
                                if ((DateTime.UtcNow - t).TotalMinutes >= 2)
                                {
                                    keys.Add(item.Key);
                                }
                                break;

                            case CommonLab.TimePeriodType.m5:
                                if ((DateTime.UtcNow - t).TotalMinutes >= 6)
                                {
                                    keys.Add(item.Key);
                                }
                                break;

                            case CommonLab.TimePeriodType.m10:
                                if ((DateTime.UtcNow - t).TotalMinutes >= 11)
                                {
                                    keys.Add(item.Key);
                                }
                                break;

                            case CommonLab.TimePeriodType.m30:
                                if ((DateTime.UtcNow - t).TotalMinutes >= 31)
                                {
                                    keys.Add(item.Key);
                                }
                                break;

                            case CommonLab.TimePeriodType.h1:
                                if ((DateTime.UtcNow - t).TotalHours >= 1.1)
                                {
                                    keys.Add(item.Key);
                                }
                                break;

                            case CommonLab.TimePeriodType.h4:
                                if ((DateTime.UtcNow - t).TotalHours >= 4.1)
                                {
                                    keys.Add(item.Key);
                                }
                                break;

                            case CommonLab.TimePeriodType.d1:
                                if ((DateTime.UtcNow - t).TotalHours >= 24.1)
                                {
                                    keys.Add(item.Key);
                                }
                                break;

                            default:
                                break;
                            }

                            //需要存入redis之后移除

                            //keys.Add(item.Key);
                            string jsont = JsonConvert.SerializeObject(item.Value);
                            if (CommonLab.RedisKeyConvert.GetRedisKeyExpiredTime(periodType) == -1)
                            {
                                db.StringSet(item.Key, jsont);
                            }
                            else
                            {
                                db.StringSet(item.Key, jsont);

                                db.KeyExpire(item.Key, DateTime.UtcNow.AddMinutes(48 * 60));
                            }


                            //Data.Remove(item.Key);
                            Console.WriteLine("TID:" + Thread.CurrentThread.ManagedThreadId.ToString() + " " + DateTime.UtcNow.ToString() + "- WI" + item.Key + " into redis.");
                        }
                    }
                    catch (Exception e)
                    {
                        log.log(e.Message + e.StackTrace);
                    }
                }
                foreach (string key in keys)
                {
                    CommonLab.TradePeriod igonred = new CommonLab.TradePeriod("", null, 0);
                    TradeData.TryRemove(key, out igonred);
                }
                Thread.Sleep(30 * 1000);
            }
        }