public Asset[] GetAssets()
        {
            string    response = QueryPublic("Assets");
            ObjResult result   = JsonConvert.DeserializeObject <ObjResult>(response);


            List <Asset> assets = new List <Asset>();

            foreach (JProperty property in result.Result.Children())
            {
                try
                {
                    Asset asset = JsonConvert.DeserializeObject <Asset>(property.Value.ToString());
                    asset.Name = property.Name;
                    assets.Add(asset);
                }
                catch
                {
                    continue;
                }
            }

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

            return(assets.ToArray());
        }
Exemple #2
0
        /// <summary>
        /// Get tradable asset pairs
        /// </summary>
        /// <returns></returns>
        public AssetPair[] GetAssetPairs()
        {
            string response = QueryPublic("AssetPairs");

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            List <AssetPair> values = new List <AssetPair>();

            foreach (JProperty property in result.Result.Children())
            {
                try
                {
                    AssetPair value = JsonConvert.DeserializeObject <AssetPair>(property.Value.ToString());
                    value.Name = property.Name;
                    values.Add(value);
                }
                catch (Exception ex)
                {
                    ex.ToOutput();
                    continue;
                }
            }

            return(values.ToArray());
        }
        public void GetLedgers(string aclass = "currency", string asset = "all", string type = "all", string start = null, string end = null, string ofs = null)
        {
            string props = "";

            if (!ofs.IsNullOrEmpty())
            {
                props += string.Format("&ofs={0}", ofs);
            }
            if (!aclass.IsNullOrEmpty())
            {
                props += string.Format("&aclass={0}", aclass);
            }
            if (!type.IsNullOrEmpty())
            {
                props += string.Format("&type={0}", type);
            }
            if (!start.IsNullOrEmpty())
            {
                props += string.Format("&start={0}", start);
            }
            if (!end.IsNullOrEmpty())
            {
                props += string.Format("&end={0}", end);
            }

            string response = this.QueryPrivate("Ledgers", props);

            if (response == null)
            {
                return;
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return;
            }

            /* List<Ticker> values = new List<Ticker>();
             * foreach (JProperty property in result.Result.Children())
             * {
             *   try
             *   {
             *       Ticker value = JsonConvert.DeserializeObject<Ticker>(property.Value.ToString());
             *       value.Name = property.Name;
             *       values.Add(value);
             *   }
             *   catch(Exception ex)
             *   {
             *       ex.ToOutput();
             *       continue;
             *   }
             * }
             */
            return;
        }
Exemple #4
0
        public Ticker[] GetTickers(AssetPair[] pairs)
        {
            if (pairs == null)
            {
                return(null);
            }
            if (pairs.Count() == 0)
            {
                return(null);
            }

            StringBuilder pairString = new StringBuilder("pair=");

            foreach (var item in pairs)
            {
                pairString.Append(item.Name + ",");
            }
            pairString.Length--; //disregard trailing comma



            string response = QueryPublic("Ticker", pairString.ToString());

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            List <Ticker> values = new List <Ticker>();

            foreach (JProperty property in result.Result.Children())
            {
                try
                {
                    Ticker value = JsonConvert.DeserializeObject <Ticker>(property.Value.ToString());
                    value.Name = property.Name;
                    values.Add(value);
                }
                catch (Exception ex)
                {
                    ex.ToOutput();
                    continue;
                }
            }

            return(values.ToArray());
        }
        public OrderBook GetOrderBook(AssetPair pair, int?count = null)
        {
            string props = string.Format("pair={0}", pair.Name);

            if (count != null)
            {
                props += string.Format("&count={0}", count.Value);
            }

            string response = QueryPublic("Depth", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            List <OrderBook> values = new List <OrderBook>();

            foreach (JProperty property in result.Result.Children())
            {
                OrderBook book = JsonConvert.DeserializeObject <OrderBook>(property.Value.ToString());
                book.Name = property.Name;

                book.Asks = new OrderBookEntry[book.asks.Length];
                book.Bids = new OrderBookEntry[book.bids.Length];

                for (int i = 0; i < book.asks.Length; i++)
                {
                    book.Asks[i] = new OrderBookEntry(book.asks[i]);
                }

                for (int i = 0; i < book.bids.Length; i++)
                {
                    book.Bids[i] = new OrderBookEntry(book.bids[i]);
                }

                values.Add(book);
            }

            return(values[0]);
        }
        public TradeBalance GetTradeBalance(string aclass = "currency", string asset = "ZUSD")
        {
            string props = "";

            if (!aclass.IsNullOrEmpty())
            {
                props += string.Format("&aclass={0}", aclass);
            }

            if (!asset.IsNullOrEmpty())
            {
                props += string.Format("&asset={0}", asset);
            }



            string response = this.QueryPrivate("TradeBalance", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            /* List<Ticker> values = new List<Ticker>();
             * foreach (JProperty property in result.Result.Children())
             * {
             *   try
             *   {
             *       Ticker value = JsonConvert.DeserializeObject<Ticker>(property.Value.ToString());
             *       value.Name = property.Name;
             *       values.Add(value);
             *   }
             *   catch(Exception ex)
             *   {
             *       ex.ToOutput();
             *       continue;
             *   }
             * }
             */
            return(null);
        }
        public void GetQueryLedgers(List <string> ids)
        {
            if (ids.Count > 20)
            {
                throw new Exception("Ledgers amount max is 20.");
            }


            string props = string.Format("&id={0}", ids[0]);


            for (int i = 1; i < ids.Count; i++)
            {
                props += "," + ids[i];
            }

            string response = this.QueryPrivate("Ledgers", props);

            if (response == null)
            {
                return;
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return;
            }

            /* List<Ticker> values = new List<Ticker>();
             * foreach (JProperty property in result.Result.Children())
             * {
             *   try
             *   {
             *       Ticker value = JsonConvert.DeserializeObject<Ticker>(property.Value.ToString());
             *       value.Name = property.Name;
             *       values.Add(value);
             *   }
             *   catch(Exception ex)
             *   {
             *       ex.ToOutput();
             *       continue;
             *   }
             * }
             */
            return;
        }
        public void GetTradesHistory(string type = "all", bool trades = false, string start = null, string end = null, string ofs = null)
        {
            string props = string.Format("&ofs={0}&type={1}&trades={2}", ofs, type, trades);

            if (!start.IsNullOrEmpty())
            {
                props += string.Format("&start={0}", start);
            }
            if (!end.IsNullOrEmpty())
            {
                props += string.Format("&end={0}", start);
            }


            string response = this.QueryPrivate("TradesHistory", props);

            if (response == null)
            {
                return;
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return;
            }

            /* List<Ticker> values = new List<Ticker>();
             * foreach (JProperty property in result.Result.Children())
             * {
             *   try
             *   {
             *       Ticker value = JsonConvert.DeserializeObject<Ticker>(property.Value.ToString());
             *       value.Name = property.Name;
             *       values.Add(value);
             *   }
             *   catch(Exception ex)
             *   {
             *       ex.ToOutput();
             *       continue;
             *   }
             * }
             */
            return;
        }
Exemple #9
0
        public Trades GetTrades(AssetPair pair, string since = null)
        {
            string props = string.Format("pair={0}", pair.Name);

            if (since != null)
            {
                props += string.Format("&since={0}", since);
            }

            string response = QueryPublic("Trades", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }


            JToken[]  tokens = result.Result.Children().ToArray();
            JProperty jpair  = (JProperty)tokens[0];
            JProperty jlast  = (JProperty)tokens[1];

            object[][] records = JsonConvert.DeserializeObject <object[][]>(jpair.Value.ToString());

            Trades trades = new Trades();

            trades.Name = jpair.Name;
            trades.Last = jlast.Value.ToString();

            List <TradeEntry> entries = new List <TradeEntry>();

            foreach (object[] record in records)
            {
                entries.Add(new TradeEntry(record));
            }

            trades.Entries = entries.ToArray();

            return(trades);
        }
        public Balance[] GetBalance()
        {
            string response = null;

            try
            {
                response = this.QueryPrivate("Balance");
            }
            catch (Exception ex)
            {
                ex.ToOutput();
                response = null;
            }

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            List <Balance> values = new List <Balance>();

            foreach (JProperty property in result.Result.Children())
            {
                try
                {
                    Balance value = new Balance();
                    value.AssetName     = property.Name;
                    value.BalanceAmount = decimal.Parse(property.Value.ToString());
                    values.Add(value);
                }
                catch (Exception ex)
                {
                    ex.ToOutput();
                    continue;
                }
            }

            return(values.ToArray());
        }
Exemple #11
0
        /// <summary>
        /// Get public server time
        /// This is to aid in approximatig the skew time between the server and client
        /// </summary>
        /// <returns></returns>
        public TickTime GetServerTime()
        {
            string response = null;

            try
            {
                response = QueryPublic("Time");
            }
            catch (Exception ex)
            {
                ex.ToOutput();
                return(TickTime.Default);
            }

            ObjResult     result     = JsonConvert.DeserializeObject <ObjResult>(response);
            ObjServerTime servertime = JsonConvert.DeserializeObject <ObjServerTime>(result.Result.ToString());

            return(servertime.TickTime);
        }
Exemple #12
0
        /// <summary>
        /// Get open orders
        /// </summary>
        /// <param name="trades">whether or not to include trades in output (optional.  default = false)</param>
        /// <param name="userref">restrict results to given user reference id (optional)</param>
        /// <returns></returns>
        public TradeBalance GetOpenOrders(bool trades = false, string userref = null)
        {
            string props = string.Format("&trades={0}", trades);

            if (!userref.IsNullOrEmpty())
            {
                props += string.Format("&userref={0}", userref);
            }



            string response = this.QueryPrivate("OpenOrders", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            /* List<Ticker> values = new List<Ticker>();
             * foreach (JProperty property in result.Result.Children())
             * {
             *   try
             *   {
             *       Ticker value = JsonConvert.DeserializeObject<Ticker>(property.Value.ToString());
             *       value.Name = property.Name;
             *       values.Add(value);
             *   }
             *   catch(Exception ex)
             *   {
             *       ex.ToOutput();
             *       continue;
             *   }
             * }
             */
            return(null);
        }
        /// <summary>
        /// Cancel open order
        /// </summary>
        /// <param name="txid">txid = transaction id</param>
        /// <returns></returns>
        public CancelOrderInfo CancelOrder(string txid)
        {
            string props = string.Format("&txid={0}", txid);


            string response = this.QueryPrivate("CancelOrder", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            CancelOrderInfo info = JsonConvert.DeserializeObject <CancelOrderInfo>(result.Result.ToString());

            return(info);
        }
        public void GetOpenPositions(string txid = null, bool trades = false)
        {
            string props = string.Format("&txid={0}&trades={1}", txid, trades);

            string response = this.QueryPrivate("OpenPositions", props);

            if (response == null)
            {
                return;
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return;
            }

            /* List<Ticker> values = new List<Ticker>();
             * foreach (JProperty property in result.Result.Children())
             * {
             *   try
             *   {
             *       Ticker value = JsonConvert.DeserializeObject<Ticker>(property.Value.ToString());
             *       value.Name = property.Name;
             *       values.Add(value);
             *   }
             *   catch(Exception ex)
             *   {
             *       ex.ToOutput();
             *       continue;
             *   }
             * }
             */
            return;
        }
        /// <summary>
        /// Withdraw funds
        /// </summary>
        /// <param name="asset">asset being withdrawn</param>
        /// <param name="key">withdrawal key name, as set up on your account</param>
        /// <param name="amount">amount to withdraw, including fees</param>
        /// <param name="aclass">asset class (optional): currency(default)</param>
        /// <returns></returns>
        public Withdraw GetWithdraw(string asset, string key, decimal amount, string aclass = "currency")
        {
            string props = string.Format("&asset={0}&key={1}&amount={2}&aclass={3}", asset, key, amount, aclass);

            string response = this.QueryPrivate("Withdraw", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }


            Withdraw withdraw = JsonConvert.DeserializeObject <Withdraw>(result.Result.ToString());


            return(withdraw);
        }
Exemple #16
0
        /// <summary>
        /// Default interval = 1
        /// since = return committed OHLC data since given id (optional.  exclusive)
        ///
        /// The last entry in the OHLC array is for the current, not-yet-committed frame and will always be present, regardless of the value of "since".
        /// </summary>
        /// <param name="pair"></param>
        /// <param name="interval"></param>
        /// <param name="since"></param>
        /// <returns></returns>
        public OHLC GetOHLC(string pair, OHLC.Interval interval = OHLC.Interval._1m, string since = null)
        {
            string props = string.Format("pair={0}", pair);

            props += string.Format("&interval={0}", (int)interval);


            if (since != null)
            {
                props += string.Format("&since={0}", since);
            }

            string response = QueryPublic("OHLC", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }

            OHLC ohlc = JsonConvert.DeserializeObject <OHLC>(result.Result.ToString());

            //OHLC ohlc = new OHLC();
            foreach (JProperty property in result.Result.Children())
            {
                try
                {
                    if (property.Name != pair)
                    {
                        continue;
                    }

                    ohlc.PairName = pair;

                    if (property.Value == null)
                    {
                        continue;
                    }

                    decimal[][] value = JsonConvert.DeserializeObject <decimal[][]>(property.Value.ToString());

                    List <OHLCEntry> entries = new List <OHLCEntry>();
                    foreach (decimal[] array in value)
                    {
                        if (array.IsNullOrEmpty())
                        {
                            continue;
                        }

                        OHLCEntry entry = new OHLCEntry();
                        entry.Entry = array;
                        entries.Add(entry);
                    }


                    ohlc.Entries = entries.ToArray();

                    break;
                }
                catch (Exception ex)
                {
                    ex.ToOutput();
                    continue;
                }
            }


            return(ohlc);
        }
        public OrderInfo[] GetClosedOrders(bool trades = false, string userref = null, string start = null, string end = null, string ofs = null, string closetime = null)
        {
            string props = string.Format("&trades={0}", trades.ToString().ToLower());

            if (!userref.IsNullOrEmpty())
            {
                props += string.Format("&userref={0}", userref);
            }
            if (!start.IsNullOrEmpty())
            {
                props += string.Format("&start={0}", start);
            }
            if (!end.IsNullOrEmpty())
            {
                props += string.Format("&end={0}", end);
            }
            if (!ofs.IsNullOrEmpty())
            {
                props += string.Format("&ofs={0}", ofs);
            }
            if (!closetime.IsNullOrEmpty())
            {
                props += string.Format("&closetime={0}", closetime);
            }

            string response = this.QueryPrivate("ClosedOrders", props);

            if (response.IsNullOrWhiteSpace())
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (!result.Error.IsNullOrEmpty())
            {
                return(null);
            }

            JProperty closed = (JProperty)result.Result.Children().First();

            if (closed.Name.ToLower() != "closed")
            {
                return(null);
            }

            List <OrderInfo> list = new List <OrderInfo>();

            foreach (JProperty property in closed.Value.Children())
            {
                try
                {
                    OrderInfo info = JsonConvert.DeserializeObject <OrderInfo>(property.Value.ToString());

                    if (info == null)
                    {
                        continue;
                    }

                    info.ID = property.Name;
                    list.Add(info);
                }
                catch (Exception ex)
                {
                    ex.ToOutput();
                    continue;
                }
            }

            return(list.ToArray());
        }
        public TransactionOrder AddOrder(
            string pair,
            string type,
            string ordertype,
            decimal volume,
            decimal?price,
            decimal?price2,
            string leverage = "none",
            string oflags   = null,
            string starttm  = null,
            string expiretm = null,
            string userref  = null,
            bool validate   = false,
            Dictionary <string, string> close = null
            )
        {
            string props = string.Format("&pair={0}&type={1}&ordertype={2}&volume={3}&leverage={4}", pair, type, ordertype, volume, leverage);

            if (price.HasValue)
            {
                props += string.Format("&price={0}", price.Value);
            }
            if (price2.HasValue)
            {
                props += string.Format("&price2={0}", price2.Value);
            }
            if (!string.IsNullOrEmpty(oflags))
            {
                props += string.Format("&oflags={0}", oflags);
            }
            if (!string.IsNullOrEmpty(starttm))
            {
                props += string.Format("&starttm={0}", starttm);
            }
            if (!string.IsNullOrEmpty(expiretm))
            {
                props += string.Format("&expiretm={0}", expiretm);
            }
            if (!string.IsNullOrEmpty(userref))
            {
                props += string.Format("&userref={0}", userref);
            }
            if (validate)
            {
                props += "&validate=true";
            }

            if (close != null)
            {
                string closeString = string.Format("&close[ordertype]={0}&close[price]={1}&close[price2]={2}", close["ordertype"], close["price"], close["price2"]);
                props += closeString;
            }


            string           response = this.QueryPrivate("AddOrder", props);
            TransactionOrder order;

            if (response.IsNullOrEmpty())
            {
                order       = new TransactionOrder();
                order.Error = "Could not recognize order result, or server havn't responded in due time.";
                return(order);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (!result.Error.IsNullOrEmpty())
            {
                order       = new TransactionOrder();
                order.Error = result.Error.ToArray()[0].ToString();
                return(order);
            }

            order = JsonConvert.DeserializeObject <TransactionOrder>(result.Result.ToString());

            return(order);
        }
Exemple #19
0
        public TradeVolume GetTradeVolume(List <string> pairs = null, bool feeinfo = false)
        {
            string props = "";

            if (pairs != null)
            {
                props = string.Format("&pair={0}", pairs[0]);


                for (int i = 1; i < pairs.Count; i++)
                {
                    props += "," + pairs[i];
                }
            }

            if (feeinfo)
            {
                props += string.Format("&fee-info={0}", feeinfo);
            }


            string response = this.QueryPrivate("TradeVolume", props);

            if (response == null)
            {
                return(null);
            }

            ObjResult result = JsonConvert.DeserializeObject <ObjResult>(response);

            if (result.Error == null || result.Error.Count > 0)
            {
                return(null);
            }



            TradeVolume volume = JsonConvert.DeserializeObject <TradeVolume>(result.Result.ToString());

            List <TradeFees> tradefees = new List <TradeFees>();

            foreach (JProperty property in volume.fees.Children())
            {
                if (property == null || property.Value == null)
                {
                    continue;
                }
                try
                {
                    TradeFees tradefee = JsonConvert.DeserializeObject <TradeFees>(property.Value.ToString());
                    tradefee.PairName = property.Name;
                    tradefees.Add(tradefee);
                }
                catch
                {
                    continue;
                }
            }

            volume.Fees = tradefees.ToArray();


            List <TradeFees> tradefees_maker = new List <TradeFees>();

            foreach (JProperty property in volume.fees_maker.Children())
            {
                if (property == null || property.Value == null)
                {
                    continue;
                }

                try
                {
                    TradeFees tradefee = JsonConvert.DeserializeObject <TradeFees>(property.Value.ToString());
                    tradefee.PairName = property.Name;
                    tradefees_maker.Add(tradefee);
                }
                catch
                {
                    continue;
                }
            }


            volume.FeesMaker = tradefees_maker.ToArray();

            return(volume);
        }