private async static Task <OrderId> ClosePosition(CryptsyExchange cryptsy, Market market, Wallet wallet) { // Get the market depth to determine best available price Book book = await cryptsy.GetMarketDepth(market.MarketId); decimal price; if (book.Bids.Count > 0) { price = book.Bids[0].Price; } else if (book.Asks.Count > 0) { price = book.Asks[0].Price; } else { List <MarketTrade> recentTrades = await cryptsy.GetMarketTrades(market.MarketId); price = recentTrades[0].Price; } return(await cryptsy.CreateOrder(market.MarketId, OrderType.Sell, wallet.Balance, price)); }
/// <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()); } } } } }
public static void Main(string[] argv) { using (CryptsyExchange cryptsy = new CryptsyExchange()) { // TODO: Add in API keys DoPanicSell(cryptsy); } }
/// <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()); } } } } }
public static void Main() { try { using (BterExchange bter = new BterExchange()) { using (CoinExExchange coinEx = new CoinExExchange()) { PublicPrivateKeyPair cryptsyConfiguration = LoadPublicPrivateKeyPair(CRYPTSY_CONFIGURATION_FILENAME); using (CryptsyExchange cryptsy = new CryptsyExchange() { PublicKey = cryptsyConfiguration.PublicKey, PrivateKey = cryptsyConfiguration.PrivateKey } ) { PublicPrivateKeyPair vaultOfSatoshiConfiguration = LoadPublicPrivateKeyPair(VAULT_OF_SATOSHI_CONFIGURATION_FILENAME); using (VoSExchange vaultOfSatoshi = new VoSExchange() { PublicKey = vaultOfSatoshiConfiguration.PublicKey, PrivateKey = vaultOfSatoshiConfiguration.PrivateKey } ) { using (VircurexExchange vircurex = new VircurexExchange()) { DoAnalysis(new List <IExchange>() { vaultOfSatoshi, bter, coinEx, cryptsy, vircurex }); } } } } } } catch (ExchangeConfigurationException e) { Console.WriteLine(e.Message); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } }
public static void Main() { try { using (BterExchange bter = new BterExchange()) { using (CoinExExchange coinEx = new CoinExExchange()) { PublicPrivateKeyPair cryptsyConfiguration = LoadPublicPrivateKeyPair(CRYPTSY_CONFIGURATION_FILENAME); using (CryptsyExchange cryptsy = new CryptsyExchange() { PublicKey = cryptsyConfiguration.PublicKey, PrivateKey = cryptsyConfiguration.PrivateKey } ) { PublicPrivateKeyPair vaultOfSatoshiConfiguration = LoadPublicPrivateKeyPair(VAULT_OF_SATOSHI_CONFIGURATION_FILENAME); using (VoSExchange vaultOfSatoshi = new VoSExchange() { PublicKey = vaultOfSatoshiConfiguration.PublicKey, PrivateKey = vaultOfSatoshiConfiguration.PrivateKey } ) { using (VircurexExchange vircurex = new VircurexExchange()) { DoAnalysis(new List<IExchange>() { vaultOfSatoshi, bter, coinEx, cryptsy, vircurex }); } } } } } } catch (ExchangeConfigurationException e) { Console.WriteLine(e.Message); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } }
private static void DoPanicSell(CryptsyExchange cryptsy) { // Cancel all orders Task cancelTask = cryptsy.CancelAllOrders(); Task <List <Market> > marketsTask = cryptsy.GetMarkets(); Task <AccountInfo> accountInfoTask = cryptsy.GetAccountInfo(); List <Wallet> nonZeroWalletsExcludingBtc = accountInfoTask.Result.Wallets .Where(wallet => wallet.CurrencyCode != "BTC" && wallet.Balance > 0.00000000m).ToList(); List <string> currenciesWithPositions = nonZeroWalletsExcludingBtc .Select(wallet => wallet.CurrencyCode).ToList(); // Filter markets to BTC crosses with wallets as above. List <Market> relevantMarkets = marketsTask.Result .Where(market => market.BaseCurrencyCode == "BTC" && currenciesWithPositions.Contains(market.QuoteCurrencyCode)) .ToList(); // Wait until we've finished cancelling orders before we create new ones cancelTask.Wait(); List <Task <OrderId> > flattenTasks = new List <Task <OrderId> >(); foreach (Market market in relevantMarkets) { foreach (Wallet wallet in nonZeroWalletsExcludingBtc) { if (wallet.CurrencyCode == market.QuoteCurrencyCode && wallet.Balance > 0.0m) { // Start the flatten requests, but don't block waiting for any of // them to complete, yet flattenTasks.Add(ClosePosition(cryptsy, market, wallet)); } } } // Wait for all of the orders to be issued. foreach (Task <OrderId> task in flattenTasks) { task.Wait(); } }
private static void DoPanicSell(CryptsyExchange cryptsy) { // Cancel all orders Task cancelTask = cryptsy.CancelAllOrders(); Task<List<Market>> marketsTask = cryptsy.GetMarkets(); Task<AccountInfo> accountInfoTask = cryptsy.GetAccountInfo(); List<Wallet> nonZeroWalletsExcludingBtc = accountInfoTask.Result.Wallets .Where(wallet => wallet.CurrencyCode != "BTC" && wallet.Balance > 0.00000000m).ToList(); List<string> currenciesWithPositions = nonZeroWalletsExcludingBtc .Select(wallet => wallet.CurrencyCode).ToList(); // Filter markets to BTC crosses with wallets as above. List<Market> relevantMarkets = marketsTask.Result .Where(market => market.BaseCurrencyCode == "BTC" && currenciesWithPositions.Contains(market.QuoteCurrencyCode)) .ToList(); // Wait until we've finished cancelling orders before we create new ones cancelTask.Wait(); List<Task<OrderId>> flattenTasks = new List<Task<OrderId>>(); foreach (Market market in relevantMarkets) { foreach (Wallet wallet in nonZeroWalletsExcludingBtc) { if (wallet.CurrencyCode == market.QuoteCurrencyCode && wallet.Balance > 0.0m) { // Start the flatten requests, but don't block waiting for any of // them to complete, yet flattenTasks.Add(ClosePosition(cryptsy, market, wallet)); } } } // Wait for all of the orders to be issued. foreach (Task<OrderId> task in flattenTasks) { task.Wait(); } }
public void TestSignCryptsyRequest() { string privateKey = "topsecret"; byte[] privateKeyBytes = System.Text.Encoding.ASCII.GetBytes(privateKey); string actual; string expected = "6dd05bfe3104a70768cf76a30474176db356818d3556e536c31d158fc2c3adafa096df144b46b2ccb1ff6128d6a0a07746695eca061547b25fd676c9614e6718"; FormUrlEncodedContent request = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>(CryptsyExchange.PARAM_METHOD, Enum.GetName(typeof(CryptsyMethod), CryptsyMethod.getinfo)), new KeyValuePair <string, string>(CryptsyExchange.PARAM_NONCE, "1388246959") }); using (CryptsyExchange cryptsy = new CryptsyExchange() { PublicKey = "64d00dc4ee1c2b9551eabbdc831972d4ce2bcac5", PrivateKey = privateKey } ) { actual = cryptsy.GenerateSHA512Signature(request); } Assert.AreEqual(expected, actual); }
private async static Task<OrderId> ClosePosition(CryptsyExchange cryptsy, Market market, Wallet wallet) { // Get the market depth to determine best available price Book book = await cryptsy.GetMarketDepth(market.MarketId); decimal price; if (book.Bids.Count > 0) { price = book.Bids[0].Price; } else if (book.Asks.Count > 0) { price = book.Asks[0].Price; } else { List<MarketTrade> recentTrades = await cryptsy.GetMarketTrades(market.MarketId); price = recentTrades[0].Price; } return await cryptsy.CreateOrder(market.MarketId, OrderType.Sell, wallet.Balance, price); }
public void TestSignCryptsyRequest() { string privateKey = "topsecret"; byte[] privateKeyBytes = System.Text.Encoding.ASCII.GetBytes(privateKey); string actual; string expected = "6dd05bfe3104a70768cf76a30474176db356818d3556e536c31d158fc2c3adafa096df144b46b2ccb1ff6128d6a0a07746695eca061547b25fd676c9614e6718"; FormUrlEncodedContent request = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>(CryptsyExchange.PARAM_METHOD, Enum.GetName(typeof(CryptsyMethod), CryptsyMethod.getinfo)), new KeyValuePair<string, string>(CryptsyExchange.PARAM_NONCE, "1388246959") }); using (CryptsyExchange cryptsy = new CryptsyExchange() { PublicKey = "64d00dc4ee1c2b9551eabbdc831972d4ce2bcac5", PrivateKey = privateKey } ) { actual = cryptsy.GenerateSHA512Signature(request); } Assert.AreEqual(expected, actual); }