예제 #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);
        }
예제 #2
0
        public ImageOptimizationResponse ProcessImage(ImageOptimizationRequest imageOptimizationRequest)
        {
            try
            {
                if (imageOptimizationRequest == null)
                {
                    return(new ImageOptimizationResponse());
                }

                var ParentAuth = new Auth
                {
                    api_key    = ImageOptimizationSettings.Instance.ApiKey,
                    api_secret = ImageOptimizationSettings.Instance.ApiSecret
                };

                string strimage_url = imageOptimizationRequest.ImageUrl;


                var krakenRequest = new KrakenRequest
                {
                    auth  = ParentAuth,
                    url   = strimage_url,
                    wait  = true,
                    lossy = true
                };
                KrakenResponse krakenResponse = this._krakenProxy.ProcessImage(krakenRequest);

                return(krakenResponse.ConvertToResponse());
            }catch (Exception exception)
            {
                Debug.WriteLine(exception.ToString());
                throw new Exception(exception.Message);
            }
        }
예제 #3
0
        public KrakenResponse ProcessImage(KrakenRequest krakenRequest)
        {
            try

            {
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(KrakenRequest));
                MemoryStream mem = new MemoryStream();
                ser.WriteObject(mem, krakenRequest);

                string jsonString = Encoding.Default.GetString(mem.ToArray());

                _webClient.Headers["Content-type"] = "application/json";

                string result = _webClient.UploadString("https://api.kraken.io/v1/url", "POST", jsonString);

                var json_serializer = new JavaScriptSerializer();
                var response        = json_serializer.Deserialize <KrakenResponse>(result);

                return(response);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.ToString());
                throw new Exception(exception.Message);
            }
        }
예제 #4
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"));
        }
예제 #5
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);
        }
예제 #6
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"));
        }
예제 #7
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, '|'));
        }
예제 #8
0
        public override void UpdateOrderBook(int?maxSize = null)
        {
            KrakenRequest request = new KrakenRequest(OrderBookPath);

            request.AddParameter("pair", _btcFiatPairSymbol);

            if (maxSize != null)
            {
                request.AddParameter("count", maxSize.Value);
            }

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

            response = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, _btcFiatPairSymbol);
            BuildOrderBook(response, 1, 0, maxSize);
        }
예제 #9
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.");
            }
        }
        public override Stream CompressImageData(Image image, Stream imageData, out string optimizedExtension)
        {
            KrakenRequest krakenRequest = new KrakenRequest();

            krakenRequest.Lossy = _useLossy;

            if (_useCallbacks)
            {
                krakenRequest.CallbackUrl = _callbackUrl;
            }
            else
            {
                krakenRequest.Wait = true;
            }

            krakenRequest.File = ((MemoryStream)imageData).ToArray();

            var response = _krakenClient.Upload(krakenRequest, image.Id.ToString(), image.Extension);

            if (_useCallbacks)
            {
                Kraken.KrakenCallbackIds.Add(response.Id, image.Album.Id);

                optimizedExtension = "";
                return(null);
            }
            else
            {
                if (response.Success == false || response.Error != null)
                {
                    optimizedExtension = "";
                    return(null);
                }

                using (var webClient = new WebClient())
                {
                    var stream = webClient.OpenRead(response.KrakedUrl);

                    optimizedExtension = Path.GetExtension(response.KrakedUrl);
                    return(stream);
                }
            }
        }
예제 #11
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();
        }