Пример #1
0
        static async Task FindTransactionByCryptoAddress()
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            string addressToLookFor = "<address>";

            var request = new HistoryRequest
            {
                Currency = "BTC",
                Method   = "bitcoin",
                Since    = DateTimeOffset.Now.AddDays(-3).ToUnixTimeSeconds().ToString(),
                Until    = DateTimeOffset.Now.AddDays(1).ToUnixTimeSeconds().ToString(),
                Limit    = 100,
            };

            LogRequest(request);

            var response = await api.HistoryAsync(request);

            LogResponse(response);

            var item = response.First(t => t.Address == addressToLookFor);

            double expectedAmount = 0.01851848;

            Console.WriteLine("################## Result ################");
            Console.WriteLine($"Expected: Address: {addressToLookFor}, Amount: {expectedAmount} BTC");
            Console.WriteLine($"Actual: Address: {item.Address}, Amount {item.Amount} {item.Currency}, Fee: {item.Fee}, type: {item.Type}");
        }
Пример #2
0
 private Bitfinex(string apikey, string apisecret)
 {
     ApiKey     = apikey;
     ApiSecret  = apisecret;
     m_api      = new BitfinexApiV1(ApiKey, ApiSecret);
     m_instance = this;
 }
Пример #3
0
        static async Task FindTransactionByTxnId()
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            string txnId = "<txnId>";

            var request = new HistoryRequest
            {
                Currency = "BTC",
                Method   = "bitcoin",
                Since    = DateTimeOffset.Now.AddDays(-30).ToUnixTimeSeconds().ToString(),
                Until    = DateTimeOffset.Now.AddDays(1).ToUnixTimeSeconds().ToString(),
                Limit    = 100,
            };

            LogRequest(request);

            var response = await api.HistoryAsync(request);

            LogResponse(response);

            var item = response.First(t => t.Txid == txnId);

            double expectedAmount = 0.0;

            Console.WriteLine("################## Result ################");
            Console.WriteLine($"Expected: TxnId: {txnId}, Amount: {expectedAmount} BTC");
            Console.WriteLine($"Actual: TxnId: {item.Txid}, Amount {item.Amount} {item.Currency}, Fee: {item.Fee}, type: {item.Type}");
        }
Пример #4
0
        static async Task HistorySample(string currency, string method)
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            var request = new HistoryRequest
            {
                Currency = currency,
                Method   = method,
                Since    = DateTimeOffset.Now.AddDays(-3).ToUnixTimeSeconds().ToString(),
                Until    = DateTimeOffset.Now.AddDays(1).ToUnixTimeSeconds().ToString(),
                Limit    = 100,
            };

            LogRequest(request);

            var response = await api.HistoryAsync(request);

            foreach (var r in response)
            {
                r.Timestamp        = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(Convert.ToDouble(r.Timestamp))).ToString();
                r.TimestampCreated = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(Convert.ToDouble(r.TimestampCreated))).ToString();
            }

            LogResponse(response);
        }
Пример #5
0
        static async Task SummarySample()
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            var response = await api.SummaryAsync();

            LogResponse(response);
        }
Пример #6
0
        static async Task AccountInfosSample()
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            var response = await api.AccountInfosAsync();

            LogResponse(response);
        }
Пример #7
0
        public BitfinexRestAPI()
        {
            var secret = ConfigurationManager.AppSettings["ApiSecret"];
            var key    = ConfigurationManager.AppSettings["ApiKey"];


            api = new BitfinexApiV1(key, secret);

            bal = api.GetBalances();
        }
Пример #8
0
        static async Task DepositSample()
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            // Attention !!! there is a limit on number of new address per account!!! --
            var request = new DepositRequest
            {
                Method     = "bitcoin",
                WalletName = "exchange",
                Renew      = 1,
            };

            LogRequest(request);

            var response = await api.DepositAsync(request);

            LogResponse(response);
        }
Пример #9
0
        static async Task PastTradesSample(string symbol)
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            var request = new PastTradesRequest
            {
                Symbol      = symbol,
                Timestamp   = DateTimeOffset.Now.AddDays(-3).ToUnixTimeSeconds().ToString(),
                Until       = DateTimeOffset.Now.AddDays(1).ToUnixTimeSeconds().ToString(),
                LimitTrades = 100,
                Reverse     = 0,
            };

            LogRequest(request);

            var response = await api.PastTradesAsync(request);

            LogResponse(response);
        }
Пример #10
0
        public async Task Bitfinex(string BuyOrSell)
        {
            BitfinexAssets assets = new BitfinexAssets();
            var            user   = new BitfinexApiV1("yIruCEm5k2TkExflzSf183xBp4HUt66G2BDx6WJqlL7HATRyJmcgp5UAiqYl0XsF", "BEqWhtDUPDIpNmaHFxA5ZhXLElcS74oal6yHLEx5sbE5gu46EsYLAfWAx1veyUr0");

            Console.WriteLine("Successfull");
            switch (BuyOrSell)
            {
            case "buy":
                await user.ExecuteBuyOrderAsync(1000, 1, OrderExchange.Bitfinex, OrderSymbol.ETHBTC, BitfinexApi.OrderType.MarginMarket);

                break;

            case "sell":
                await user.ExecuteSellOrderAsync(1000, 1, OrderExchange.Bitfinex, OrderSymbol.ETHBTC, BitfinexApi.OrderType.MarginMarket);

                break;
            }
        }
Пример #11
0
        static async Task OrderStatusSample(long orderId)
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            var request = new OrderStatusRequest
            {
                OrderId = orderId
            };

            LogRequest(request);

            var response = await api.OrderStatusAsync(request);

            LogResponse(response);

            if (response.IsLive)
            {
                throw new ApplicationException("Order is still being executed. Waiting for completion.");
            }
        }
Пример #12
0
        static async Task NewOrderAndOrderStatusSample()
        {
            var api = new BitfinexApiV1(Configuration["BitfinexApi_key"], Configuration["BitfinexApi_secret"]);

            var request = new NewOrderRequest
            {
                Symbol = OrderSymbols.BTCUSD,
                Amount = 0.004.ToString(),
                // Price to buy or sell at. Must be positive. Use random number for market orders.
                Price = new Random().NextDouble().ToString(),
                Side  = OrderSides.Sell,
                Type  = OrderTypes.ExchangeMarket,
            };

            LogRequest(request);

            var response = await api.NewOrderAsync(request);

            LogResponse(response);

            long orderId = response.OrderId;

            Retry.Do(() => { OrderStatusSample(orderId).Wait(); }, TimeSpan.FromSeconds(5));
        }
Пример #13
0
 public BitfinexExchange()
 {
     api = new BitfinexApiV1(Properties.Settings.Default.BitfinexApiKey, Properties.Settings.Default.BitfinexApiSecret);
 }