private static void Trade1() { // Settings BTCMarketsHelper.ProfitMargin = 2; // Get number of Open Orders OpenOrdersHistory = BTCMarketsHelper.OrderOpen(CURRENCY, INSTRUMENT, 10, "1"); if (OpenOrdersHistory.success && OpenOrdersHistory.orders != null) { if (OpenOrdersHistory.orders.Length > 1) { Console.WriteLine("Open orders are still active..."); } else { // get ETH/BTC market data i.e. instrument/currency MarketTickData marketData = BTCMarketsHelper.GetMarketTick($"{INSTRUMENT}/{CURRENCY}"); // get trading data TradingData tradingData = TradingHelper.GetTradingData(marketData, splitProfitMargin: true); Console.WriteLine($"Buy volume ({marketData.instrument}): {tradingData.BuyVolume}"); Console.WriteLine($"Buy price ({marketData.currency}): {tradingData.BuyPrice}"); Console.WriteLine($"Sell volume ({marketData.instrument}): {tradingData.SellVolume}"); Console.WriteLine($"Sell price ({marketData.currency}): {tradingData.SellPrice}"); Console.WriteLine($"Spend total ({marketData.currency}): {tradingData.SpendTotal}"); // create orders CreateOrderData buyOrder = BTCMarketsHelper.CreateNewOrder(marketData.currency, marketData.instrument, (long)(tradingData.BuyPrice * ApplicationConstants.NUMERIC_MULTIPLIER), (long)(tradingData.BuyVolume * ApplicationConstants.NUMERIC_MULTIPLIER), "Bid", "Limit"); if (buyOrder.success) { System.Threading.Thread.Sleep(rnd.Next(1, 10) * 1000); CreateOrderData sellOrder = BTCMarketsHelper.CreateNewOrder(marketData.currency, marketData.instrument, (long)(tradingData.SellPrice * ApplicationConstants.NUMERIC_MULTIPLIER), (long)(tradingData.SellVolume * ApplicationConstants.NUMERIC_MULTIPLIER), "Ask", "Limit"); if (sellOrder.success) { // append csv line BotLogger.WriteLine($",{tradingData.BuyVolume}, {marketData.instrument}, Balance (Unit 2), " + $"{tradingData.BuyPrice}, {marketData.currency}, {tradingData.SpendTotal}, {BTCMarketsHelper.ProfitMargin}%, " + $"{tradingData.SellVolume}, {tradingData.SellPrice}"); } else { Console.WriteLine(sellOrder.errorMessage); } } else { Console.WriteLine(buyOrder.errorMessage); } } } else { Console.WriteLine(OpenOrdersHistory.errorMessage); } Console.WriteLine(CONSOLE_WAITING); Console.WriteLine(); }
private static void Trade3() { // Settings BTCMarketsHelper.ProfitMargin = 0; // Get number of Open Orders OpenOrdersHistory = BTCMarketsHelper.OrderOpen(CURRENCY, INSTRUMENT, 10, "1"); if (OpenOrdersHistory.success && OpenOrdersHistory.orders != null) { if (OpenOrdersHistory.orders.Length > 1) { Console.WriteLine("Open orders are still active..."); } else { // get ETH/BTC market data i.e. instrument/currency Console.WriteLine($"Previous Ask Price: {lastETH_BTC}"); MarketTickData marketData = BTCMarketsHelper.GetMarketTick($"{INSTRUMENT}/{CURRENCY}"); Console.WriteLine($"Current Ask Price: {marketData.bestAsk}"); lastETH_BTC = marketData.bestAsk; // get trading data TradingData tradingData = TradingHelper.GetTradingData(marketData); if (lastETH_BTC > 0) // ensure first round is skipped when there is no history { if (marketData.bestAsk > lastETH_BTC) { Console.WriteLine($"Previous Volume (BTC): {lastBTC_Volume}"); if (tradingData.BuyVolume > lastBTC_Volume) { Console.WriteLine("ETH has gone stronger. Sell ETH."); } } else if (marketData.bestAsk < lastETH_BTC) { Console.WriteLine("BTC has gone stronger. Buy ETH."); Console.WriteLine($"Previous Buy Volume (ETH): {lastETH_Volume}"); Console.WriteLine($"Current Buy volume ({marketData.instrument}): {tradingData.BuyVolume}"); } } Console.WriteLine($"Buy price ({marketData.currency}): {tradingData.BuyPrice}"); Console.WriteLine($"Sell volume ({marketData.instrument}): {tradingData.SellVolume}"); Console.WriteLine($"Sell price ({marketData.currency}): {tradingData.SellPrice}"); Console.WriteLine($"Spend total ({marketData.currency}): {tradingData.SpendTotal}"); /* * // create orders * CreateOrderData buyOrder = BTCMarketsHelper.CreateNewOrder(marketData.currency, marketData.instrument, * (long)(tradingData.BuyPrice * ApplicationConstants.NUMERIC_MULTIPLIER), * (int)(tradingData.BuyVolume * ApplicationConstants.NUMERIC_MULTIPLIER), * "Bid", "Limit"); * * if (buyOrder.success) * { * CreateOrderData sellOrder = BTCMarketsHelper.CreateNewOrder(marketData.currency, marketData.instrument, * (long)(tradingData.SellPrice * ApplicationConstants.NUMERIC_MULTIPLIER), * (int)(tradingData.SellVolume * ApplicationConstants.NUMERIC_MULTIPLIER), * "Ask", "Limit"); * * if (sellOrder.success) * { * // append csv line * BotLogger.WriteLine($",{tradingData.BuyVolume.ToDecimalString(8)}, {marketData.instrument}, Balance (Unit 2), " + * $"{tradingData.BuyPrice.ToDecimalString(8)}, {marketData.currency}, {tradingData.SpendTotal.ToDecimalString(8)}, {BTCMarketsHelper.ProfitMargin}%, " + * $"{tradingData.SellVolume.ToDecimalString(8)}, {tradingData.SellPrice.ToDecimalString(8)}"); * } * else * { * Console.WriteLine(sellOrder.errorMessage); * } * } * else * { * Console.WriteLine(buyOrder.errorMessage); * } */ } } else { Console.WriteLine(OpenOrdersHistory.errorMessage); } Console.WriteLine(CONSOLE_WAITING); Console.WriteLine(); }
private void MonPrice(List <TxtParamClass> listMonitors) { WriteLogs("开启价格处理线程"); isMon = true; ThreadPool.QueueUserWorkItem(p => { MonitorSetting setting = null; while (isMon && queueSetting.TryDequeue(out setting)) { RemoveQueue(setting); TradingHelper.heightprice.Price = 0; TradingHelper.lowprice.Price = 0; bool flg = true; while (DateTime.Now < setting.DateTimePriceMonStartTime) { if (flg) { WriteLogs("等待时间...." + DateTime.Now.ToString() + "->" + setting.DateTimePriceMonStartTime.ToString()); flg = false; } Thread.Sleep(1000); } for (int i = 0; i < listMonitors.Count; i++) { foreach (DataGridViewRow row in dataGridViewData.Rows) { if (row.Tag != null && row.Tag.ToString() == listMonitors[i].MemberId.ToString()) { if (row.Cells["colMonLots"].Value == null || row.Cells["colMonRate"].Value == null) { MessageBox.Show("请认真检查Monlots 和 MonRate是否设置值!"); } else { string monlots = row.Cells["colMonLots"].Value.ToString(); string monrates = row.Cells["colMonRate"].Value.ToString(); if (monlots.IndexOf(",") >= 0 && monrates.IndexOf(",") >= 0) { int lotsindex = monlots.IndexOf(","), rateindex = monrates.IndexOf(","); string lots = monlots.Substring(0, lotsindex); string rate = monrates.Substring(0, rateindex); row.Cells["colMonLots"].Value = monlots.Remove(0, lotsindex + 1); row.Cells["colMonRate"].Value = monrates.Remove(0, rateindex + 1); listMonitors[i].MonLots = double.Parse(lots); listMonitors[i].MonRate = double.Parse(rate); } else { listMonitors[i].MonLots = double.Parse(monlots); listMonitors[i].MonRate = double.Parse(monrates); row.Cells["colMonLots"].Value = string.Empty; row.Cells["colMonRate"].Value = string.Empty; } } } } listMonitors[i].Action = TxtParamActionEnum.Monitor;//重置当前已经交易的用户 } while (DateTime.Now > setting.DateTimePriceMonStartTime && DateTime.Now < setting.DateTimePickerMonEndTime) { try { double price = 0; bool isopen = false; while (priceList.TryDequeue(out price)) { for (int i = 0; i < listMonitors.Count; i++) { listMonitors[i].MonEnd = setting.DateTimePickerMonEndTime; listMonitors[i].MonStart = setting.DateTimePriceMonStartTime; } isopen = TradingHelper.StartPriceProcess(listMonitors, price, chkShowLog.Checked); if (isopen) { break; } Thread.Sleep(5); } if (isopen) { //queueSetting.Enqueue(setting); break; } } catch (Exception ex) { _log.Error(ex); WriteLogs("处理报价出错:" + ex.ToString()); } Thread.Sleep(50); } } this.BeginInvoke((MethodInvoker)(() => { toolStartMonitor.Text = "开启监听"; priceList = new ConcurrentQueue <double>(); isMon = false; File.AppendAllText(Path.Combine("log", DateTime.Now.ToString("yyyyMMdd") + ".log"), txtLogs.Text); txtLogs.Clear(); txtLogs.ClearUndo(); })); WriteLogs("所有参数设置已经完成处理"); }); }