Beispiel #1
0
        public List <QuotationTransfer> GetChartData(string symbol, string interval)
        {
            List <QuotationTransfer> quotation = new List <QuotationTransfer>();
            string apiUrl = string.Format("https://api.binance.com/api/v1/klines?symbol={0}&interval={1}&limit=1000", symbol, interval);

            //Get data from Binance API
            List <List <double> > coinQuotation = HttpHelper.GetApiData <List <List <double> > >(new Uri(apiUrl));

            foreach (var item in coinQuotation)
            {
                QuotationTransfer newQuotation = new QuotationTransfer()
                {
                    OpenTime            = item[0],
                    Open                = item[1],
                    High                = item[2],
                    Low                 = item[3],
                    Close               = item[4],
                    Volume              = item[5],
                    CloseTime           = item[6],
                    QuoteAssetVolume    = item[7],
                    NumberOfTrades      = item[8],
                    BuyBaseAssetVolume  = item[9],
                    BuyQuoteAssetVolume = item[10],
                    Ignore              = item[11],
                };
                quotation.Add(newQuotation);
            }

            //Add Indicators to the list
            TradeIndicator.CalculateIndicator(ref quotation);

            return(quotation);
        }
Beispiel #2
0
        public List <PredictionTransfer> GetPrediction([FromBody] System.Text.Json.JsonElement data)
        {
            //0 - Deserialize the JSON Object
            List <ModelInput>         intradayList   = JsonConvert.DeserializeObject <List <ModelInput> >(data.ToString());
            List <PredictionTransfer> predictionList = new List <PredictionTransfer>();

            if (intradayList.Count == 0)
            {
                return(predictionList);
            }

            //1 - Add RSI and MACD
            TradeIndicator.CalculateIndicator(ref intradayList);

            //2 - List models available

            var rootFolder    = Environment.CurrentDirectory + "/AI/";
            var modelPathList = Directory.GetFiles(rootFolder, "*", SearchOption.AllDirectories);

            if (modelPathList.Length == 0)
            {
                return(predictionList);
            }

            //3 - Iterate throw model and fire prediction
            foreach (var modelPath in modelPathList)
            {
                PredictionTransfer prediction = new PredictionTransfer();

                var fromIndex = Path.GetFileName(modelPath).IndexOf("-") + 1;
                var toIndex   = Path.GetFileName(modelPath).Length - fromIndex - 4;
                prediction.ModelName = Path.GetFileName(modelPath).Substring(fromIndex, toIndex);

                prediction.Future   = CalculatePrediction(intradayList.Last(), modelPath).Future;
                prediction.Rsi      = intradayList.Last().Rsi;
                prediction.Macd     = intradayList.Last().Macd;
                prediction.MacdHist = intradayList.Last().MacdHist;
                prediction.MacdSign = intradayList.Last().MacdSign;
                predictionList.Add(prediction);
            }

            return(predictionList);
        }