Beispiel #1
0
        public static List <hb_market> getSymbolsList(string type, string time)
        {
            using (huobiEntities hbdb = new huobiEntities())
            {
                DateTime time1 = DateTime.Parse(time);

                var st  = time1.Date;
                var st2 = st.AddDays(1);

                double rate = CommonData.getUSRMBrate();

                List <market> m_s = null;


                if (type == "all")
                {
                    var m = hbdb.market.Where(a => (a.last_time >= st && a.last_time < st2)).OrderByDescending(a => a.rose);

                    m_s = m.ToList();
                }
                else
                {
                    var m = hbdb.market.Where(a => (a.token_type == type && a.last_time >= st && a.last_time < st2)).OrderByDescending(a => a.rose);

                    m_s = m.ToList();
                }

                market m_btc = hbdb.market.FirstOrDefault(a => (a.coin_type == "btc" && a.token_type == "usdt" && a.last_time >= st && a.last_time < st2));

                market m_eth = hbdb.market.FirstOrDefault(a => (a.coin_type == "eth" && a.token_type == "usdt" && a.last_time >= st && a.last_time < st2));

                List <hb_market> markets = new List <hb_market>();

                //AutoMapper自动映射


                foreach (var item in m_s)
                {
                    hb_market hb_m = Mapper.Map <market, hb_market>(item);

                    if (item.token_type == "usdt")
                    {
                        hb_m.rate = rate;
                    }
                    else if (item.token_type == "btc")
                    {
                        hb_m.rate = m_btc.close_price * rate;
                    }
                    else if (item.token_type == "eth")
                    {
                        hb_m.rate = m_eth.close_price * rate;
                    }

                    markets.Add(hb_m);
                }

                return(markets);
            }
        }
Beispiel #2
0
        public static List <market> getGoodSymbols(string type)
        {
            using (huobiEntities hbdb = new huobiEntities())
            {
                DateTime time1 = DateTime.Now;

                var st  = time1.Date;
                var st2 = st.AddDays(1);
                if (type == "all")
                {
                    var m = hbdb.market.Where(a => (a.last_time >= st && a.last_time < st2));

                    return(m.ToList());
                }
                else
                {
                    var m = hbdb.market.Where(a => (a.token_type == type && a.last_time >= st && a.last_time < st2));

                    return(m.ToList());
                }
            }
        }
Beispiel #3
0
        private static void SendBackMsg()
        {
            //   huobiEntities hbdb = new huobiEntities();

            DateTime time1 = new DateTime();

            List <hb_symbols> symbols = null;

            int count = 150;

            Log.error("测试日志");

            while (true)
            {
                //半小时取一次所有交易对

                try
                {
                    DateTime time2 = DateTime.Now;

                    if ((time2 - time1).TotalMinutes > 30)
                    {
                        symbols = server.getAllSymbol();
                        time1   = time2;
                    }

                    if (symbols != null)
                    {
                        //去取数据
                        using (huobiEntities hbdb = new huobiEntities())
                        {
                            foreach (var item in symbols)
                            {
                                if (item.symbol_partition == "main" || item.symbol_partition == "innovation")
                                {
                                    string symbol = item.base_currency + item.quote_currency;

                                    List <hb_kline> data = server.getKLine(symbol, "1day", count);

                                    //存数据库....
                                    DateTime time3 = DateTime.Now;

                                    DateTime time4 = time3.Date.AddHours(23).AddMinutes(59);

                                    if (data != null && data.Count > 0)
                                    {
                                        for (var i = 0; i < data.Count; i++)
                                        {
                                            hb_kline linedata = data[i];

                                            DateTime temptime  = time4.AddDays(-i).Date;
                                            DateTime temptime2 = temptime.Date.AddDays(1);

                                            market m = hbdb.market.FirstOrDefault(a => (a.symbols == symbol && a.last_time >= temptime && a.last_time < temptime2));

                                            if (m == null)
                                            {
                                                m = new market();

                                                m.symbols     = symbol;
                                                m.coin_type   = item.base_currency;
                                                m.token_type  = item.quote_currency;
                                                m.open_price  = linedata.open;
                                                m.close_price = linedata.close;
                                                m.rose        = m.open_price != 0 ? (m.close_price - m.open_price) / m.open_price : 0;
                                                m.turnover    = 0;
                                                m.last_time   = i == 0 ? time3 : time4.AddDays(-i);

                                                hbdb.market.Add(m);
                                            }
                                            else
                                            {
                                                m.open_price  = linedata.open;
                                                m.close_price = linedata.close;
                                                m.rose        = m.open_price != 0 ? (m.close_price - m.open_price) / m.open_price : 0;
                                                m.turnover    = 0;
                                                m.last_time   = i == 0 ? time3 : time4.AddDays(-i);

                                                hbdb.Entry(m).State = EntityState.Modified;
                                            }
                                        }

                                        hbdb.SaveChanges();

                                        Thread.Sleep(100);
                                    }
                                }
                            }
                        }
                        count = 1;
                    }
                }
                catch (Exception ex)
                {
                    Log.error(ex);
                }

                Thread.Sleep(5000);
            }
        }