Example #1
0
        /// <summary>
        /// Rough test which finds market IDs, then fetches recent transactions and dumps
        /// them to CSV.
        /// </summary>
        private static void TestCryptsy()
        {
            string fileName = System.IO.Path.GetTempFileName();

            fileName = fileName.Replace(".tmp", ".csv");
            Dictionary <string, CryptsyMarket> markets = new Dictionary <string, CryptsyMarket>();

            string[] marketCodes = new string[] {
                "DOGE/BTC",
                "LTC/BTC",
                "QRK/BTC",
                "VTC/BTC"
            };

            using (StreamWriter writer = new StreamWriter(new FileStream(fileName, FileMode.Create)))
            {
                using (CryptsyExchange cryptsy = new CryptsyExchange())
                {
                    cryptsy.PublicKey  = "";
                    cryptsy.PrivateKey = "topsecret";

                    foreach (Market market in cryptsy.GetMarkets().Result)
                    {
                        CryptsyMarket cryptsyMarket = (CryptsyMarket)market;
                        markets[cryptsyMarket.BaseCurrencyCode + "/"
                                + cryptsyMarket.QuoteCurrencyCode] = cryptsyMarket;
                    }

                    foreach (string marketCode in marketCodes)
                    {
                        CryptsyMarket market = markets[marketCode];

                        writer.WriteLine("Date,Time,Side,Trade ID,Exchange,Base currency,Quantity,Quote currency,Price,Cost,Fee,Fee currency");

                        foreach (MyTrade trade in cryptsy.GetMyTrades(market.MarketId, null).Result)
                        {
                            System.Text.StringBuilder line = new System.Text.StringBuilder();

                            line.Append(trade.DateTime.ToString("yyyy-MM-dd")).Append(",")
                            .Append(trade.DateTime.ToString("HH:mm:ss")).Append(",")
                            .Append(Enum.GetName(typeof(OrderType), trade.TradeType)).Append(",")
                            .Append(trade.OrderId).Append(",")
                            .Append("Cryptsy").Append(",")
                            .Append(market.BaseCurrencyCode).Append(",")
                            .Append(trade.Quantity).Append(",")
                            .Append(market.QuoteCurrencyCode).Append(",")
                            .Append(trade.Price).Append(",")
                            .Append(",")
                            .Append(trade.Fee).Append(",")
                            .Append(market.QuoteCurrencyCode);

                            writer.WriteLine(line.ToString());
                        }
                    }
                }
            }
        }
Example #2
0
        public void TestParseCryptsyMarkets()
        {
            JObject              jsonObj         = LoadTestData("getmarkets.json");
            TimeZoneInfo         defaultTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
            JArray               marketsJson     = jsonObj.Value <JArray>("return");
            List <CryptsyMarket> markets         = marketsJson.Select(
                market => CryptsyMarket.Parse(market as JObject, defaultTimeZone)
                ).ToList();

            Assert.AreEqual(114, markets.Count);

            foreach (Market market in markets)
            {
                // DOGE/BTC
                if (market.MarketId.ToString().Equals("132"))
                {
                    Assert.AreEqual(market.BaseCurrencyCode, "DOGE");
                    Assert.AreEqual(market.QuoteCurrencyCode, "BTC");
                    Assert.AreEqual(market.Statistics.Volume24HBase, (decimal)716008746.70171800);
                }
            }
        }