Exemplo n.º 1
0
        public override void DeleteOrder(string orderId)
        {
            BitstampRequest deleteOrderRequest = new BitstampRequest(DeleteOrderPath, _apiInfo);

            deleteOrderRequest.AddParameter("id", orderId);

            //Can't call ApiPost, because this request does not return a dictionary unless there is an error.
            RestClient client = new RestClient {
                BaseUrl = new Uri(BaseUrl)
            };
            IRestResponse response = client.Execute(deleteOrderRequest);

            //Don't think this can happen, but just in case
            if (response == null)
            {
                throw new Exception("Could not delete order " + orderId + " for " + Name + "; did not get a response back from the api.");
            }

            //If the response is anything other than 'true,' something went wrong. Extract the error message and throw an exception.
            if (!response.Content.Equals("true", StringComparison.InvariantCultureIgnoreCase))
            {
                //Extract the error message
                Dictionary <string, dynamic> returnedContent = new JavaScriptSerializer().Deserialize <Dictionary <string, dynamic> >(response.Content);
                string errorMessage = StringManipulation.AppendPeriodIfNecessary((string)returnedContent["error"]);

                throw new Exception("Problem deleting order " + orderId + " for " + Name + ": " + errorMessage);
            }

            //If the response just contains the word 'true', then the delete was successful.
        }
Exemplo n.º 2
0
        public override sealed void UpdateBalances()
        {
            //If using EUR, reset the converion rate everytime this method is called, to ensure it is always up to date.
            if (FiatTypeToUse == FiatType.Eur)
            {
                ConversionRate = GetUsdEurConversionRate();
            }

            // Create the authenticated request
            RestRequest request = new BitstampRequest(AccountBalanceInfoPath, _apiInfo);
            Dictionary <string, dynamic> response = ApiPost(request);

            //Set the trade fee, fiat, and btc balances.
            //Note, Bitstamp only uses USD, so before setting the fiat balance you must convert them to Euros
            TradeFee     = TypeConversion.ParseStringToDecimalStrict(response["fee"]);
            AvailableBtc = TypeConversion.ParseStringToDecimalStrict(response["btc_available"]);
            TotalBtc     = (TypeConversion.ParseStringToDecimalStrict(response["btc_available"]) + TypeConversion.ParseStringToDecimalStrict(response["btc_reserved"]));

            switch (FiatTypeToUse)
            {
            case FiatType.Eur:
                AvailableFiat = TypeConversion.ParseStringToDecimalStrict(response["usd_available"]) / ConversionRate;
                TotalFiat     = ((TypeConversion.ParseStringToDecimalStrict(response["usd_available"]) / ConversionRate) + (TypeConversion.ParseStringToDecimalStrict(response["usd_reserved"]) / ConversionRate));
                break;

            case FiatType.Usd:
                AvailableFiat = TypeConversion.ParseStringToDecimalStrict(response["usd_available"]);
                TotalFiat     = ((TypeConversion.ParseStringToDecimalStrict(response["usd_available"])) + TypeConversion.ParseStringToDecimalStrict(response["usd_reserved"]));
                break;

            //Defensive code
            default:
                throw new Exception("Unkown fiat type.");
            }
        }
Exemplo n.º 3
0
        public decimal GetUsdEurConversionRate()
        {
            //If the conversion re
            BitstampRequest conversionRateRequest = new BitstampRequest(_conversionRatePath);
            Dictionary <string, dynamic> response = ApiPost(conversionRateRequest);

            return(TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(response, "sell")));
        }
Exemplo n.º 4
0
        public override void SetTradeFee()
        {
            // Create the authenticated request
            RestRequest request = new BitstampRequest(AccountBalanceInfoPath, _apiInfo);
            Dictionary <string, dynamic> response = ApiPost(request);

            TradeFee = TypeConversion.ParseStringToDecimalStrict(response["fee"]);
        }
Exemplo n.º 5
0
        public override Dictionary <string, dynamic> GetOrderInformation(string orderId)
        {
            BitstampRequest orderStatusRequest = new BitstampRequest(OrderQueryPath, _apiInfo);

            orderStatusRequest.AddParameter("id", orderId);

            Dictionary <string, dynamic> orderStatusReponse = ApiPost(orderStatusRequest);

            return(orderStatusReponse);
        }
Exemplo n.º 6
0
        protected override string TransferInternal(decimal amount, string address)
        {
            BitstampRequest transferRequest = new BitstampRequest(_transferPath, _apiInfo);

            transferRequest.AddParameter("amount", amount);
            transferRequest.AddParameter("address", address);

            Dictionary <string, dynamic> response = ApiPost(transferRequest);

            //Bitstamp returns an integer, so turn it into a string
            return("" + GetValueFromResponseResult(response, "id"));
        }
Exemplo n.º 7
0
        public override List <Dictionary <string, dynamic> > GetAllOpenOrders()
        {
            BitstampRequest openOrderRequest = new BitstampRequest(OpenOrderPath, _apiInfo);

            Dictionary <string, dynamic>[] orderStatusReponse = ApiPost_Array(openOrderRequest);

            if (orderStatusReponse.Length <= 0)
            {
                return(null);
            }

            return(orderStatusReponse.ToList());
        }
Exemplo n.º 8
0
        public override void UpdateOrderBook(int?maxSize = null)
        {
            BitstampRequest orderBookRequest      = new BitstampRequest(OrderBookPath);
            Dictionary <string, dynamic> response = ApiPost(orderBookRequest);

            if (!response.ContainsKey("bids") || !response.ContainsKey("asks"))
            {
                throw new Exception("Could not update order book for " + Name + ", 'asks' or 'bids' object was not in the response.");
            }

            BuildOrderBook(response, 1, 0, maxSize);

            if (FiatTypeToUse == FiatType.Eur)
            {
                ConvertOrderBookToEuro();
            }
        }
Exemplo n.º 9
0
        protected override string SellInternal(decimal amount, decimal price)
        {
            if (FiatTypeToUse == FiatType.Eur)
            {
                //Price is given in Euros, but bitstamp only deals in USD. Convert price to USD. Remember to use floor round as this is a
                //sell, and thus should be rounded down.
                price = MathHelpers.FloorRound(price * ConversionRate, 2);
            }

            BitstampRequest sellRequest = new BitstampRequest(_addSellOrderPath, _apiInfo);

            sellRequest.AddParameter("amount", amount);
            sellRequest.AddParameter("price", price);

            Dictionary <string, dynamic> sellResponse = ApiPost(sellRequest);

            //Bitstamp returns an integer, so turn it into a string
            return("" + GetValueFromResponseResult(sellResponse, "id"));
        }