Exemplo n.º 1
0
        public static IBitfinexClient CreateResponseClient <T>(T response, BitfinexClientOptions options = null)
        {
            var client = (BitfinexClient)CreateClient(options);

            SetResponse(client, JsonConvert.SerializeObject(response));
            return(client);
        }
Exemplo n.º 2
0
        public BitfinexRestApi(string apiKey, string apiSecret)
        {
            BitfinexClientOptions options = new BitfinexClientOptions();

            options.ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials(apiKey, apiSecret);
            m_client = new BitfinexClient(options);
        }
Exemplo n.º 3
0
        public static IBitfinexClient CreateResponseClient(string response, BitfinexClientOptions options = null, HttpStatusCode code = HttpStatusCode.OK)
        {
            var client = (BitfinexClient)CreateClient(options);

            SetResponse(client, response, code);
            return(client);
        }
Exemplo n.º 4
0
        public void CancelOrder(UserTradeOrder aOrder, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder == null)
            {
                throw new ArgumentNullException(nameof(aOrder), "Invalid argument: " + nameof(aOrder));
            }

            BitfinexClientOptions lBittrexClientOptions = new BitfinexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (BitfinexClient lClient = aUseProxy ? new BitfinexClient(lBittrexClientOptions) : new BitfinexClient())
            {
                var lResponse = lClient.CancelOrderAsync(Convert.ToInt64(aOrder.ID)).Result;
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to cancel order in exchange. Message: " + lResponse.Error.Message);
                }
            }
        }
Exemplo n.º 5
0
        public bool RefundOrder(UserTradeOrder aOrder, string aAddress, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder.Status == OrderStatus.Withdrawn)
            {
                return(false);
            }

            BitfinexClientOptions lBittrexClientOptions = new BitfinexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (BitfinexClient lClient = aUseProxy ? new BitfinexClient(lBittrexClientOptions) : new BitfinexClient())
            {
                var lResponse = lClient.WithdrawAsync(aOrder.Market.SellingCurrencyInfo.Name.ToLowerInvariant(), WithdrawWallet.Exchange, aOrder.SentQuantity, aAddress).Result;
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to withdraw. Error message:" + lResponse.Error.Message);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        public static IBitfinexClient CreateResponseClient(string response, BitfinexClientOptions options = null)
        {
            var client = (BitfinexClient)CreateClient(options);

            SetResponse(client, response);
            return(client);
        }
Exemplo n.º 7
0
 private BitfinexClient Construct(BitfinexClientOptions options = null)
 {
     if (options != null)
     {
         return(new BitfinexClient(options));
     }
     return(new BitfinexClient());
 }
Exemplo n.º 8
0
        public static IBitfinexClient CreateClient(BitfinexClientOptions options = null)
        {
            IBitfinexClient client;

            client = options != null ? new BitfinexClient(options) : new BitfinexClient();
            client.RequestFactory = Mock.Of <IRequestFactory>();
            return(client);
        }
Exemplo n.º 9
0
        public void Clear()
        {
            var lClientOptions = new BitfinexClientOptions {
                ApiCredentials = null
            };

            BitfinexClient.SetDefaultOptions(lClientOptions);
            IsCredentialsSet = false;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create a new instance of BitfinexClient using provided options
        /// </summary>
        /// <param name="options">The options to use for this client</param>
        public BitfinexClient(BitfinexClientOptions options) : base("Bitfinex", options)
        {
            if (options == null)
            {
                throw new ArgumentException("Cant pass null options, use empty constructor for default");
            }

            GeneralApi = AddApiClient(new BitfinexClientGeneralApi(log, this, options));
            SpotApi    = AddApiClient(new BitfinexClientSpotApi(log, this, options));
        }
Exemplo n.º 11
0
        internal BitfinexClientGeneralApi(Log log, BitfinexClient baseClient, BitfinexClientOptions options) :
            base(options, options.SpotApiOptions)
        {
            _baseClient = baseClient;
            _log        = log;
            _options    = options;

            Funding = new BitfinexClientGeneralApiFunding(this);

            AffiliateCode = options.AffiliateCode;
        }
Exemplo n.º 12
0
        public BitfinexClient GetBitfinexClient()
        {
            var exchange  = "BITFINEX";
            var apiKey    = m_creds[exchange].Key;
            var apiSecret = m_creds[exchange].Secret;
            var options   = new BitfinexClientOptions();

            options.ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials(apiKey, apiSecret);
            var client = new BitfinexClient(options);

            return(client);
        }
Exemplo n.º 13
0
        internal BitfinexClientSpotApi(Log log, BitfinexClient baseClient, BitfinexClientOptions options) :
            base(options, options.SpotApiOptions)
        {
            _baseClient = baseClient;
            _log        = log;
            _options    = options;

            Account      = new BitfinexClientSpotApiAccount(this);
            ExchangeData = new BitfinexClientSpotApiExchangeData(this);
            Trading      = new BitfinexClientSpotApiTrading(this);

            AffiliateCode = options.AffiliateCode;
        }
Exemplo n.º 14
0
        public bool PlaceOrder(UserTradeOrder aOrder, bool aUseProxy = true)
        {
            if (!IsCredentialsSet)
            {
                throw new Exception("No Credentials were set");
            }

            if (aOrder == null || aOrder.Market == null)
            {
                throw new ArgumentNullException(aOrder == null ? nameof(aOrder) : nameof(aOrder.Market), "Invalid argument: " + aOrder == null ? nameof(aOrder) : nameof(aOrder.Market));
            }

            if (aOrder.Status != OrderStatus.Waiting)
            {
                return(false);
            }

            BitfinexClientOptions lBitfinexClientOptions = new BitfinexClientOptions()
            {
                Proxy          = PandoraProxy.GetApiProxy(),
                ApiCredentials = new ApiCredentials(FUserCredentials.Item1, FUserCredentials.Item2)
            };

            using (BitfinexClient lClient = aUseProxy ? new BitfinexClient(lBitfinexClientOptions) : new BitfinexClient())
            {
                if (!aOrder.Market.TryCastToLocalMarket(out ExchangeMarket lExchangeMarket))
                {
                    throw new ArgumentException(nameof(aOrder.Market), "Invalid Market");
                }
                var lResponse = lClient.PlaceOrderAsync(lExchangeMarket.MarketPairID, lExchangeMarket.MarketDirection == MarketDirection.Sell ? OrderSide.Sell : OrderSide.Buy, OrderType.ExchangeLimit, lExchangeMarket.MarketDirection == MarketDirection.Sell ? aOrder.SentQuantity : aOrder.SentQuantity / aOrder.Rate, aOrder.Rate).Result;
                if (!lResponse.Success)
                {
                    throw new Exception($"Bitfinex Error. Message: {lResponse.Error.Message}");
                }
                long lUuid = lResponse.Data.Id;

                var lVerifyResponse = lClient.GetOrderAsync(lUuid).Result;
                if (!lResponse.Success)
                {
                    throw new Exception("Failed to verify order with exchange server");
                }
                aOrder.ID        = lUuid.ToString();
                aOrder.OpenTime  = lVerifyResponse.Data.Timestamp;
                aOrder.Cancelled = lVerifyResponse.Data.Canceled;
                aOrder.Completed = lVerifyResponse.Data.RemainingAmount == 0;
            }

            return(true);
        }
Exemplo n.º 15
0
        static void CreateBitfinexExchange(out BitfinexClient exch, out BitfinexSocketClient sock)
        {
            var evKeys = Environment.GetEnvironmentVariable("BITFINEX_KEY", EnvironmentVariableTarget.User);
            var keys   = evKeys.Split('|');

            var clientOptions = new BitfinexClientOptions();

            clientOptions.ApiCredentials = new ApiCredentials(keys[0], keys[1]);
            exch = new BitfinexClient(clientOptions);
            //----------
            var socketOptions = new BitfinexSocketClientOptions();

            socketOptions.ApiCredentials = clientOptions.ApiCredentials;
            sock = new BitfinexSocketClient(socketOptions);
        }
        //public BitfinexExchange(KafkaProducer p)
        public BitfinexExchange(string bootstrapServers, string topic)
        {
            var evKeys = Environment.GetEnvironmentVariable(ApiKeyEnvVar, EnvironmentVariableTarget.User);
            var keys = evKeys.Split('|');

            var clientOptions = new BitfinexClientOptions();
            clientOptions.ApiCredentials = new ApiCredentials(keys[0], keys[1]);
            this.exch = new BitfinexClient(clientOptions);
            //----------
            var socketOptions = new BitfinexSocketClientOptions();
            socketOptions.ApiCredentials = clientOptions.ApiCredentials;
            this.sock = new BitfinexSocketClient(socketOptions);

            //_p = p;
            _p = new KafkaProducer(bootstrapServers, topic);
        }
Exemplo n.º 17
0
        public void SetCredentials(string aApiKey, string aApiSecret)
        {
            var lCredentials = new ApiCredentials(aApiKey, aApiSecret);

            var lClientOptions = new BitfinexClientOptions {
                ApiCredentials = lCredentials
            };

            BitfinexClient.SetDefaultOptions(lClientOptions);
            using (BitfinexClient lClient = new BitfinexClient())
            {
                var lResponse = lClient.GetBalancesAsync().Result;
                if (!lResponse.Success)
                {
                    throw new PandoraExchangeExceptions.InvalidExchangeCredentials("Incorrect Key Pair for selected exchange");
                }
            }
            FUserCredentials = new Tuple <string, string>(aApiKey, aApiSecret);
            IsCredentialsSet = true;
        }
Exemplo n.º 18
0
 /// <summary>
 /// Set the default options to be used when creating new clients
 /// </summary>
 /// <param name="options">Options to use as default</param>
 public static void SetDefaultOptions(BitfinexClientOptions options)
 {
     BitfinexClientOptions.Default = options;
 }
Exemplo n.º 19
0
        public static IBitfinexClient CreateAuthenticatedResponseClient <T>(T response, BitfinexClientOptions options = null)
        {
            var client = (BitfinexClient)CreateClient(options ?? new BitfinexClientOptions()
            {
                ApiCredentials = new ApiCredentials("Test", "Test")
            });

            SetResponse(client, JsonConvert.SerializeObject(response));
            return(client);
        }