Пример #1
0
        public override void DeleteOrder(string orderId)
        {
            OkCoinRequest deleteOrderRequest = new OkCoinRequest(DeleteOrderPath, _apiInfo);

            deleteOrderRequest.AddParameter("api_key", _apiInfo.Key);
            deleteOrderRequest.AddParameter("order_id", orderId);
            deleteOrderRequest.AddParameter("symbol", _btcFiatPairSymbol);
            deleteOrderRequest.AddSignatureHeader();

            ApiPost(deleteOrderRequest);
        }
Пример #2
0
        /// <summary>
        /// With Okcoin, 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)
        {
            OkCoinRequest buyRequest = new OkCoinRequest(_addOrderPath, _apiInfo);

            buyRequest.AddParameter("amount", amount);
            buyRequest.AddParameter("api_key", ApiInfo.Key);
            buyRequest.AddParameter("price", price);
            buyRequest.AddParameter("symbol", _btcFiatPairSymbol);
            buyRequest.AddParameter("type", orderType.ToString().ToLower());

            buyRequest.AddSignatureHeader();

            //Make the api call
            Dictionary <string, dynamic> response = ApiPost(buyRequest);

            //Get order id from the response
            return(((int)GetValueFromResponseResult(response, "order_id")).ToString());
        }
Пример #3
0
        public override List <Dictionary <string, dynamic> > GetAllOpenOrders()
        {
            OkCoinRequest orderInfoRequest = new OkCoinRequest(OpenOrderPath, ApiInfo);

            orderInfoRequest.AddParameter("api_key", _apiInfo.Key);
            orderInfoRequest.AddParameter("order_id", "-1");
            orderInfoRequest.AddParameter("symbol", _btcFiatPairSymbol);
            orderInfoRequest.AddSignatureHeader();

            Dictionary <string, dynamic> response = ApiPost(orderInfoRequest);
            ArrayList orders = (ArrayList)GetValueFromResponseResult(response, "orders");

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

            return(orders.Cast <Dictionary <string, dynamic> >().ToList());
        }
Пример #4
0
        public override Dictionary <string, dynamic> GetOrderInformation(string orderId)
        {
            OkCoinRequest orderInfoRequest = new OkCoinRequest(OrderQueryPath, ApiInfo);

            orderInfoRequest.AddParameter("api_key", _apiInfo.Key);
            orderInfoRequest.AddParameter("order_id", orderId);
            orderInfoRequest.AddParameter("symbol", _btcFiatPairSymbol);
            orderInfoRequest.AddSignatureHeader();

            Dictionary <string, dynamic> response = ApiPost(orderInfoRequest);
            ArrayList orders = (ArrayList)GetValueFromResponseResult(response, "orders");

            if (orders.Count <= 0)
            {
                throw new Exception("Could not find order with id '" + orderId + ".");
            }

            //The array list should only have one order, which the given id. So just return the first one in the array.
            return((Dictionary <string, dynamic>)orders[0]);
        }
Пример #5
0
        public override void UpdateOrderBook(int?maxSize = null)
        {
            OkCoinRequest orderBookRequest = new OkCoinRequest(OrderBookPath);

            //If a max size was provided, add it as parameter
            if (maxSize != null)
            {
                orderBookRequest.AddParameter("size", maxSize);
            }

            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.");
            }

            //OkCoin returns the asks list in the wrong order (with best ask being at the end of the list), so reverse it
            ((ArrayList)response["asks"]).Reverse();

            BuildOrderBook(response, 1, 0, maxSize);
        }
Пример #6
0
        public override void UpdateBalances()
        {
            OkCoinRequest request = new OkCoinRequest(AccountBalanceInfoPath, _apiInfo);

            request.AddParameter("api_key", _apiInfo.Key);
            request.AddSignatureHeader();

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

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

            Dictionary <string, dynamic> freeAssets   = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, "free");
            Dictionary <string, dynamic> frozenAssets = (Dictionary <string, dynamic>)GetValueFromResponseResult(response, "freezed");

            AvailableFiat = TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(freeAssets, FiatTypeToUse.ToString().ToLower()));
            AvailableBtc  = TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(freeAssets, "btc"));

            //Calculate total balances by adding the 'free' and 'frozen' assets
            TotalFiat = AvailableFiat + TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(frozenAssets, FiatTypeToUse.ToString().ToLower()));
            TotalBtc  = AvailableBtc + TypeConversion.ParseStringToDecimalStrict((string)GetValueFromResponseResult(frozenAssets, "btc"));
        }