Esempio n. 1
0
        static void Main(string[] args)
        {
            //SPH: 2018-03-18 17:00:00          BTC-CLAM panic:05.10% in 1 hours, stability:  2 hours, recovery:1 hours,  price: 0.00039249
            //SPH: 2018-03-18 16:00:00          BTC-DOGE panic:05.13% in 1 hours, stability:  3 hours, recovery:2 hours,  price: 0.00000037
            //SPH: 2018-03-15 06:00:00          BTC-PDC panic:07.74% in 1 hours, stability:  2 hours, recovery:2 hours,  price: 0.00000286
            //SPH: 2018-02-06 08:00:00          NULSBTC panic:09.36 % in 1 hours, stability: 2 hours, recovery: 2 hours,  price: 0.00022659
            Console.WriteLine("SPH Scanner 1.04 (c) 2018 Erwin Beckers");
            Console.WriteLine("");

            // create database if it doesnt exists yet
            var db = new PriceDbContext();

            db.Database.EnsureCreated();

            // create strategy
            var strategy = new SPHStrategy();

            // scan SPH's on bittrex
            var scanner = new Scanner(ExchangeTypes.Bittrex);

            scanner.Scan(strategy);

            // scan SPH's on binance
            scanner = new Scanner(ExchangeTypes.Binance);
            scanner.Scan(strategy);


            Console.WriteLine("--- done ---");
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("SPH Scanner 1.05 (c) 2018 Erwin Beckers");
            Console.WriteLine("");

            // create database if it doesnt exists yet
            using (var db = new PriceDbContext())
            {
                db.Database.EnsureCreated();

                // create strategy
                var strategy = new SPHStrategy();

                // scan SPH's on bitfinex
                var scanner = new Scanner(db, ExchangeTypes.Bitfinex);
                scanner.Scan(strategy);

                // scan SPH's on kraken
                scanner = new Scanner(db, ExchangeTypes.Kraken);
                scanner.Scan(strategy);

                // scan SPH's on bittrex
                scanner = new Scanner(db, ExchangeTypes.Bittrex);
                scanner.Scan(strategy);

                // scan SPH's on binance
                scanner = new Scanner(db, ExchangeTypes.Binance);
                scanner.Scan(strategy);
            }

            Console.WriteLine("--- done ---");
            Console.ReadLine();
        }
Esempio n. 3
0
        public void TestGetPrice()
        {
            IPriceDbContext context = new PriceDbContext();
            //Console.WriteLine("123");
            //Price price = new Price();
            //price.ElectriPrice = 1.5;

            Price price = context.GetPrice("000001G001");

            //List<EnergyPrice> energyPrice = new List<EnergyPrice>();
            foreach (System.Reflection.PropertyInfo item in price.GetType().GetProperties())
            {
                Console.WriteLine("{0},{1}", item.Name, item.GetValue(price, null));
            }
        }
Esempio n. 4
0
 public CandleFactory(ExchangeTypes exchangeType, ExchangeAPI api, PriceDbContext dbContext)
 {
     _api          = api;
     _dbContext    = dbContext;
     _exchangeType = exchangeType;
 }
Esempio n. 5
0
 public PricesController(PriceDbContext context)
 {
     _context = context;
 }
Esempio n. 6
0
 public Scanner(PriceDbContext dbContext, ExchangeTypes exchangeType)
 {
     _exchangeType = exchangeType;
     _dbContext = dbContext;
 }
Esempio n. 7
0
 public PriceService()
 {
     context = new PriceDbContext();
 }
Esempio n. 8
0
        /// <summary>
        /// Returns the candles for a specific exchange & symbol.
        /// When present candles are returned from the database
        /// and if needed database is updated with new candles from the exchange
        /// </summary>
        /// <returns>Candles for the exchange / symbol</returns>
        /// <param name="exchangeType">Exchange.</param>
        /// <param name="symbolName">Symbol.</param>
        public List <Candle> Get(ExchangeTypes exchangeType, string symbolName)
        {
            // open database
            using (var db = new PriceDbContext())
            {
                // get exchange from database
                var exchange = db.Exchanges.FirstOrDefault(e => e.Name == exchangeType);
                if (exchange == null)
                {
                    Debug.WriteLine($"Add {exchangeType}");
                    // new exchange.. add record in database
                    exchange = new Exchange()
                    {
                        Name = exchangeType
                    };
                    db.Exchanges.Add(exchange);
                    db.SaveChanges();
                }

                // get symbol from database
                var symbol = db.Symbols.FirstOrDefault(e => e.Name == symbolName && e.ExchangeId == exchange.ExchangeId);
                if (symbol == null)
                {
                    Debug.WriteLine($"Add {symbolName}  on {exchangeType}");
                    // new symbol.. add record in database
                    symbol = new Symbol()
                    {
                        Name       = symbolName,
                        ExchangeId = exchange.ExchangeId,
                        LastUpdate = new DateTime(2018, 1, 1),
                        LastCandle = new DateTime(2018, 1, 1)
                    };
                    db.Symbols.Add(symbol);
                    db.SaveChanges();
                }

                // Check if we need to get new candles from the exchange
                var now = DateTime.Now;
                if (now.Day != symbol.LastUpdate.Day || now.Month != symbol.LastUpdate.Month || now.Year != symbol.LastUpdate.Year)
                {
                    // yes... then get all (new) candles from the exchange
                    Debug.WriteLine($"update {symbol.Name}  Last Update:{symbol.LastUpdate} ");

                    var api = ExchangeFactory.Create(exchangeType);
                    for (int i = 0; i < 2; ++i)
                    {
                        var newCandles = api.GetCandles(symbol.Name, TIMEFRAME_H1, symbol.LastCandle).ToList();
                        // add new candles to the database for next time
                        foreach (var candle in newCandles)
                        {
                            // only add new candles
                            if (candle.Timestamp > symbol.LastCandle)
                            {
                                symbol.LastCandle = candle.Timestamp;

                                db.Candles.Add(new Candle()
                                {
                                    SymbolId = symbol.SymbolId,
                                    Date     = candle.Timestamp,
                                    Open     = candle.OpenPrice,
                                    Close    = candle.ClosePrice,
                                    Low      = candle.LowPrice,
                                    High     = candle.HighPrice
                                });
                            }
                        }
                        var ts = DateTime.Now - symbol.LastCandle;
                        if (ts.TotalDays <= 1)
                        {
                            break;
                        }
                    }

                    // set lastupdate for this symbol
                    symbol.LastUpdate = now;

                    Debug.WriteLine($"  set lastupdate {symbol.Name}  to :{symbol.LastUpdate} ");
                    db.SaveChanges();
                }


                // return candles for this symbol;
                var startDate = DateTime.Now.AddMonths(-2);
                var candles   = db.Candles
                                .Where(e => e.SymbolId == symbol.SymbolId && e.Date >= startDate)
                                .OrderBy(e => e.Date)
                                .ToList();
                return(candles);
            }
        }