Exemplo n.º 1
0
        public override List <Dictionary <string, dynamic> > GetAllOpenOrders()
        {
            List <Dictionary <string, dynamic> > returnList = new List <Dictionary <string, dynamic> >();

            KrakenRequest request = new KrakenRequest(OpenOrderPath, _apiInfo);

            request.AddSignatureHeader();
            Dictionary <string, dynamic> response = ApiPost(request);

            response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, "open");

            //Loop through all the orders, add the id as one of the properties and build the return list
            foreach (var order in response)
            {
                order.Value["order-id"] = order.Key;
                returnList.Add(order.Value);
            }

            if (returnList.Count <= 0)
            {
                return(null);
            }

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

            transferRequest.AddParameter("asset", BTC_SYMBOL);
            transferRequest.AddParameter("key", address);
            transferRequest.AddParameter("amount", amount);
            transferRequest.AddSignatureHeader();

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

            return((string)GetValueFromResponseResult(response, "refid"));
        }
Exemplo n.º 3
0
        public override Dictionary <string, dynamic> GetOrderInformation(string orderId)
        {
            KrakenRequest request = new KrakenRequest(OrderQueryPath, _apiInfo);

            request.AddParameter("txid", orderId);
            request.AddSignatureHeader();

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

            response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, orderId);

            return(response);
        }
Exemplo n.º 4
0
        public override void SetTradeFee()
        {
            KrakenRequest request = new KrakenRequest(_tradeFeeInfoPath, _apiInfo);

            request.AddParameter("pair", _btcFiatPairSymbol);
            request.AddSignatureHeader();

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

            //The trade fee value is buried deep in the response; par down response until we get to the bit we want
            response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, "fees");
            response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, _btcFiatPairSymbol);

            TradeFee = TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(response, "fee"));
        }
Exemplo n.º 5
0
        /// <summary>
        /// With Kraken, buying and selling is the same Api call. So both SellInternal and BuyInternal point to this.
        /// </summary>
        /// <param name="amount">Amount of btc to be bought/sold.</param>
        /// <param name="price">Price to set for the order.</param>
        /// <param name="orderType">Can be either be "buy" or "sell".</param>
        /// <returns>String representation of the executed order.</returns>
        private string ExecuteOrder(decimal amount, decimal price, OrderType orderType)
        {
            KrakenRequest sellRequest = new KrakenRequest(_addOrderPath, _apiInfo);

            sellRequest.AddParameter("pair", _btcFiatPairSymbol);
            sellRequest.AddParameter("type", orderType.ToString().ToLower());     //Important note: Kraken api requires that the order type be lower case (else there will be an error), thus the ToLower().
            sellRequest.AddParameter("ordertype", "limit");
            sellRequest.AddParameter("price", price);
            sellRequest.AddParameter("volume", amount);
            sellRequest.AddSignatureHeader();

            Dictionary <string, dynamic> sellResponse = ApiPost(sellRequest);
            ArrayList transactionIdList = (ArrayList)GetValueFromResponseResult(sellResponse, "txid");

            return(StringManipulation.CreateDelimitedStringFromArrayList(transactionIdList, '|'));
        }
Exemplo n.º 6
0
        public override void DeleteOrder(string orderId)
        {
            //Build the request
            KrakenRequest deleteOrderRequest = new KrakenRequest(DeleteOrderPath, _apiInfo);

            deleteOrderRequest.AddParameter("txid", orderId);
            deleteOrderRequest.AddSignatureHeader();

            //Post the request
            Dictionary <string, dynamic> response = ApiPost(deleteOrderRequest);

            //Kraken should return a response indicating that exactly 1 order was deleted. If more than 1 was deleted, something went wrong.
            if ((int)GetValueFromResponseResult(response, "count") > 1)
            {
                throw new Exception("Delete for order " + orderId + " at " + Name + " resulted in more than 1 order being deleted.");
            }
        }
Exemplo n.º 7
0
        public override void UpdateBalances()
        {
            KrakenRequest request = new KrakenRequest(AccountBalanceInfoPath, _apiInfo);

            request.AddSignatureHeader();
            Dictionary <string, dynamic> response = ApiPost(request);

            //Get the BTC value from the response, convert it to a decimal and sign it to this exchange.
            TotalBtc = TypeConversion.ParseStringToDecimalLoose((string)GetValueFromResponseResult(response, "XXBT", true));

            switch (FiatTypeToUse)
            {
            case FiatType.Eur:
                TotalFiat = TypeConversion.ParseStringToDecimalLoose((string)GetValueFromResponseResult(response, "ZEUR", true));
                break;

            case FiatType.Usd:
                TotalFiat = TypeConversion.ParseStringToDecimalLoose((string)GetValueFromResponseResult(response, "ZUSD", true));
                break;
            }

            //The above returned the total amounts for fiat and btc. Need to get the open orders, and calculate the amount of currencies tied up
            CalculateAvailableCurrenciesFromOpenOrders();
        }