Example #1
0
        /// <summary>
        /// This never worked for me...
        /// </summary>
        /// <returns></returns>
        public object GetAccountInformation()
        {
            var accountPost = new BitfinexPostBase
            {
                Request = AccountInfoRequestUrl,
                Nonce   = Common.UnixTimeStampUtc().ToString(CultureInfo.InvariantCulture)
            };

            var response = GetRestResponse(accountPost);

            Log.Info("Account Information: {0}", response);
            return(response);
        }
Example #2
0
        public string CancellAllActiveOrders()
        {
            const string url           = OrderCancelRequestUrl + CancelAllRequestUrl;
            var          cancelAllPost = new BitfinexPostBase
            {
                Request = url,
                Nonce   = Common.UnixTimeStampUtc().ToString(CultureInfo.InvariantCulture)
            };

            var response = GetRestResponse(cancelAllPost);

            return(response);
        }
Example #3
0
        private string GetRestResponse(BitfinexPostBase obj)
        {
            HttpRequestMessage request;
            {
                var jsonObj = JsonConvert.SerializeObject(obj);
                var payload = Convert.ToBase64String(Encoding.UTF8.GetBytes(jsonObj));
                request = new HttpRequestMessage(HttpMethod.Post, obj.Request);
                request.Headers.Add(ApiBfxKey, ApiKey);
                request.Headers.Add(ApiBfxPayload, payload);
                request.Headers.Add(ApiBfxSig, GetHexHashSignature(payload));
            }

            var responseMessage = WebApi.Client.SendAsync(request).Result;
            var response        = responseMessage.Content.ReadAsStringAsync().Result;

            CheckResultCode(responseMessage.StatusCode, response);

            return(response);
        }
Example #4
0
        /// <summary>
        /// In the Total Return Swaps page you will see a horizontal header "Swaps used in margin position"
        /// This function returns information about what you have borrowed. If you want to close the
        /// swap you must pass the id returned here to the "CloseSwap" function.
        /// If you want to 'cash out' and claim the position you must pass the position id to the "ClaimPosition" function.
        /// </summary>
        /// <returns></returns>
        public IList <BitfinexActiveSwapsInMarginResponse> GetActiveSwapsUsedInMarginPosition()
        {
            var activeSwapsInMarginPost = new BitfinexPostBase
            {
                Request = ActiveMarginSwapsRequestUrl,
                Nonce   = Common.UnixTimeStampUtc().ToString(CultureInfo.InvariantCulture)
            };

            var response = GetRestResponse(activeSwapsInMarginPost);
            var activeSwapsInMarginResponseObj = JsonConvert.DeserializeObject <IList <BitfinexActiveSwapsInMarginResponse> >(response);

            Log.Info("Active Swaps In Margin Pos:");
            foreach (var activeSwaps in activeSwapsInMarginResponseObj)
            {
                Log.Info("Swaps used in margin: {0}", activeSwaps.ToString());
            }

            return(activeSwapsInMarginResponseObj);
        }
Example #5
0
        public IList <BitfinexActiveCreditsResponse> GetActiveCredits()
        {
            var activeCreditsPost = new BitfinexPostBase
            {
                Request = ActiveCreditsRequestUrl,
                Nonce   = Common.UnixTimeStampUtc().ToString(CultureInfo.InvariantCulture)
            };

            var response = GetRestResponse(activeCreditsPost);
            var activeCreditsResponseObj = JsonConvert.DeserializeObject <IList <BitfinexActiveCreditsResponse> >(response);

            Log.Info("Active Credits:");
            foreach (var activeCredits in activeCreditsResponseObj)
            {
                Log.Info("Credits: {0}", activeCredits.ToString());
            }

            return(activeCreditsResponseObj);
        }
Example #6
0
        public IList <BitfinexBalanceResponse> GetBalances()
        {
            var balancePost = new BitfinexPostBase
            {
                Request = BalanceRequestUrl,
                Nonce   = Common.UnixTimeStampUtc().ToString(CultureInfo.InvariantCulture)
            };

            var response    = GetRestResponse(balancePost);
            var balancesObj = JsonConvert.DeserializeObject <IList <BitfinexBalanceResponse> >(response);

            Log.Info("Balances:");
            foreach (var balance in balancesObj)
            {
                Log.Info(balance.ToString());
            }

            return(balancesObj);
        }
Example #7
0
        private IRestResponse QueryPrivate(string method, Dictionary <string, Object> param = null)
        {
            string path        = string.Format(CultureInfo.InvariantCulture, "/v1/0}", method);
            var    balancePost = new BitfinexPostBase();

            balancePost.Request = path;
            balancePost.Nonce   = GetNonce().ToString();

            var client      = GetRestClient(path);
            var restRequest = GetRestRequest(balancePost);

            if (param != null)
            {
                foreach (var item in param)
                {
                    restRequest.AddParameter(item.Key, item.Value);
                }
            }
            var response = GetRestResponse(client, restRequest);

            return(response);
        }
Example #8
0
        public BitfinexMarginInfoResponse GetMarginInformation()
        {
            var marginPost = new BitfinexPostBase
            {
                Request = MarginInfoRequstUrl,
                Nonce   = Common.UnixTimeStampUtc().ToString(CultureInfo.InvariantCulture)
            };

            var response = GetRestResponse(marginPost);

            var jArr = JsonConvert.DeserializeObject(response) as JArray;

            if (jArr == null || jArr.Count == 0)
            {
                return(null);
            }

            var marginInfoStr         = jArr[0].ToString();
            var marginInfoResponseObj = JsonConvert.DeserializeObject <BitfinexMarginInfoResponse>(marginInfoStr);

            Log.Info("Margin Info: {0}", marginInfoResponseObj.ToString());

            return(marginInfoResponseObj);
        }