public static void captureData() { lock (MainClass.data) { try { System.Data.DataSet ds = null; bool create = false; if (!System.IO.File.Exists(MainClass.location + "bd.xml")) { System.Data.DataTable dt = new System.Data.DataTable("Balances"); dt.Columns.Add("Date"); dt.Columns.Add("Coin"); dt.Columns.Add("Amount"); dt.Rows.Add("", "", ""); System.Data.DataTable dtParameters = new System.Data.DataTable("Parameters"); dtParameters.Columns.Add("Parameter"); dtParameters.Columns.Add("Value"); dtParameters.Rows.Add("", ""); ds = new System.Data.DataSet(); ds.DataSetName = "Database"; ds.Tables.Add(dt); ds.Tables.Add(dtParameters); ds.WriteXml(MainClass.location + "bd.xml"); create = true; } ds = new System.Data.DataSet(); ds.ReadXml(MainClass.location + "bd.xml"); BitMEX.BitMEXApi bitMEXApi = new BitMEX.BitMEXApi(MainClass.bitmexKeyWeb, MainClass.bitmexSecretWeb, MainClass.bitmexDomain); string json = bitMEXApi.GetWallet(); JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); if (create) { ds.Tables[0].Rows.Clear(); } ds.Tables[0].Rows.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MainClass.pair, jCointaner[0]["walletBalance"].ToString()); ds.Tables[1].Rows.Clear(); ds.Tables[1].Rows.Add("OpenOrders", bitMEXApi.GetOpenOrders(MainClass.pair).Count); ds.Tables[1].Rows.Add("Amount", jCointaner[0]["walletBalance"].ToString()); System.IO.File.Delete(MainClass.location + "bd.xml"); ds.WriteXml(MainClass.location + "bd.xml"); } catch { } } }
private void Run(string[] args) { BitMEXApi bitmex = new BitMEXApi(bitmexKey, bitmexSecret); // var orderBook = bitmex.GetOrderBook("XBTUSD", 3); var orders = bitmex.GetOrders(); // var orders = bitmex.DeleteOrders(); Console.WriteLine(orders); }
public static void Main(string[] args) { try { //Config Console.Title = "Loading..."; Console.ForegroundColor = ConsoleColor.White; log("Deleron - Back to the future - v" + version + " - Bitmex version"); log("by Matheus Grijo ", ConsoleColor.Green); log(" ======= HALL OF FAME BOTMEX ======= "); log(" - Lucas Sousa", ConsoleColor.Magenta); log(" - Carlos Morato", ConsoleColor.Magenta); log(" - Luis Felipe Alves", ConsoleColor.Magenta); log(" ======= END HALL OF FAME BOTMEX ======= "); log("http://botmex.ninja/"); log("GITHUB http://github.com/matheusgrijo", ConsoleColor.Blue); log(" ******* DONATE ********* "); log("BTC 39DWjHHGXJh9q82ZrxkA8fiZoE37wL8jgh"); log("BCH qqzwkd4klrfafwvl7ru7p7wpyt5z3sjk6y909xq0qk"); log("ETH 0x3017E79f460023435ccD285Ff30Bd10834D20777"); log("ETC 0x088E7E67af94293DB55D61c7B55E2B098d2258D9"); log("LTC MVT8fxU4WBzdfH5XgvRPWkp7pE4UyzG9G5"); log("Load config..."); log("Considere DOAR para o projeto!", ConsoleColor.Green); log("Vamos aguardar 10 min para voce doar ;) ... ", ConsoleColor.Blue); log("ATENCAO, PARA FACILITAR A DOACAO DAQUI A 30 SEGUNDOS VAMOS ABRIR UMA PAGINA PARA VOCE!", ConsoleColor.Green); System.Threading.Thread.Sleep(30000); System.Diagnostics.Process.Start("https://www.blockchain.com/btc/payment_request?address=1AnttTLGhzJsX7T96SutWS4N9wPYuBThu8&amount_local=30¤cy=USD&nosavecurrency=true"); log("Perfeito, agora aguarde os 9 minutos e 30 segundos restantes para iniciar o BOTMEX, enquanto isto estamos carregando as suas configuracoes...", ConsoleColor.Magenta); String jsonConfig = System.IO.File.ReadAllText(location + "key.txt"); JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(jsonConfig, (typeof(JContainer))); System.Threading.Thread.Sleep(60000 * 10); bitmexKey = jCointaner["key"].ToString(); bitmexSecret = jCointaner["secret"].ToString(); bitmexKeyWeb = jCointaner["webserverKey"].ToString(); bitmexSecretWeb = jCointaner["webserverSecret"].ToString(); bitmexDomain = jCointaner["domain"].ToString(); statusShort = jCointaner["short"].ToString(); statusLong = jCointaner["long"].ToString(); pair = jCointaner["pair"].ToString(); timeGraph = jCointaner["timeGraph"].ToString(); qtdyContacts = int.Parse(jCointaner["contract"].ToString()); interval = int.Parse(jCointaner["interval"].ToString()); intervalCancelOrder = int.Parse(jCointaner["intervalCancelOrder"].ToString()); intervalOrder = int.Parse(jCointaner["intervalOrder"].ToString()); intervalCapture = int.Parse(jCointaner["webserverIntervalCapture"].ToString()); profit = double.Parse(jCointaner["profit"].ToString()); fee = double.Parse(jCointaner["fee"].ToString()); stoploss = double.Parse(jCointaner["stoploss"].ToString()); stopgain = double.Parse(jCointaner["stopgain"].ToString()); roeAutomatic = jCointaner["roe"].ToString() == "automatic"; limiteOrder = int.Parse(jCointaner["limiteOrder"].ToString()); bitMEXApi = new BitMEX.BitMEXApi(bitmexKey, bitmexSecret, bitmexDomain); //TESTS HERE //makeOrder("Buy"); //FINAL if (jCointaner["webserver"].ToString() == "enable") { WebServer ws = new WebServer(WebServer.SendResponse, jCointaner["webserverConfig"].ToString()); ws.Run(); System.Threading.Thread tCapture = new Thread(Database.captureDataJob); tCapture.Start(); System.Threading.Thread.Sleep(1000); } log("wait 1s..."); System.Threading.Thread.Sleep(1000); log("Total open orders: " + bitMEXApi.GetOpenOrders(pair).Count); log(""); log("Wallet: " + bitMEXApi.GetWallet()); lstIndicatorsAll.Add(new IndicatorADX()); lstIndicatorsAll.Add(new IndicatorMFI()); lstIndicatorsAll.Add(new IndicatorBBANDS()); lstIndicatorsAll.Add(new IndicatorCCI()); lstIndicatorsAll.Add(new IndicatorCMO()); lstIndicatorsAll.Add(new IndicatorDI()); lstIndicatorsAll.Add(new IndicatorDM()); lstIndicatorsAll.Add(new IndicatorMA()); lstIndicatorsAll.Add(new IndicatorMACD()); lstIndicatorsAll.Add(new IndicatorMOM()); lstIndicatorsAll.Add(new IndicatorPPO()); lstIndicatorsAll.Add(new IndicatorROC()); lstIndicatorsAll.Add(new IndicatorRSI()); lstIndicatorsAll.Add(new IndicatorSAR()); lstIndicatorsAll.Add(new IndicatorSTOCH()); lstIndicatorsAll.Add(new IndicatorSTOCHRSI()); lstIndicatorsAll.Add(new IndicatorTRIX()); lstIndicatorsAll.Add(new IndicatorULTOSC()); lstIndicatorsAll.Add(new IndicatorWILLR()); foreach (var item in jCointaner["indicatorsEntry"]) { foreach (var item2 in lstIndicatorsAll) { if (item["name"].ToString().Trim().ToUpper() == item2.getName().Trim().ToUpper()) { item2.setPeriod(int.Parse((item["period"].ToString().Trim().ToUpper()))); lstIndicatorsEntry.Add(item2); } } } foreach (var item in jCointaner["indicatorsEntryCross"]) { foreach (var item2 in lstIndicatorsAll) { if (item["name"].ToString().Trim().ToUpper() == item2.getName().Trim().ToUpper()) { item2.setPeriod(int.Parse((item["period"].ToString().Trim().ToUpper()))); lstIndicatorsEntryCross.Add(item2); } } } foreach (var item in jCointaner["indicatorsEntryDecision"]) { foreach (var item2 in lstIndicatorsAll) { if (item["name"].ToString().Trim().ToUpper() == item2.getName().Trim().ToUpper()) { item2.setPeriod(int.Parse((item["period"].ToString().Trim().ToUpper()))); lstIndicatorsEntryDecision.Add(item2); } } } if (jCointaner["webserver"].ToString() == "enable") { System.Diagnostics.Process.Start(jCointaner["webserverConfig"].ToString()); } bool automaticTendency = statusLong == "automatic"; //LOOP while (true) { positionContracts = getPosition(); // FIX CARLOS MORATO roe = getRoe(); //Stop Loss if (roe < 0) { if ((roe * (-1)) >= stoploss) { //Stop loss bitMEXApi.CancelAllOpenOrders(pair); String side = "Buy"; if (positionContracts > 0) { side = "Sell"; } bitMEXApi.MarketOrder(pair, side, positionContracts); } } //Stop Gain if (roe > 0) { if (roe >= stopgain) { //Stop loss bitMEXApi.CancelAllOpenOrders(pair); String side = "Buy"; if (positionContracts > 0) { side = "Sell"; } bitMEXApi.MarketOrder(pair, side, positionContracts); } } //SEARCH POSITION AND MAKE ORDER //By Carlos Morato if (roeAutomatic && (Math.Abs(getOpenOrderQty()) < Math.Abs(positionContracts))) { log("Get Position " + positionContracts); int qntContacts = (Math.Abs(positionContracts) - Math.Abs(getOpenOrderQty())); if (positionContracts > 0) { string side = "Sell"; double priceContacts = Math.Abs(getPositionPrice()); double actualPrice = Math.Abs(getPriceActual(side)); double priceContactsProfit = Math.Abs(Math.Floor(priceContacts + (priceContacts * (profit + fee) / 100))); if (actualPrice > priceContactsProfit) { double price = actualPrice + 1; String json = bitMEXApi.PostOrderPostOnly(pair, side, price, qntContacts); JContainer jCointaner2 = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); log(json); } else { double price = priceContactsProfit; String json = bitMEXApi.PostOrderPostOnly(pair, side, price, qntContacts); JContainer jCointaner2 = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); log(json); } } if (positionContracts < 0) { string side = "Buy"; double priceContacts = Math.Abs(getPositionPrice()); double actualPrice = Math.Abs(getPriceActual(side)); double priceContactsProfit = Math.Abs(Math.Floor(priceContacts - (priceContacts * (profit + fee) / 100))); if (actualPrice < priceContactsProfit) { double price = actualPrice - 1; String json = bitMEXApi.PostOrderPostOnly(pair, side, price, qntContacts); JContainer jCointaner2 = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); log(json); } else { double price = priceContactsProfit; String json = bitMEXApi.PostOrderPostOnly(pair, side, price, qntContacts); JContainer jCointaner2 = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); log(json); } } } //CANCEL ORDER WITHOUT POSITION //By Carlos Morato if (roeAutomatic && Math.Abs(positionContracts) != Math.Abs(getOpenOrderQty())) { bitMEXApi.CancelAllOpenOrders(pair); } if (automaticTendency) { verifyTendency(); } //GET CANDLES if (getCandles()) { if (statusLong == "enable") { log(""); log("=========================================================="); log(" ==================== Verify LONG OPERATION =============", ConsoleColor.Green); log("=========================================================="); /////VERIFY OPERATION LONG string operation = "buy"; //VERIFY INDICATORS ENTRY foreach (var item in lstIndicatorsEntry) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (operationBuy != Operation.buy) { operation = "nothing"; break; } } //VERIFY INDICATORS CROSS if (operation == "buy") { //Prepare to long while (true) { log("wait operation long..."); getCandles(); foreach (var item in lstIndicatorsEntryCross) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator Cross: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (item.getTypeIndicator() == TypeIndicator.Cross) { if (operationBuy == Operation.buy) { operation = "long"; break; } } else if (operationBuy != Operation.buy) { operation = "long"; break; } } if (lstIndicatorsEntryCross.Count == 0) { operation = "long"; } if (operation != "buy") { break; } log("wait " + interval + "ms"); Thread.Sleep(interval); } } //VERIFY INDICATORS DECISION if (operation == "long" && lstIndicatorsEntryDecision.Count > 0) { operation = "decision"; foreach (var item in lstIndicatorsEntryDecision) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator Decision: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (getValue("indicatorsEntryDecision", item.getName(), "decision") == "enable" && getValue("indicatorsEntryDecision", item.getName(), "tendency") == "enable") { int decisionPoint = int.Parse(getValue("indicatorsEntryDecision", item.getName(), "decisionPoint")); if (item.getResult() >= decisionPoint && item.getTendency() == Tendency.high) { operation = "long"; break; } } if (getValue("indicatorsEntryDecision", item.getName(), "decision") == "enable") { int decisionPoint = int.Parse(getValue("indicatorsEntryDecision", item.getName(), "decisionPoint")); if (item.getResult() >= decisionPoint) { operation = "long"; break; } } if (getValue("indicatorsEntryDecision", item.getName(), "tendency") == "enable") { if (item.getTendency() == Tendency.high) { operation = "long"; break; } } } } //EXECUTE OPERATION if (operation == "long") { makeOrder("Buy"); } ////////////FINAL VERIFY OPERATION LONG////////////////// } if (statusShort == "enable") { ////////////////////////////////////////////////////////////// log(""); log("=========================================================="); log(" ==================== Verify SHORT OPERATION =============", ConsoleColor.Red); log("=========================================================="); /////VERIFY OPERATION LONG string operation = "sell"; //VERIFY INDICATORS ENTRY foreach (var item in lstIndicatorsEntry) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (operationBuy != Operation.sell) { operation = "nothing"; break; } } //VERIFY INDICATORS CROSS if (operation == "sell") { //Prepare to long while (true) { log("wait operation short..."); getCandles(); foreach (var item in lstIndicatorsEntryCross) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator Cross: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (item.getTypeIndicator() == TypeIndicator.Cross) { if (operationBuy == Operation.sell) { operation = "short"; break; } } else if (operationBuy != Operation.sell) { operation = "short"; break; } } if (lstIndicatorsEntryCross.Count == 0) { operation = "short"; } if (operation != "sell") { break; } log("wait " + interval + "ms"); Thread.Sleep(interval); } } //VERIFY INDICATORS DECISION if (operation == "short" && lstIndicatorsEntryDecision.Count > 0) { operation = "decision"; foreach (var item in lstIndicatorsEntryDecision) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator Decision: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (getValue("indicatorsEntryDecision", item.getName(), "decision") == "enable" && getValue("indicatorsEntryDecision", item.getName(), "tendency") == "enable") { int decisionPoint = int.Parse(getValue("indicatorsEntryDecision", item.getName(), "decisionPoint")); if (item.getResult() <= decisionPoint && item.getTendency() == Tendency.low) { operation = "short"; break; } } if (getValue("indicatorsEntryDecision", item.getName(), "decision") == "enable") { int decisionPoint = int.Parse(getValue("indicatorsEntryDecision", item.getName(), "decisionPoint")); if (item.getResult() <= decisionPoint) { operation = "short"; break; } } if (getValue("indicatorsEntryDecision", item.getName(), "tendency") == "enable") { if (item.getTendency() == Tendency.low) { operation = "short"; break; } } } } //EXECUTE OPERATION if (operation == "short") { makeOrder("Sell"); } ////////////FINAL VERIFY OPERATION LONG////////////////// } } log("wait " + interval + "ms", ConsoleColor.Blue); Thread.Sleep(interval); } } catch (Exception ex) { log("ERROR FATAL::" + ex.Message + ex.StackTrace); } }
public static void Main(string[] args) { try { Console.Title = "Loading..."; Console.ForegroundColor = ConsoleColor.White; log("Deleron - Back to the future - v" + version + " - Bitmex version"); log("by Matheus Grijo ", ConsoleColor.Green); log("GITHUB http://github.com/matheusgrijo", ConsoleColor.Blue); log("Load config..."); String jsonConfig = System.IO.File.ReadAllText(location + "key.txt"); JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(jsonConfig, (typeof(JContainer))); bitmexKey = jCointaner["key"].ToString(); bitmexSecret = jCointaner["secret"].ToString(); bitmexKeyWeb = jCointaner["webserverKey"].ToString(); bitmexSecretWeb = jCointaner["webserverSecret"].ToString(); bitmexDomain = jCointaner["domain"].ToString(); pair = jCointaner["pair"].ToString(); qtdyContacts = int.Parse(jCointaner["contract"].ToString()); interval = int.Parse(jCointaner["interval"].ToString()); intervalCapture = int.Parse(jCointaner["webserverIntervalCapture"].ToString()); bitMEXApi = new BitMEX.BitMEXApi(bitmexKey, bitmexSecret, bitmexDomain); if (jCointaner["webserver"].ToString() == "enable") { WebServer ws = new WebServer(WebServer.SendResponse, jCointaner["webserverConfig"].ToString()); ws.Run(); System.Threading.Thread tCapture = new Thread(Database.captureDataJob); tCapture.Start(); System.Threading.Thread.Sleep(1000); OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; if (pid != PlatformID.Unix) { System.Diagnostics.Process.Start(jCointaner["webserverConfig"].ToString()); } } log("Total open orders: " + bitMEXApi.GetOpenOrders(pair).Count); log(""); log("Wallet: " + bitMEXApi.GetWallet()); string codeTendency = ""; //LOOP while (true) { try { //Surf mode String json = Http.get("https://anubis.website/api/anubis/trend/"); JContainer jTrrend = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); int open = getPosition(); //OPEN LONG if (jTrrend["data"][0]["trend"].ToString() == "LONG") { if (open <= 0) { open = Math.Abs(open); codeTendency = jTrrend["data"][0]["timestamp"].ToString(); bitMEXApi.MarketOrder(pair, "Buy", qtdyContacts + open); } } //OPEN SHORT if (jTrrend["data"][0]["trend"].ToString() == "SHORT") { if (open >= 0) { codeTendency = jTrrend["data"][0]["timestamp"].ToString(); bitMEXApi.MarketOrder(pair, "Sell", qtdyContacts + open); } } log("wait " + interval + "ms", ConsoleColor.White); Thread.Sleep(interval); } catch (Exception ex) { log("while true::" + ex.Message + ex.StackTrace); } } } catch (Exception ex) { log("ERROR FATAL::" + ex.Message + ex.StackTrace); } }
public static void Main(string[] args) { IStrategies strategy = null; try { //Config Console.Title = "Loading..."; Console.ForegroundColor = ConsoleColor.White; log("Tesourinho Deprimente - Devolve tudo ao mercado - v" + version); log("by Matheus Grijo ", ConsoleColor.Green); log(" ======= HALL OF FAME BOTMEX ======= "); log(" - Lucas Sousa", ConsoleColor.Magenta); log(" - Carlos Morato", ConsoleColor.Magenta); log(" - Luis Felipe Alves", ConsoleColor.Magenta); log(" - O Zuca que toda a gente pensa que está Bebendo", ConsoleColor.Green); log(" - O Portuga da Maconha", ConsoleColor.Red); log(" ======= END HALL OF FAME BOTMEX ======= "); log("http://botmex.ninja/"); log("GITHUB http://github.com/tperalta82/botmex", ConsoleColor.Blue); log(" ******* DONATE ********* "); log("BTC: 3NoXn5PHyBAxxQAc2LCruWoEhthWsAdSR8"); log("LTC: MKPZ2XZep3pTfggjBpiSgjRofDAEbBC8qp "); log("ETH: 0x172bdb1ab580128d42993c00a60AF99b726eaF81"); log("Load config..."); log("Considere DOAR para o projeto, senão oh, fico sem maconha e as ideias boas vão com o caralho!", ConsoleColor.Green); String jsonConfig = System.IO.File.ReadAllText(location + "key.json"); JContainer config = (JContainer)JsonConvert.DeserializeObject(jsonConfig, (typeof(JContainer))); sharedConfig = config; usedb = config["usedb"].ToString() == "enable"; bitmexKey = config["key"].ToString(); bitmexSecret = config["secret"].ToString(); bitmexWebSocketDomain = config["websocketDomain"].ToString(); bitmexKeyWebSocket = config["websocketKey"].ToString(); bitmexSecretWebSocket = config["websocketSecret"].ToString(); bitmexDomain = config["domain"].ToString(); statusShort = config["short"].ToString(); statusLong = config["long"].ToString(); pair = config["pair"].ToString(); ClassDB.strConn = config["dbcon"].ToString(); ClassDB.dbquery = config["dbquery"].ToString(); timeGraph = config["timeGraph"].ToString(); qtdyContacts = int.Parse(config["contract"].ToString()); interval = int.Parse(config["interval"].ToString()); intervalCancelOrder = int.Parse(config["intervalCancelOrder"].ToString()); intervalOrder = int.Parse(config["intervalOrder"].ToString()); intervalCapture = int.Parse(config["webserverIntervalCapture"].ToString()); profit = double.Parse(config["profit"].ToString()); fee = double.Parse(config["fee"].ToString()); stoploss = double.Parse(config["stoploss"].ToString()); stepValue = double.Parse(config["stepvalue"].ToString()); stopgain = double.Parse(config["stopgain"].ToString()); roeAutomatic = config["roe"].ToString() == "automatic"; tendencyBook = config["tendencyBook"].ToString() == "enable"; operation = config["operation"].ToString(); limiteOrder = int.Parse(config["limiteOrder"].ToString()); carolatr = config["carolatr"].ToString() == "enable"; atrvalue = double.Parse(config["atrvalue"].ToString()); apiDebug = bool.Parse(config["apidebug"].ToString()); bitMEXApi = new BitMEX.BitMEXApi(bitmexKey, bitmexSecret, bitmexDomain, 5000, apiDebug); marketTaker = config["marketTaker"].ToString() == "enable"; obDiff = double.Parse(config["obDiff"].ToString()); stoplosstype = config["stoplosstype"].ToString(); stoplossInterval = int.Parse(config["stoplossInterval"].ToString()); if (config["webserver"].ToString() == "enable") { WebServer ws = new WebServer(WebServer.SendResponse, config["webserverConfig"].ToString()); ws.Run(); System.Threading.Thread tCapture = new Thread(Database.captureDataJob); tCapture.Start(); System.Threading.Thread.Sleep(1000); OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; if (pid != PlatformID.Unix) { System.Diagnostics.Process.Start(config["webserverConfig"].ToString()); } } log("Total open orders: " + bitMEXApi.GetOpenOrders(pair).Count); log(""); log("Wallet: " + bitMEXApi.GetWallet()); foreach (var item in config["indicatorsEntry"]) { IIndicator ind = LoadIndicator(item["name"].ToString().Trim().ToUpper()); Dictionary <string, string> cfg = new Dictionary <string, string>(); foreach (JProperty cfgitem in item) { cfg.Add(cfgitem.Name.ToString(), cfgitem.Value.ToString()); } ind.Setup(cfg); lstIndicatorsEntry.Add(ind); } foreach (var item in config["indicatorsEntryCross"]) { IIndicator ind = LoadIndicator(item["name"].ToString().Trim().ToUpper()); Dictionary <string, string> cfg = new Dictionary <string, string>(); foreach (JProperty cfgitem in item) { cfg.Add(cfgitem.Name.ToString(), cfgitem.Value.ToString()); } ind.Setup(cfg); lstIndicatorsEntryCross.Add(ind); } foreach (var item in config["indicatorsEntryThreshold"]) { IIndicator ind = LoadIndicator(item["name"].ToString().Trim().ToUpper()); Dictionary <string, string> cfg = new Dictionary <string, string>(); foreach (JProperty cfgitem in item) { cfg.Add(cfgitem.Name.ToString(), cfgitem.Value.ToString()); } ind.Setup(cfg); lstIndicatorsEntryThreshold.Add(ind); } foreach (var item in config["indicatorsInvert"]) { IIndicator ind = LoadIndicator(item["name"].ToString().Trim().ToUpper()); Dictionary <string, string> cfg = new Dictionary <string, string>(); foreach (JProperty cfgitem in item) { cfg.Add(cfgitem.Name.ToString(), cfgitem.Value.ToString()); } ind.Setup(cfg); lstIndicatorsInvert.Add(ind); } foreach (var item in config["strategyOptions"]) { strategyOptions[item["name"].ToString().Trim().ToLower()] = item["value"].ToString().Trim(); } bool automaticTendency = statusLong == "automatic"; /* Get initial candles */ getCandles("1m", false); getCandles("5m", false); getCandles("1h", false); Thread.Sleep(2000); Timer wsHandle = new Timer(handleWebsockets, null, TimeSpan.Zero, TimeSpan.FromSeconds(15)); if (operation == "manual") { while (true) { System.Threading.Thread.Sleep(2000); } } //Threaded SL if (stoplosstype != "strategy") { Timer slt = new Timer(runSL, null, TimeSpan.Zero, TimeSpan.FromSeconds(stoplossInterval)); } //TESTS HERE if (operation == "debug") { tests(); System.Environment.Exit(1); } //FINAL //LOOP while (true) { try { if ((useWebSockets && RunTrigger) || !useWebSockets) { positionContracts = getPosition(); // FIX CARLOS MORATO positionPrice = 0; if (positionContracts != 0) { positionPrice = getPositionPrice(); } log("positionContracts " + positionContracts); log("positionPrice " + positionPrice); #region "Fix position not orders if (operation == "normal" || operation == "scalper" || operation == "scalperv2" || operation == "bingo") { fixOrdersPosition(); } #endregion if (automaticTendency) { verifyTendency(); } //GET CANDLES if (useWebSockets || getCandles(timeGraph, false, true)) { if (operation == "normal" || operation == "surf") { Normal.run(); } else if (operation == "scalper") { Scalper.run(); } else if (operation == "scalperv2") { ScalperV2.run(); } else if (operation == "bingo") { Bingo.run(); } else { if (strategy == null) { MainClass.log("Loading Strategies"); string[] strategies = Directory.GetFiles(location, "Strategy*.dll"); Type strat = Type.GetType("Botmex.Strategies." + operation.First().ToString().ToUpper() + operation.Substring(1)); log(operation.First().ToString().ToUpper() + operation.Substring(1)); foreach (string dllStrategy in strategies) { log(dllStrategy); try { log("Trying to load Strategy: " + dllStrategy); var assembly = Assembly.LoadFile(@dllStrategy); Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.ToString().Equals("Botmex.Strategies." + operation.First().ToString().ToUpper() + operation.Substring(1))) { strat = assembly.GetType("Botmex.Strategies." + operation.First().ToString().ToUpper() + operation.Substring(1)); } } } catch (Exception ex) { log("Cold not load strategy: " + dllStrategy + ex.ToString()); } } if (strat == null) { log("Estrategia não encontrada", ConsoleColor.Red); System.Environment.Exit(1); } strategy = (IStrategies)Activator.CreateInstance(strat); } strategy.run(); } } RunTrigger = false; } if (useWebSockets) { Thread.Sleep(20); } else { log("wait " + interval + "ms", ConsoleColor.Blue); Thread.Sleep(interval); } } catch (Exception ex) { RunTrigger = false; log("while true::" + ex.Message + ex.StackTrace); } } } catch (Exception ex) { log("ERROR FATAL::" + ex.Message + ex.StackTrace); Console.ReadLine(); } }
public static void Main(string[] args) { try { //Config log("BOTMEX - ONOBOT - v" + version + " - Bitmex version"); log("by ONO NAKAMOTO"); log("GITHUB http://github.com/ononakamoto"); log(" ******* DONATE ********* "); log("BTC 36dbH2hr1mphZYrNKzYBHXLK1sgEwEYF2m"); log("Load config..."); String jsonConfig = System.IO.File.ReadAllText(location + "key.txt"); JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(jsonConfig, (typeof(JContainer))); bitmexKey = jCointaner["key"].ToString(); bitmexSecret = jCointaner["secret"].ToString(); bitmexKeyWeb = jCointaner["webserverKey"].ToString(); bitmexSecretWeb = jCointaner["webserverSecret"].ToString(); bitmexDomain = jCointaner["domain"].ToString(); statusShort = jCointaner["short"].ToString(); statusLong = jCointaner["long"].ToString(); pair = jCointaner["pair"].ToString(); timeGraph = jCointaner["timeGraph"].ToString(); qtdyContacts = int.Parse(jCointaner["contract"].ToString()); interval = int.Parse(jCointaner["interval"].ToString()); intervalOrder = int.Parse(jCointaner["intervalOrder"].ToString()); intervalCapture = int.Parse(jCointaner["webserverIntervalCapture"].ToString()); profit = double.Parse(jCointaner["profit"].ToString()); fee = double.Parse(jCointaner["fee"].ToString()); if (jCointaner["webserver"].ToString() == "enable") { WebServer ws = new WebServer(WebServer.SendResponse, jCointaner["webserverConfig"].ToString()); ws.Run(); System.Threading.Thread tCapture = new Thread(Database.captureDataJob); tCapture.Start(); System.Threading.Thread.Sleep(1000); } bitMEXApi = new BitMEX.BitMEXApi(bitmexKey, bitmexSecret, bitmexDomain); log("wait 1s..."); System.Threading.Thread.Sleep(1000); log("Total open orders: " + bitMEXApi.GetOpenOrders(pair).Count); log(""); log("Wallet: " + bitMEXApi.GetWallet()); lstIndicatorsAll.Add(new IndicatorMFI()); lstIndicatorsAll.Add(new IndicatorBBANDS()); lstIndicatorsAll.Add(new IndicatorCCI()); lstIndicatorsAll.Add(new IndicatorCMO()); lstIndicatorsAll.Add(new IndicatorDI()); lstIndicatorsAll.Add(new IndicatorDM()); lstIndicatorsAll.Add(new IndicatorMA()); lstIndicatorsAll.Add(new IndicatorMACD()); lstIndicatorsAll.Add(new IndicatorMOM()); lstIndicatorsAll.Add(new IndicatorPPO()); lstIndicatorsAll.Add(new IndicatorROC()); lstIndicatorsAll.Add(new IndicatorRSI()); lstIndicatorsAll.Add(new IndicatorSAR()); lstIndicatorsAll.Add(new IndicatorSTOCH()); lstIndicatorsAll.Add(new IndicatorSTOCHRSI()); lstIndicatorsAll.Add(new IndicatorTRIX()); lstIndicatorsAll.Add(new IndicatorULTOSC()); lstIndicatorsAll.Add(new IndicatorWILLR()); foreach (var item in jCointaner["indicatorsEntry"]) { foreach (var item2 in lstIndicatorsAll) { if (item["name"].ToString().Trim().ToUpper() == item2.getName().Trim().ToUpper()) { item2.setPeriod(int.Parse((item["period"].ToString().Trim().ToUpper()))); lstIndicatorsEntry.Add(item2); } } } foreach (var item in jCointaner["indicatorsEntryCross"]) { foreach (var item2 in lstIndicatorsAll) { if (item["name"].ToString().Trim().ToUpper() == item2.getName().Trim().ToUpper()) { item2.setPeriod(int.Parse((item["period"].ToString().Trim().ToUpper()))); lstIndicatorsEntryCross.Add(item2); } } } foreach (var item in jCointaner["indicatorsEntryDecision"]) { foreach (var item2 in lstIndicatorsAll) { if (item["name"].ToString().Trim().ToUpper() == item2.getName().Trim().ToUpper()) { item2.setPeriod(int.Parse((item["period"].ToString().Trim().ToUpper()))); lstIndicatorsEntryDecision.Add(item2); } } } if (jCointaner["webserver"].ToString() == "enable") { System.Diagnostics.Process.Start(jCointaner["webserverConfig"].ToString()); } //LOOP while (true) { //GET CANDLES if (getCandles()) { /////VERIFY OPERATION LONG string operation = "buy"; //VERIFY INDICATORS ENTRY foreach (var item in lstIndicatorsEntry) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (operationBuy != Operation.buy) { operation = "nothing"; break; } } //VERIFY INDICATORS CROSS if (operation == "buy") { //Prepare to long while (true) { log("wait operation long..."); getCandles(); foreach (var item in lstIndicatorsEntryCross) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator Cross: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (item.getTypeIndicator() == TypeIndicator.Cross) { if (operationBuy == Operation.buy) { operation = "long"; break; } } else if (operationBuy != Operation.buy) { operation = "long"; break; } } if (lstIndicatorsEntryCross.Count == 0) { operation = "long"; } if (operation != "buy") { break; } log("wait " + interval + "ms"); Thread.Sleep(interval); } } //VERIFY INDICATORS DECISION if (operation == "long" && lstIndicatorsEntryDecision.Count > 0) { operation = "decision"; foreach (var item in lstIndicatorsEntryDecision) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator Decision: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (getValue("indicatorsEntryDecision", item.getName(), "decision") == "enable" && getValue("indicatorsEntryDecision", item.getName(), "tendency") == "enable") { int decisionPoint = int.Parse(getValue("indicatorsEntryDecision", item.getName(), "decisionPoint")); if (item.getResult() >= decisionPoint && item.getTendency() == Tendency.high) { operation = "long"; break; } } if (getValue("indicatorsEntryDecision", item.getName(), "decision") == "enable") { int decisionPoint = int.Parse(getValue("indicatorsEntryDecision", item.getName(), "decisionPoint")); if (item.getResult() >= decisionPoint) { operation = "long"; break; } } if (getValue("indicatorsEntryDecision", item.getName(), "tendency") == "enable") { if (item.getTendency() == Tendency.high) { operation = "long"; break; } } } } //EXECUTE OPERATION if (operation == "long") { makeOrder("Buy"); } ////////////FINAL VERIFY OPERATION LONG////////////////// ////////////////////////////////////////////////////////////// /////VERIFY OPERATION LONG operation = "sell"; //VERIFY INDICATORS ENTRY foreach (var item in lstIndicatorsEntry) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (operationBuy != Operation.sell) { operation = "nothing"; break; } } //VERIFY INDICATORS CROSS if (operation == "sell") { //Prepare to long while (true) { log("wait operation short..."); getCandles(); foreach (var item in lstIndicatorsEntryCross) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator Cross: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (item.getTypeIndicator() == TypeIndicator.Cross) { if (operationBuy == Operation.sell) { operation = "short"; break; } } else if (operationBuy != Operation.sell) { operation = "short"; break; } } if (lstIndicatorsEntryCross.Count == 0) { operation = "short"; } if (operation != "sell") { break; } log("wait " + interval + "ms"); Thread.Sleep(interval); } } //VERIFY INDICATORS DECISION if (operation == "short" && lstIndicatorsEntryDecision.Count > 0) { operation = "decision"; foreach (var item in lstIndicatorsEntryDecision) { Operation operationBuy = item.GetOperation(arrayPriceOpen, arrayPriceClose, arrayPriceLow, arrayPriceHigh, arrayPriceVolume); log("Indicator Decision: " + item.getName()); log("Result1: " + item.getResult()); log("Result2: " + item.getResult2()); log("Operation: " + operationBuy.ToString()); log(""); if (getValue("indicatorsEntryDecision", item.getName(), "decision") == "enable" && getValue("indicatorsEntryDecision", item.getName(), "tendency") == "enable") { int decisionPoint = int.Parse(getValue("indicatorsEntryDecision", item.getName(), "decisionPoint")); if (item.getResult() <= decisionPoint && item.getTendency() == Tendency.low) { operation = "short"; break; } } if (getValue("indicatorsEntryDecision", item.getName(), "decision") == "enable") { int decisionPoint = int.Parse(getValue("indicatorsEntryDecision", item.getName(), "decisionPoint")); if (item.getResult() <= decisionPoint) { operation = "short"; break; } } if (getValue("indicatorsEntryDecision", item.getName(), "tendency") == "enable") { if (item.getTendency() == Tendency.low) { operation = "short"; break; } } } } //EXECUTE OPERATION if (operation == "short") { makeOrder("Sell"); } ////////////FINAL VERIFY OPERATION LONG////////////////// } log("wait " + interval + "ms"); Thread.Sleep(interval); } } catch (Exception ex) { log("ERROR FATAL::" + ex.Message + ex.StackTrace); } }
public static void captureData() { lock (MainClass.data) { string dataBaseFile = MainClass.location + "bd.xml"; try { System.Data.DataSet ds = null; bool create = false; if (!System.IO.File.Exists(dataBaseFile)) { System.Data.DataTable dt = new System.Data.DataTable("Balances"); dt.Columns.Add("Date"); dt.Columns.Add("Coin"); dt.Columns.Add("Amount"); dt.Rows.Add("", "", ""); System.Data.DataTable dtParameters = new System.Data.DataTable("Parameters"); dtParameters.Columns.Add("Parameter"); dtParameters.Columns.Add("Value"); dtParameters.Rows.Add("", ""); ds = new System.Data.DataSet(); ds.DataSetName = "Database"; ds.Tables.Add(dt); ds.Tables.Add(dtParameters); ds.WriteXml(dataBaseFile); create = true; } ds = new System.Data.DataSet(); ds.ReadXml(dataBaseFile); BitMEX.BitMEXApi bitMEXApi = new BitMEX.BitMEXApi(MainClass.bitmexKey, MainClass.bitmexSecret, MainClass.bitmexDomain); string json = bitMEXApi.GetWallet(); JContainer data = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer))); ClassDB.execS(ClassDB.dbquery.Replace("@balance", data[0]["walletBalance"].ToString().Replace(",", "."))); if (create) { ds.Tables[0].Rows.Clear(); } ds.Tables[0].Rows.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), MainClass.pair, data[0]["walletBalance"].ToString()); ds.Tables[1].Rows.Clear(); ds.Tables[1].Rows.Add("OpenOrders", bitMEXApi.GetOpenOrders(MainClass.pair).Count); ds.Tables[1].Rows.Add("Amount", data[0]["walletBalance"].ToString()); System.IO.File.Delete(dataBaseFile); ds.WriteXml(dataBaseFile); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }