예제 #1
0
        /// <summary>
        /// The method with switch cases
        /// </summary>
        /// <param name="type">strategy name in string</param>
        /// <param name="context">parameter to pass to strategy(for test)</param>
        /// <returns></returns>
        public bool SwitchCaseMethod(String type, String context)
        {
            try
            {
                var assembly = Assembly.GetExecutingAssembly();

                var strategyClassName = assembly.GetTypes()
                                        .First(t => t.Name == type);

                IStrategies strategy = (IStrategies)Activator.CreateInstance(strategyClassName);
                strategy.Action(context);
                return(true);
            }
            catch (Exception err)
            {
                Console.WriteLine($"Error: {err}");
                return(false);
            }
        }
예제 #2
0
 /// <summary>
 /// Create an instance of <see cref="BinaryValue"/> from the specified byte array
 /// </summary>
 /// <param name="binaryValue">The input byte array</param>
 /// <param name="strategies">The <see cref="IStrategies"/> to use</param>
 public BinaryValue(byte[] binaryValue, IStrategies strategies)
 {
     this.binaryValue = binaryValue;
     this.strategies  = strategies;
 }
예제 #3
0
    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();
        }
    }
예제 #4
0
 /// <summary>
 /// Create an instance of <see cref="TypeValue{T}"/> from the specified object
 /// </summary>
 /// <param name="typeInstance">The input object</param>
 /// <param name="strategies">The <see cref="IStrategies"/> to use</param>
 /// <returns>An instance of <see cref="TypeValue{T}"/></returns>
 public static TypeValue <T> Object <T>(T typeInstance, IStrategies strategies = null) => new TypeValue <T>(typeInstance, strategies);
예제 #5
0
 /// <summary>
 /// Create an instance of <see cref="BinaryValue"/> from the specified byte array
 /// </summary>
 /// <param name="binaryValue">The input byte array</param>
 /// <param name="strategies">The <see cref="IStrategies"/> to use</param>
 /// <returns>An instance of <see cref="BinaryValue"/></returns>
 public static BinaryValue Bytes(byte[] binaryValue, IStrategies strategies = null) => new BinaryValue(binaryValue, strategies);
예제 #6
0
 /// <summary>
 /// Create an instance of <see cref="StringValue"/> from the specified string
 /// </summary>
 /// <param name="stringValue">The input string</param>
 /// <param name="strategies">The <see cref="IStrategies"/> to use</param>
 /// <returns>An instance of <see cref="StringValue"/></returns>
 public static StringValue String(string stringValue, IStrategies strategies = null) => new StringValue(stringValue, strategies);
예제 #7
0
 /// <summary>
 /// Create an instance of <see cref="StringValue"/> from the specified string
 /// </summary>
 /// <param name="stringValue">The input string</param>
 /// <param name="strategies">The <see cref="IStrategies"/> to use</param>
 public StringValue(string stringValue, IStrategies strategies)
 {
     this.stringValue = stringValue;
     this.strategies  = strategies;
 }
예제 #8
0
 /// <summary>
 /// Create an instance of <see cref="TypeValue{T}"/> from an instance of the specified type
 /// </summary>
 /// <param name="typeInstance">The input instance</param>
 /// <param name="strategies">The <see cref="IStrategies"/> to use</param>
 public TypeValue(T typeInstance, IStrategies strategies)
 {
     this.typeInstance = typeInstance;
     this.strategies   = strategies;
 }