private async Task <string[]> GetPairsToSubscribe() { var supported = _settings.SupportedCurrencySymbols.Select(x => x.ExchangeSymbol.ToUpper()).ToArray(); if (_settings.UseSupportedCurrencySymbolsAsFilter) { return(supported); } else { var bitfinexServiceClientCredentials = new BitfinexServiceClientCredentials( string.Empty, string.Empty); // bitfinex does not require key/secret for public events var api = new BitfinexApi(bitfinexServiceClientCredentials, _log) { BaseUri = new Uri(_settings.EndpointUrl) }; return((await api.GetAllSymbolsAsync()) .Select(x => x.ToUpper()) .Concat(supported).ToArray()); } }
public BitfinexExchange(String publicKey, String privateKey, ValutaFactory factory) { if (publicKey == null || publicKey == "" || privateKey == null || privateKey == "") { throw new ArgumentException("chiavi non valide!"); } _apiClient = new BitfinexApi(publicKey, privateKey); ChiavePubblica = publicKey; ChiavePrivata = privateKey; _factory = factory ?? throw new ArgumentException("factory non può essere null!"); }
public BitfinexExchange( BitfinexAdapterSettings configuration, ILimitOrderRepository snapshotStorage, string xApiKey, string apiKey, string secret, ILog log) : base(Constants.BitfinexExchangeName, configuration, log) { _modelConverter = new BitfinexModelConverter(configuration); var credenitals = new BitfinexServiceClientCredentials(apiKey, secret); _snapshotStorage = snapshotStorage; _xApiKey = xApiKey; _exchangeApi = new BitfinexApi(credenitals, log) { BaseUri = new Uri(configuration.EndpointUrl) }; }
public override void ConnectToApi() { try { var apiSecret = ConfigurationManager.AppSettings["ApiSecret"]; var apiKey = ConfigurationManager.AppSettings["ApiKey"]; if (string.IsNullOrEmpty(apiSecret)) { throw new Exception("Missing ApiSecret in App.config"); } if (string.IsNullOrEmpty(apiKey)) { throw new Exception("Missing ApiKey in App.config"); } Api = new BitfinexApi(apiSecret, apiKey); } catch (Exception ex) { Logger.LogException(ex); } }
private static void GenerateBTCProfitRecordings() { ProfitRecording pf = new ProfitRecording(); var luno = LunoApi.GetLunoResult(0.00001M, LunoSymbolEnum.XBTZAR); decimal bestprice = ((luno.ask.price + luno.bid.price) / 2); //var bitlishUSD = BitlishApi.GetBestPrices(BitlsihSymbolEnum.BtcUsd, 0.01m); //var bitlishEUR = BitlishApi.GetBestPrices(BitlsihSymbolEnum.BtcEur, 0.01m); var cexUSD = CexApi.GetBestPrices(CEXSymbolEnum.Btc_Usd, 0.01m); var cexEUR = CexApi.GetBestPrices(CEXSymbolEnum.Btc_Eur, 0.01m); var cexGBP = CexApi.GetBestPrices(CEXSymbolEnum.Btc_Gbp, 0.01m); var bitfinexUSD = BitfinexApi.GetBestPrices(BitfinexSymbolEnum.BtcUsd, 0.01m); var bitstampUSD = BitstampApi.GetBestPrices(BitstampSymbolEnum.BTCUSD, 0.01m); var bitstampEUR = BitstampApi.GetBestPrices(BitstampSymbolEnum.BTCEUR, 0.01m); decimal usdzar = 0m; decimal eurzar = 0m; decimal rubzar = 0m; decimal gbpzar = 0m; try { usdzar = CurrencyHelper.ConvertToZAR(1, CurrencyHelper.CurrencyEnum.Usd); eurzar = CurrencyHelper.ConvertToZAR(1, CurrencyHelper.CurrencyEnum.Eur); // rubzar = CurrencyHelper.ConvertToZAR(1, CurrencyHelper.CurrencyEnum.Rub); gbpzar = CurrencyHelper.ConvertToZAR(1, CurrencyHelper.CurrencyEnum.Gbp); } catch { // failed to get live rates - use latest ProfitRecording recEUR = GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.EUR, "BTC"); ProfitRecording recUSD = GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.USD, "BTC"); ProfitRecording recGBP = GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.GBP, "BTC"); eurzar = recEUR.CurrencyToZARExchangeRate; usdzar = recUSD.CurrencyToZARExchangeRate; gbpzar = recGBP.CurrencyToZARExchangeRate; } decimal profPerc = 0; //// Bitlish USD; //try //{ // profPerc = GetProfit(bitlishUSD.ask.price, luno.bid.price, usdzar, 0.4M, 4.84M, 4000); // pf = new ProfitRecording(); // pf.Exchange = enExchange.Bitlish; // pf.Currency = enCurrency.USD; // pf.LunoBid = luno.bid.price; // pf.ExchangeAsk = bitlishUSD.ask.price; // pf.CurrencyToZARExchangeRate = usdzar; // pf.ProfitPerc = profPerc; // pf.ArbSymblol = "BTC"; // pf.Save(); //} //catch //{// duplicate last recording // ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitlish, enCurrency.USD, "BTC"); // pf = new ProfitRecording(); // pf.Exchange = pflast.Exchange; // pf.Currency = pflast.Currency; // pf.LunoBid = pflast.LunoBid; // pf.ExchangeAsk = pflast.ExchangeAsk; // pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate; // pf.ProfitPerc = pflast.ProfitPerc; // pf.ArbSymblol = "BTC"; // pf.Save(); //} //// Bitlish EUR; //try //{ // profPerc = GetProfit(bitlishEUR.ask.price, luno.bid.price, eurzar, 0.4M, 4.35M, 4000); // pf = new ProfitRecording(); // pf.Exchange = enExchange.Bitlish; // pf.Currency = enCurrency.EUR; // pf.LunoBid = luno.bid.price; // pf.ExchangeAsk = bitlishEUR.ask.price; // pf.CurrencyToZARExchangeRate = eurzar; // pf.ProfitPerc = profPerc; // pf.ArbSymblol = "BTC"; // pf.Save(); //} //catch //{// duplicate last recording // ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitlish, enCurrency.EUR, "BTC"); // pf = new ProfitRecording(); // pf.Exchange = pflast.Exchange; // pf.Currency = pflast.Currency; // pf.LunoBid = pflast.LunoBid; // pf.ExchangeAsk = pflast.ExchangeAsk; // pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate; // pf.ProfitPerc = pflast.ProfitPerc; // pf.ArbSymblol = "BTC"; // pf.Save(); //} // CEX USD; try { profPerc = GetProfit(cexUSD.ask.price, luno.bid.price, usdzar, 0.4M, 2.99M, 3000); pf = new ProfitRecording(); pf.Exchange = enExchange.Cex; pf.Currency = enCurrency.USD; pf.LunoBid = luno.bid.price; pf.ExchangeAsk = cexUSD.ask.price; pf.CurrencyToZARExchangeRate = usdzar; pf.ProfitPerc = profPerc; pf.ArbSymblol = "BTC"; pf.Save(); } catch {// duplicate last recording ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.USD, "BTC"); pf = new ProfitRecording(); pf.Exchange = pflast.Exchange; pf.Currency = pflast.Currency; pf.LunoBid = pflast.LunoBid; pf.ExchangeAsk = pflast.ExchangeAsk; pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate; pf.ProfitPerc = pflast.ProfitPerc; pf.ArbSymblol = "BTC"; pf.Save(); } // CEX EUR; try { profPerc = GetProfit(cexEUR.ask.price, luno.bid.price, eurzar, 0.4M, 2.99M, 3000); pf = new ProfitRecording(); pf.Exchange = enExchange.Cex; pf.Currency = enCurrency.EUR; pf.LunoBid = luno.bid.price; pf.ExchangeAsk = cexEUR.ask.price; pf.CurrencyToZARExchangeRate = eurzar; pf.ProfitPerc = profPerc; pf.ArbSymblol = "BTC"; pf.Save(); } catch {// duplicate last recording ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.EUR, "BTC"); pf = new ProfitRecording(); pf.Exchange = pflast.Exchange; pf.Currency = pflast.Currency; pf.LunoBid = pflast.LunoBid; pf.ExchangeAsk = pflast.ExchangeAsk; pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate; pf.ProfitPerc = pflast.ProfitPerc; pf.ArbSymblol = "BTC"; pf.Save(); } // CEX GBP; try { profPerc = GetProfit(cexGBP.ask.price, luno.bid.price, gbpzar, 0.4M, 2.99M, 2000); pf = new ProfitRecording(); pf.Exchange = enExchange.Cex; pf.Currency = enCurrency.GBP; pf.LunoBid = luno.bid.price; pf.ExchangeAsk = cexGBP.ask.price; pf.CurrencyToZARExchangeRate = gbpzar; pf.ProfitPerc = profPerc; pf.ArbSymblol = "BTC"; pf.Save(); } catch { // duplicate last recording ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.GBP, "BTC"); pf = new ProfitRecording(); pf.Exchange = pflast.Exchange; pf.Currency = pflast.Currency; pf.LunoBid = pflast.LunoBid; pf.ExchangeAsk = pflast.ExchangeAsk; pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate; pf.ProfitPerc = pflast.ProfitPerc; pf.ArbSymblol = "BTC"; pf.Save(); } // Bitfinex USD; try { profPerc = GetProfit(bitfinexUSD.ask.price, luno.bid.price, usdzar, 0.4M, 3.5M, 2000); pf = new ProfitRecording(); pf.Exchange = enExchange.Bitfinex; pf.Currency = enCurrency.USD; pf.LunoBid = luno.bid.price; pf.ExchangeAsk = bitfinexUSD.ask.price; pf.CurrencyToZARExchangeRate = usdzar; pf.ProfitPerc = profPerc; pf.ArbSymblol = "BTC"; pf.Save(); } catch { // duplicate last recording ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitfinex, enCurrency.USD, "BTC"); pf = new ProfitRecording(); pf.Exchange = pflast.Exchange; pf.Currency = pflast.Currency; pf.LunoBid = pflast.LunoBid; pf.ExchangeAsk = pflast.ExchangeAsk; pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate; pf.ProfitPerc = pflast.ProfitPerc; pf.ArbSymblol = "BTC"; pf.Save(); } // BitStamp USD; try { profPerc = GetProfit(bitstampUSD.ask.price, luno.bid.price, usdzar, 0.4M, 5.25M, 2000); pf = new ProfitRecording(); pf.Exchange = enExchange.Bitstamp; pf.Currency = enCurrency.USD; pf.LunoBid = luno.bid.price; pf.ExchangeAsk = bitstampUSD.ask.price; pf.CurrencyToZARExchangeRate = usdzar; pf.ProfitPerc = profPerc; pf.ArbSymblol = "BTC"; pf.Save(); } catch { // duplicate last recording ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitstamp, enCurrency.USD, "BTC"); pf = new ProfitRecording(); pf.Exchange = pflast.Exchange; pf.Currency = pflast.Currency; pf.LunoBid = pflast.LunoBid; pf.ExchangeAsk = pflast.ExchangeAsk; pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate; pf.ProfitPerc = pflast.ProfitPerc; pf.ArbSymblol = "BTC"; pf.Save(); } // BitStamp EUR; try { profPerc = GetProfit(bitstampEUR.ask.price, luno.bid.price, eurzar, 0.4M, 5.25M, 2000); pf = new ProfitRecording(); pf.Exchange = enExchange.Bitstamp; pf.Currency = enCurrency.EUR; pf.LunoBid = luno.bid.price; pf.ExchangeAsk = bitstampEUR.ask.price; pf.CurrencyToZARExchangeRate = eurzar; pf.ProfitPerc = profPerc; pf.ArbSymblol = "BTC"; pf.Save(); } catch { // duplicate last recording ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitstamp, enCurrency.EUR, "BTC"); pf = new ProfitRecording(); pf.Exchange = pflast.Exchange; pf.Currency = pflast.Currency; pf.LunoBid = pflast.LunoBid; pf.ExchangeAsk = pflast.ExchangeAsk; pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate; pf.ProfitPerc = pflast.ProfitPerc; pf.ArbSymblol = "BTC"; pf.Save(); } }
public static void Test() { using (var wsApi = new BitfinexSocketApi()) { BitfinexSocketApi.SetLogVerbosity(Bitfinex.Logging.LogVerbosity.Info); Console.WriteLine("Bitfinex: Socket starting..."); wsApi.Connect(); Task.Delay(3000).Wait(); /* * var subcribtion1 = wsApi.SubscribeToTradingPairTicker("tETHBTC", summary => * { * Console.WriteLine($"{DateTime.Now} BTC-ETH: {summary.LastPrice}"); * }); * Console.WriteLine($"Subcribtion1: {subcribtion1}"); */ var subcribtion2 = wsApi.SubscribeToOrderBooks("tETHBTC", OnOrderBooks, frequency: Frequency.F0, length: 1); Console.WriteLine($"Subcribtion2: {subcribtion2}"); Console.ReadLine(); } /* * var ticker = BitfinexApi.GetPublicTicker(BtcInfo.PairTypeEnum.btcusd, BtcInfo.BitfinexUnauthenicatedCallsEnum.pubticker); * Console.WriteLine(ticker.LastPrice); * * var trades = BitfinexApi.GetPairTrades(BtcInfo.PairTypeEnum.btcusd, BtcInfo.BitfinexUnauthenicatedCallsEnum.trades); * Console.WriteLine("trades.Count=" + trades.Count); * * var orderBook = BitfinexApi.GetOrderBook(BtcInfo.PairTypeEnum.btcusd); * Console.WriteLine("orderBook.Asks.Length={0}, orderBook.Bids.Length={1}", orderBook.Asks.Length, orderBook.Bids.Length); */ var api = new BitfinexApi(ApiKey, ApiSecret); var balances = api.GetBalances(); var usd = balances.FirstOrDefault(x => x.Type == "exchange" && x.Currency == "usd"); var btc = balances.FirstOrDefault(x => x.Type == "exchange" && x.Currency == "btc"); Console.WriteLine("usd: " + usd); Console.WriteLine("btc: " + btc); foreach (var balance in balances) { Console.WriteLine("balance: " + balance); } var info = api.GetAccountInformation(); Console.WriteLine("Account info: {0}", info); var openOrders = api.GetActiveOrders(); Console.WriteLine("Open orders: {0}", openOrders.Count()); /* * var cancelResult = api.CancelOrder(12345); * Console.WriteLine("CancelOrder: {0}", cancelResult); * * var sellAnswer = api.Sell(12456.3M, 2); * Console.WriteLine("Sell: {0}", sellAnswer); * * var buyAnswer = api.Buy(12.3M, 1); * Console.WriteLine("Buy: {0}", buyAnswer); */ }
public BitfinexApiClientTests() { var cred = new BitfinexServiceClientCredentials("Your API key", "Your secret"); _api = new BitfinexApi(cred); }