コード例 #1
0
        /// <summary>
        /// Used to retrieve the balance from your account for a specific currency.
        /// </summary>
        /// <param name="currency">equired	a string literal for the currency (ex: LTC)</param>
        /// <returns>The balance from your account for a specific currency</returns>
        public static Balance GetBalance(string currency)
        {
            string url = Constants.baseUrl + "account/getbalance?apikey=" + Constants.ApiKey + "&currency=" + currency + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    throw new ArgumentException("Unable to get data from API: " + response.message.ToString());
                }
            }

            if (response.result == null)
            {
                throw new NoCurrentBalancesException();
            }

            Balance b = null;

            string curr          = response.result.Currency.ToString();
            string balance       = response.result.Balance.ToString();
            string available     = response.result.Available.ToString();
            string pending       = response.result.Pending.ToString();
            string cryptoAddress = response.result.CryptoAddress.ToString();
            bool   requested     = Convert.ToBoolean(response.result.Requested);
            string uuid          = response.result.uuid;

            b = new Balance(curr, balance, available, pending, cryptoAddress, requested, uuid);


            return(b);
        }
コード例 #2
0
        /// <summary>
        /// Get all orders that you currently have opened. A specific market can be requested
        /// </summary>
        /// <param name="market">requires a string literal for the market (ex: BTC-LTC)</param>
        /// <returns>A list of open orders<returns>
        public static List <OpenOrder> GetOpenOrders(string market)
        {
            string url = Constants.baseUrl + "market/getopenorders?apikey=" + Constants.ApiKey + "&market=" + market + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    throw new Exception("Unable to get data from API: " + response.message.ToString());
                }
            }

            if (response.message == "INVALID_MARKET")
            {
                throw new ArgumentException("This is not a valid market. Use GetMarkets() to get a list of valid markets.");
            }

            List <OpenOrder> openOrdersList = new List <OpenOrder>();

            if (response.result == null)
            {
                throw new NoOpenOrdersException();
            }
            else
            {
                foreach (var item in response.result)
                {
                    string   uuid              = item.Uuid.ToString();
                    string   orderUuid         = item.OrderUuid.ToString();
                    string   exchange          = item.Exchange.ToString();
                    string   orderType         = item.OrderType.ToString();
                    double   quantity          = Convert.ToDouble(item.Quantity);
                    double   quantityRemaining = Convert.ToDouble(item.QuantityRemaining);
                    double   limit             = Convert.ToDouble(item.Limit);
                    double   commissionPaid    = Convert.ToDouble(item.CommissionPaid);
                    double   price             = Convert.ToDouble(item.Price);
                    string   pricePerUnit      = item.PricePerUnit.ToString();
                    DateTime opened            = Convert.ToDateTime(item.Opened);
                    string   closed            = item.Closed.ToString();
                    bool     cancelInitiated   = Convert.ToBoolean(item.CancelInitiated);
                    bool     immediateOrCancel = Convert.ToBoolean(item.ImmediateOrCancel);
                    bool     isConditional     = Convert.ToBoolean(item.IsConditional);
                    string   condition         = item.Condition.ToString();
                    string   conditionTarget   = item.ConditionTarget.ToString();

                    OpenOrder openOrder = new OpenOrder(uuid, orderUuid, exchange, orderType, quantity, quantityRemaining, limit, commissionPaid, price, pricePerUnit, opened, closed,
                                                        cancelInitiated, immediateOrCancel, isConditional, condition, conditionTarget);

                    openOrdersList.Add(openOrder);
                }
            }
            return(openOrdersList);
        }
コード例 #3
0
        /// <summary>
        /// Used to cancel a buy or sell order.
        /// </summary>
        /// <param name="uuid">The uuid of the order you want to cancel</param>
        public static void CancelOrder(string uuid)
        {
            string url = Constants.baseUrl + "market/cancel?apikey=" + Constants.ApiKey + "&uuid=" + uuid + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == "false")
            {
                Console.WriteLine("*Unable to cancel order" + "\n" +
                                  "Error: " + response.message
                                  );
                return;
            }

            Console.WriteLine("Order: " + uuid + " has been canceled");
        }
コード例 #4
0
        /// <summary>
        /// Used to place a sell order in a specific market. Use selllimit to place limit orders. Make sure you have the proper permissions set on your API keys for this call to work
        /// </summary>
        /// <param name="market">requires a string literal for the market (ex: BTC-LTC)</param>
        /// <param name="quantity">Amount of coins to buy</param>
        /// <param name="rate">The rate per coin</param>
        /// <returns>The UUID for the sell order<returns>
        public static string PlaceSellLimitOrder(string market, double quantity, double rate)
        {
            string url = Constants.baseUrl + "market/selllimit?apikey=" + Constants.ApiKey + "&market=" + market + "&quantity=" +
                         quantity.ToString() + "&rate=" + rate.ToString() + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == "false")
            {
                throw new ArgumentException("Unable to place sell limit order: " + response.message.ToString());
            }

            Console.WriteLine("Sell limit order placed: " + response.result.ToString());

            return(response.result.ToString());
        }
コード例 #5
0
        /// <summary>
        /// Used to retrieve a single order by uuid.
        /// </summary>
        /// <param name="uuid">The uuid of the buy or sell order</param>
        /// <returns>The details of an specific order</returns>
        public static AccountOrder GetOrder(string uuid)
        {
            string url = Constants.baseUrl + "account/getorder&uuid=" + uuid + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    Console.WriteLine("*Unable to get balances" + "\n" +
                                      "Error: " + response.message + "\n"
                                      );
                    throw new Exception("Unable to get data from API: " + response.message.ToString());
                }
            }

            string accountId                   = response.result.AccountId.ToString();
            string orderUuid                   = response.result.OrderUuid.ToString();
            string exchange                    = response.result.Exchange.ToString();
            string type                        = response.result.Type.ToString();
            string quantity                    = response.result.Quantity.ToString();
            string quantityRemaing             = response.result.QuantityRemaining.ToString();
            string limit                       = response.result.Limit.ToString();
            string reserved                    = response.result.Reserved.ToString();
            string reservedRemaining           = response.result.ReservedRemaining.ToString();
            string commissionReserved          = response.result.ReserveRemaining.ToString();
            string commissionReservedRemaining = response.result.CommissionReserveRemaining.ToString();
            string commissionPaid              = response.result.CommissionPaid.ToString();
            string price                       = response.result.Price.ToString();
            string pricePerUnit                = response.result.PricePerUnit.ToString();
            string opened                      = response.result.Opened.ToString();
            string closed                      = response.result.Closed.ToString();
            string isOpen                      = response.result.IsOpen.ToString();
            string sentinel                    = response.result.Sentinel.ToString();
            string cancelInitiated             = response.result.CancelInitiated.ToString();
            string immediateOrCancel           = response.result.ImmediateOrCancel.ToString();
            string isConditional               = response.result.IsConditional.ToString();
            string condiition                  = response.result.Condition.ToString();
            string conditionTarget             = response.result.ConditionTarget.ToString();

            AccountOrder order = new AccountOrder(accountId, orderUuid, exchange, type, quantity, quantityRemaing, limit, reserved, reservedRemaining, commissionReserved,
                                                  commissionReservedRemaining, commissionPaid, price, pricePerUnit, opened, closed, isOpen, sentinel, cancelInitiated, immediateOrCancel, isConditional, condiition, conditionTarget);

            return(order);
        }
コード例 #6
0
        /// <summary>
        /// Used to retrieve your order history for a specific market.
        /// </summary>
        /// <param name="market">a string literal for the market (ie. BTC-LTC).</param>
        /// <returns></returns>
        public static List <HistoryOrder> GetOrderHistory(string market)
        {
            List <HistoryOrder> historyOrdersList = new List <HistoryOrder>();

            string url = Constants.baseUrl + "account/getorderhistory?apikey=" + Constants.ApiKey + "&market=" + market + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    Console.WriteLine("*Unable to get balances" + "\n" +
                                      "Error: " + response.message + "\n"
                                      );
                    throw new Exception("Unable to get data from API: " + response.message.ToString());
                }
            }

            foreach (var item in response.result)
            {
                string orderUuid         = item.OrderUuid.ToString();
                string exchange          = item.Exchange.ToString();
                string timeStamp         = item.TimeStamp.ToString();
                string ordertype         = item.OrderType.ToString();
                string limit             = item.Limit.ToString();
                string quantity          = item.Quantity.ToString();
                string quantityRemaining = item.QuantityRemaining.ToString();
                string commission        = item.Commission.ToString();
                string price             = item.Price.ToString();
                string pricePerUnit      = item.PricePerUnit.ToString();
                string isConditional     = item.IsConditional.ToString();
                string condition         = item.Condition.ToString();
                string conditionTarget   = item.ConditionTarget.ToString();
                string immediateOrCancel = item.ImmediateOrCancel.ToString();

                HistoryOrder order = new HistoryOrder(orderUuid, exchange, timeStamp, ordertype, limit, quantity, quantityRemaining, commission, price, pricePerUnit, isConditional, condition, conditionTarget,
                                                      immediateOrCancel);

                historyOrdersList.Add(order);
            }

            return(historyOrdersList);
        }
コード例 #7
0
        /// <summary>
        /// Used to withdraw funds from your account. note: please account for txfee.
        /// </summary>
        /// <param name="currency">A string literal for the currency (ie. BTC)</param>
        /// <param name="quantity">The quantity of coins to withdraw</param>
        /// <param name="address">The address to send the funds to</param>
        /// <returns>The UUID of the transcation</returns>
        public static string Withdraw(string currency, double quantity, string address)
        {
            string url = Constants.baseUrl + "account/withdraw?apikey=" + Constants.ApiKey + "&currency=" + currency + "&quantity=" + quantity + "&address=" + address + " & nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    Console.WriteLine("*Unable to get balances" + "\n" +
                                      "Error: " + response.message + "\n"
                                      );
                    throw new Exception("Unable to get data from API: " + response.message.ToString());
                }
            }

            return(response.result.uuid.ToString());
        }
コード例 #8
0
        /// <summary>
        /// Used to retrieve or generate an address for a specific currency. If one does not exist, the call will fail and return ADDRESS_GENERATING until one is available.
        /// </summary>
        /// <param name="currency">required	a string literal for the currency (ie. BTC)</param>
        /// <returns>The address, or if the call fails will return ADDRESS_GENERATING until address is available</returns>
        public static string GetDepositAddress(string currency)
        {
            string url = Constants.baseUrl + "account/getdepositaddress?apikey=" + Constants.ApiKey + "&currency=" + currency + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    Console.WriteLine("*Unable to get balances" + "\n" +
                                      "Error: " + response.message + "\n"
                                      );
                    throw new Exception("Unable to get data from API: " + response.message.ToString());
                }
            }

            return(response.result.address.ToString());
        }
コード例 #9
0
        /// <summary>
        /// Used to retrieve all balances from your account
        /// </summary>
        /// <returns>A list of balances</returns>
        public static List <Balance> GetBalances()
        {
            List <Balance> balanceList = new List <Balance>();

            string url = Constants.baseUrl + "account/getbalances?apikey=" + Constants.ApiKey + "&nonce=" + nonce;

            dynamic response = JsonConvert.DeserializeObject(HTTPMethods.HttpSignAndGet(url));

            if (response.success == false)
            {
                if (response.success == "false")
                {
                    throw new Exception("Unable to get data from API: " + response.message.ToString());
                }
            }

            if (response.result == null)
            {
                throw new NoCurrentBalancesException();
            }

            foreach (var item in response.result)
            {
                string currency      = item.Currency.ToString();
                string balance       = item.Balance.ToString();
                string available     = item.Available.ToString();
                string pending       = item.Pending.ToString();
                string cryptoAddress = item.CryptoAddress.ToString();
                bool   requested     = Convert.ToBoolean(item.Requested);
                string uuid          = item.uuid;

                Balance b = new Balance(currency, balance, available, pending, cryptoAddress, requested, uuid);

                balanceList.Add(b);
            }

            return(balanceList);
        }