Ejemplo n.º 1
0
        public void OpenWebSocketTest()
        {
            // Arrange
            IExchangeApi exchangeApi = ExchangeFactory.GetExchangeApi(Enumerations.ExchangesEnum.Gdax, _exchangeSettings);

            // Act
            exchangeApi.OpenSocket();
        }
Ejemplo n.º 2
0
        private IExchangeApi GetExchange(Bot bot)
        {
            ApiSetting exchangeSetting = bot.User.ApiSettings.FirstOrDefault(x => x.Exchange.ExchangeId == bot.Exchange.ExchangeId);

            return
                (ExchangeFactory.GetExchangeApi((Enumerations.ExchangesEnum)bot.Exchange.ExchangeId, new ExchangeSettings
            {
                Url = exchangeSetting.Url,
                SocketUrl = exchangeSetting.SocketUrl,
                PassPhrase = exchangeSetting.Passphrase,
                ApiKey = exchangeSetting.Key,
                Secret = exchangeSetting.Secret,
                CommissionRate = exchangeSetting.ComissionRate,
                Simulate = exchangeSetting.Simulated
            }));
        }
Ejemplo n.º 3
0
        public void GetBTCTickerTest()
        {
            // Arrange
            IExchangeApi exchangeApi = ExchangeFactory.GetExchangeApi(Enumerations.ExchangesEnum.Gdax, _exchangeSettings);

            // Act
            var response = exchangeApi.GetTicker(new Coin()
            {
                Code = "BTC"
            }, new Coin()
            {
                Code = "EUR"
            });


            // Asert
            Assert.IsNotNull(response);
        }
Ejemplo n.º 4
0
        public async Task <HistoryResponseDto> History(string symbol, Int32 from, Int32 to, string resolution)
        {
            _exchangeApi = ExchangeFactory.GetExchangeApi(Enumerations.ExchangesEnum.Gdax, null);

            IEnumerable <Candle> candles =
                _exchangeApi.GetCandles(new Coin {
                Code = "EUR"
            }, new Coin {
                Code = "BTC"
            }, 60 * 60 * 24, UnixTimeStampToDateTime(from), UnixTimeStampToDateTime(to));

            candles = candles.OrderBy(x => x.Timestamp);

            //var asTable = ToDataTable(candles.ToList());

            var response = new HistoryResponseDto
            {
                TimeStamps = candles.Select(x => (long)CryptoUtility.UnixTimestampFromDateTimeSeconds(x.Timestamp)).ToArray(),
                Opens      = candles.Select(x => x.OpenPrice).ToArray(),
                Highs      = candles.Select(x => x.HighPrice).ToArray(),
                Lows       = candles.Select(x => x.LowPrice).ToArray(),
                Closes     = candles.Select(x => x.ClosePrice).ToArray(),
                Volumes    = candles.Select(x => Convert.ToDecimal(x.VolumeQuantity)).ToArray(),
                Status     = "ok"
            };

            return(response);

            //var json = System.IO.File.ReadAllText("D:\\Development\\CryptoBot\\CryptoBot.Api\\Data\\Sample\\history.json");
            //var result = JsonConvert.DeserializeObject<HistoryResponseDto>(json);
            //var fromDates = result.TimeStamps.Where(x => x > from);
            //var toDates = result.TimeStamps.Where(x => x < to);

            //if(!fromDates.Any() || !toDates.Any())
            //    return new HistoryResponseDto{ Status = "no_data"};

            //return JsonConvert.DeserializeObject<HistoryResponseDto>(json);
        }