public void TestParseVircurexMarketTrades() { JArray tradesJson = LoadTestData <JArray>("trades.json"); VircurexMarketId marketId = new VircurexMarketId("DOGE", "BTC"); List <MarketTrade> trades = VircurexParsers.ParseMarketTrades(marketId, tradesJson); Assert.AreEqual(1000, trades.Count); Assert.AreEqual("1110350", trades[0].TradeId.ToString()); Assert.AreEqual(new DateTime(2014, 1, 3, 11, 14, 42), trades[0].DateTime); Assert.AreEqual((decimal)1208.12173, trades[0].Quantity); Assert.AreEqual((decimal)0.00000043, trades[0].Price); Assert.AreEqual("1110352", trades[1].TradeId.ToString()); }
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 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(); } }