Пример #1
0
        public static List <MyTrade> ParseOrderExecutions(JObject responseJson)
        {
            int             numberOrderExecutions = responseJson.Value <int>("numberorderexecutions");
            VircurexOrderId orderId = new VircurexOrderId(responseJson.Value <int>("orderid"));
            List <MyTrade>  trades  = new List <MyTrade>(numberOrderExecutions);

            // Parses a trade such as:
            // "currency1": "DOGE",
            // "currency2": "BTC",
            // "quantity": "57796.176",
            // "unitprice": "0.0000025",
            // "feepaid": "115.592352",
            // "ordertype": "BUY",
            // "executed_at": "2014-02-14T15:17:08+00:00"

            for (int orderExecutionIdx = 1; orderExecutionIdx <= numberOrderExecutions; orderExecutionIdx++)
            {
                JObject          orderExecutionJson = responseJson.Value <JObject>("orderexecution-" + orderExecutionIdx);
                DateTime         executed           = orderExecutionJson.Value <DateTime>("executed_at");
                VircurexMarketId marketId           = new VircurexMarketId(orderExecutionJson.Value <string>("currency1"),
                                                                           orderExecutionJson.Value <string>("currency2"));
                OrderType orderType
                    = orderExecutionJson.Value <string>("ordertype").Equals(Enum.GetName(typeof(OrderType), OrderType.Buy).ToUpper())
                    ? OrderType.Buy
                    : OrderType.Sell;

                trades.Add(new MyTrade(new VircurexFakeTradeId(orderId, orderExecutionIdx), orderType,
                                       executed, orderExecutionJson.Value <decimal>("unitprice"), orderExecutionJson.Value <decimal>("feepaid"),
                                       orderExecutionJson.Value <decimal>("quantity"), marketId, orderId));
            }

            return(trades);
        }
Пример #2
0
        public async Task <Model.Book> GetMarketDepth(MarketId marketId)
        {
            VircurexMarketId vircurexMarketId = (VircurexMarketId)marketId;

            return(VircurexParsers.ParseOrderBook(await CallPublic <JObject>(Method.orderbook,
                                                                             vircurexMarketId.BaseCurrencyCode, vircurexMarketId.QuoteCurrencyCode)));
        }
Пример #3
0
        public async Task <List <MarketTrade> > GetMarketTrades(MarketId marketId)
        {
            VircurexMarketId vircurexMarketId = (VircurexMarketId)marketId;

            return(VircurexParsers.ParseMarketTrades(marketId,
                                                     await CallPublic <JArray>(Method.trades,
                                                                               vircurexMarketId.BaseCurrencyCode, vircurexMarketId.QuoteCurrencyCode, null)));
        }
Пример #4
0
        public override bool Equals(object obj)
        {
            if (!this.GetType().Equals(obj.GetType()))
            {
                return(false);
            }

            VircurexMarketId other = (VircurexMarketId)obj;

            return(other.BaseCurrencyCode.Equals(this.BaseCurrencyCode) &&
                   other.QuoteCurrencyCode.Equals(this.QuoteCurrencyCode));
        }
Пример #5
0
        /// <summary>
        /// Parse market information from the market data API (as in https://vircurex.com/api/get_info_for_currency.json).
        /// </summary>
        /// <param name="currencyShortCodeToLabel">A mapping from coin short codes to human readable labels</param>
        /// <param name="marketObj">The JSON object representing a market</param>
        /// <returns></returns>
        public static VircurexMarket Parse(string baseCurrencyCode, JProperty marketProperty)
        {
            JObject          marketJson  = (JObject)marketProperty.Value;
            MarketStatistics marketStats = new MarketStatistics()
            {
                LastTrade     = marketJson.Value <decimal>("ltp"),
                Volume24HBase = marketJson.Value <decimal>("volume")
            };
            string           quoteCurrencyCode = marketProperty.Name;
            VircurexMarketId marketId          = new VircurexMarketId(baseCurrencyCode, quoteCurrencyCode);

            return(new VircurexMarket(marketId, baseCurrencyCode, quoteCurrencyCode, marketStats));
        }
        /// <summary>
        /// Parse market information from the market data API (as in https://vircurex.com/api/get_info_for_currency.json).
        /// </summary>
        /// <param name="currencyShortCodeToLabel">A mapping from coin short codes to human readable labels</param>
        /// <param name="marketObj">The JSON object representing a market</param>
        /// <returns></returns>
        public static VircurexMarket Parse(string baseCurrencyCode, JProperty marketProperty)
        {
            JObject marketJson = (JObject)marketProperty.Value;
            MarketStatistics marketStats = new MarketStatistics()
            {
                LastTrade = marketJson.Value<decimal>("ltp"),
                Volume24HBase = marketJson.Value<decimal>("volume")
            };
            string quoteCurrencyCode = marketProperty.Name;
            VircurexMarketId marketId = new VircurexMarketId(baseCurrencyCode, quoteCurrencyCode);

            return new VircurexMarket(marketId, baseCurrencyCode, quoteCurrencyCode, marketStats);
        }
Пример #7
0
        CreateUnreleasedOrder(MarketId marketId, OrderType orderType, decimal quantity, decimal price)
        {
            VircurexMarketId vircurexMarketId = (VircurexMarketId)marketId;
            List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>(PARAMETER_ORDER_TYPE, Enum.GetName(typeof(OrderType), orderType).ToUpper()),
                new KeyValuePair <string, string>(PARAMETER_AMOUNT, quantity.ToString()),
                new KeyValuePair <string, string>("currency1", vircurexMarketId.BaseCurrencyCode),
                new KeyValuePair <string, string>(PARAMETER_UNIT_PRICE, price.ToString()),
                new KeyValuePair <string, string>("currency2", vircurexMarketId.QuoteCurrencyCode)
            };

            JObject response = await CallPrivate <JObject>(Method.create_order, parameters);

            return(new VircurexOrderId(response.Value <int>("orderid")));
        }
Пример #8
0
        public static Dictionary <MarketId, Book> ParseMarketOrdersAlt(string quoteCurrencyCode,
                                                                       JObject altDepthJson)
        {
            Dictionary <MarketId, Book> marketOrders = new Dictionary <MarketId, Book>();

            // altDepthJson is structured as an object containing base currency
            // codes as keys, and book data as value.
            foreach (JProperty property in altDepthJson.Properties())
            {
                string  baseCurrencyCode = property.Name;
                JObject bookJson         = property.Value as JObject;

                if (null != bookJson)
                {
                    MarketId marketId = new VircurexMarketId(baseCurrencyCode, quoteCurrencyCode);
                    marketOrders[marketId] = ParseOrderBook(bookJson);
                }
            }

            return(marketOrders);
        }
        public static Dictionary<MarketId, Book> ParseMarketOrdersAlt(string quoteCurrencyCode,
            JObject altDepthJson)
        {
            Dictionary<MarketId, Book> marketOrders = new Dictionary<MarketId, Book>();

            // altDepthJson is structured as an object containing base currency
            // codes as keys, and book data as value.
            foreach (JProperty property in altDepthJson.Properties())
            {
                string baseCurrencyCode = property.Name;
                JObject bookJson = property.Value as JObject;

                if (null != bookJson)
                {
                    MarketId marketId = new VircurexMarketId(baseCurrencyCode, quoteCurrencyCode);
                    marketOrders[marketId] = ParseOrderBook(bookJson);
                }
            }

            return marketOrders;
        }
Пример #10
0
        public static List <MyOrder> ParseMyActiveOrders(JObject responseJson)
        {
            int            numberOrders = responseJson.Value <int>("numberorders");
            List <MyOrder> orders       = new List <MyOrder>(numberOrders);

            // Parses an order such as:
            // "orderid": 3670301,
            // "ordertype": "BUY",
            // "quantity": "19.87",
            // "openquantity": "18.79",
            // "currency1": "VTC",
            // "unitprice": "0.00363",
            // "currency2": "BTC",
            // "lastchangedat": "2014-01-13T22:54:30+00:00",
            // "releasedat": "2014-01-13T22:41:46+00:00"

            for (int orderIdx = 1; orderIdx <= numberOrders; orderIdx++)
            {
                JObject          orderJson = responseJson.Value <JObject>("order-" + orderIdx);
                DateTime         created   = orderJson.Value <DateTime>("releasedat"); // TODO: Handle unreleased orders?
                VircurexOrderId  orderId   = new VircurexOrderId(orderJson.Value <int>("orderid"));
                VircurexMarketId marketId  = new VircurexMarketId(orderJson.Value <string>("currency1"),
                                                                  orderJson.Value <string>("currency2"));
                OrderType orderType
                    = orderJson.Value <string>("ordertype").Equals(Enum.GetName(typeof(OrderType), OrderType.Buy).ToUpper())
                    ? OrderType.Buy
                    : OrderType.Sell;

                orders.Add(new MyOrder(orderId, orderType, created,
                                       orderJson.Value <decimal>("unitprice"), orderJson.Value <decimal>("openquantity"),
                                       orderJson.Value <decimal>("quantity"), marketId));
            }


            return(orders);
        }
Пример #11
0
 public async Task <List <MarketTrade> > GetMarketTrades(VircurexMarketId vircurexMarketId, VircurexOrderId since)
 {
     return(VircurexParsers.ParseMarketTrades(vircurexMarketId,
                                              await CallPublic <JArray>(Method.trades,
                                                                        vircurexMarketId.BaseCurrencyCode, vircurexMarketId.QuoteCurrencyCode, since)));
 }
        private static void TestVircurex()
        {
            using (VircurexExchange vircurex = new VircurexExchange())
            {
                Wallet btcWallet = null;

                vircurex.PublicKey = "rnicoll";
                vircurex.DefaultPrivateKey = "topsecret";

                vircurex.GetMyActiveOrders(VircurexExchange.OrderReleased.Released).Wait();

                // Try creating, releasing then deleting an order
                VircurexMarketId marketId = new VircurexMarketId("VTC", "BTC");
                VircurexOrderId unreleasedOrderId = vircurex.CreateUnreleasedOrder(marketId,
                    OrderType.Sell, 1m, 0.005m).Result;
                VircurexOrderId releasedOrderId = vircurex.ReleaseOrder(unreleasedOrderId).Result;
                vircurex.CancelOrder(releasedOrderId).Wait();

                foreach (Wallet wallet in vircurex.GetAccountInfo().Result.Wallets)
                {
                    if (wallet.CurrencyCode == "BTC")
                    {
                        btcWallet = wallet;
                    }
                }

                if (null == btcWallet)
                {
                    Console.WriteLine("BTC wallet not found.");
                }
                else
                {
                    Console.WriteLine("BTC balance: "
                        + btcWallet.Balance + "BTC");
                }

                // vircurex.GetOrderExecutions(new VircurexOrderId(5)).Wait();
            }
        }
        public static List<MyTrade> ParseOrderExecutions(JObject responseJson)
        {
            int numberOrderExecutions = responseJson.Value<int>("numberorderexecutions");
            VircurexOrderId orderId = new VircurexOrderId(responseJson.Value<int>("orderid"));
            List<MyTrade> trades = new List<MyTrade>(numberOrderExecutions);

            // Parses a trade such as:
            // "currency1": "DOGE",
            // "currency2": "BTC",
            // "quantity": "57796.176",
            // "unitprice": "0.0000025",
            // "feepaid": "115.592352",
            // "ordertype": "BUY",
            // "executed_at": "2014-02-14T15:17:08+00:00"

            for (int orderExecutionIdx = 1; orderExecutionIdx <= numberOrderExecutions; orderExecutionIdx++)
            {
                JObject orderExecutionJson = responseJson.Value<JObject>("orderexecution-" + orderExecutionIdx);
                DateTime executed = orderExecutionJson.Value<DateTime>("executed_at");
                VircurexMarketId marketId = new VircurexMarketId(orderExecutionJson.Value<string>("currency1"),
                    orderExecutionJson.Value<string>("currency2"));
                OrderType orderType
                    = orderExecutionJson.Value<string>("ordertype").Equals(Enum.GetName(typeof(OrderType), OrderType.Buy).ToUpper())
                    ? OrderType.Buy
                    : OrderType.Sell;

                trades.Add(new MyTrade(new VircurexFakeTradeId(orderId, orderExecutionIdx), orderType,
                    executed, orderExecutionJson.Value<decimal>("unitprice"), orderExecutionJson.Value<decimal>("feepaid"),
                    orderExecutionJson.Value<decimal>("quantity"), marketId, orderId));
            }

            return trades;
        }
Пример #14
0
        public void UpdateAllPrices()
        {
            if (prices.Length == 0)
            {
                return;
            }

            List<Task> tasks = new List<Task>();
            int currencyCount = prices.GetLength(0);

            Dictionary<MarketId, ExchangePrice> vircurexPrices = new Dictionary<MarketId, ExchangePrice>();
            HashSet<string> vircurexQuoteCurrencyCodes = new HashSet<string>();
            VircurexExchange vircurex = null;

            // Start the data fetch running in parallel; non-Vircurex first
            for (int baseCurrencyIdx = 0; baseCurrencyIdx < currencyCount; baseCurrencyIdx++)
            {
                for (int quoteCurrencyIdx = 0; quoteCurrencyIdx < currencyCount; quoteCurrencyIdx++)
                {
                    if (baseCurrencyIdx == quoteCurrencyIdx)
                    {
                        continue;
                    }

                    foreach (MarketPrice marketPrice in this.prices[baseCurrencyIdx, quoteCurrencyIdx])
                    {
                        // Can only update prices on markets which are directly tradable; other markets
                        // infer their prices from the underlying exchange prices.
                        // As such, ignore any non-exchange-price types.
                        ExchangePrice exchangePrice = marketPrice as ExchangePrice;

                        if (null == exchangePrice)
                        {
                            continue;
                        }

                        if (exchangePrice.Exchange is VircurexExchange)
                        {
                            VircurexMarketId marketId = new VircurexMarketId(currencyCodes[baseCurrencyIdx],
                                currencyCodes[quoteCurrencyIdx]);

                            vircurexQuoteCurrencyCodes.Add(marketId.QuoteCurrencyCode);
                            vircurexPrices[marketId] = exchangePrice;
                            vircurex = (VircurexExchange)marketPrice.Exchange;
                        }
                        else
                        {
                            tasks.Add(exchangePrice.UpdatePriceAsync());
                        }
                    }
                }
            }

            // Perform data fetch for Vircurex currencies; these can be
            // done in a batch, so we do them once the rest of the data
            // requests are running
            foreach (string quoteCurrencyCode in vircurexQuoteCurrencyCodes)
            {
                Dictionary<MarketId, Book> books = vircurex.GetMarketOrdersAlt(quoteCurrencyCode).Result;

                foreach (MarketId marketId in books.Keys) {
                    ExchangePrice exchangePrice;

                    if (vircurexPrices.TryGetValue(marketId, out exchangePrice))
                    {
                        exchangePrice.MarketDepth = books[marketId];
                    }
                }
            }

            // Wait for all tasks to finish before we exit
            foreach (Task task in tasks)
            {
                task.Wait();
            }
        }
Пример #15
0
 public VircurexMarket(VircurexMarketId id, string baseCurrencyCode, string quoteCurrencyCode,
                       MarketStatistics statistics)
     : base(id, baseCurrencyCode, quoteCurrencyCode, id.ToString(), statistics)
 {
 }
        public static List<MyOrder> ParseMyActiveOrders(JObject responseJson)
        {
            int numberOrders = responseJson.Value<int>("numberorders");
            List<MyOrder> orders = new List<MyOrder>(numberOrders);

            // Parses an order such as:
            // "orderid": 3670301,
            // "ordertype": "BUY",
            // "quantity": "19.87",
            // "openquantity": "18.79",
            // "currency1": "VTC",
            // "unitprice": "0.00363",
            // "currency2": "BTC",
            // "lastchangedat": "2014-01-13T22:54:30+00:00",
            // "releasedat": "2014-01-13T22:41:46+00:00"

            for (int orderIdx = 1; orderIdx <= numberOrders; orderIdx++)
            {
                JObject orderJson = responseJson.Value<JObject>("order-" + orderIdx);
                DateTime created = orderJson.Value<DateTime>("releasedat"); // TODO: Handle unreleased orders?
                VircurexOrderId orderId = new VircurexOrderId(orderJson.Value<int>("orderid"));
                VircurexMarketId marketId = new VircurexMarketId(orderJson.Value<string>("currency1"),
                    orderJson.Value<string>("currency2"));
                OrderType orderType
                    = orderJson.Value<string>("ordertype").Equals(Enum.GetName(typeof(OrderType), OrderType.Buy).ToUpper())
                    ? OrderType.Buy
                    : OrderType.Sell;

                orders.Add(new MyOrder(orderId, orderType, created,
                    orderJson.Value<decimal>("unitprice"), orderJson.Value<decimal>("openquantity"),
                    orderJson.Value<decimal>("quantity"), marketId));
            }

            return orders;
        }
 public VircurexMarket(VircurexMarketId id, string baseCurrencyCode, string quoteCurrencyCode,
     MarketStatistics statistics)
     : base(id, baseCurrencyCode, quoteCurrencyCode, id.ToString(), statistics)
 {
 }