示例#1
0
    static void makeOrder(string side)
    {
        try
        {
            log("Make order " + side);
            if (side == "Sell" && statusShort == "enable")
            {
                String json = bitMEXApi.MarketOrder(pair, "Sell", qtdyContacts);
                log(json);
                JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer)));
                double     price      = double.Parse(jCointaner["price"].ToString().Replace(".", "."));
                price -= (price * (fee + profit)) / 100;
                price  = Math.Floor(price);
                json   = bitMEXApi.PostOrderPostOnly(pair, "Buy", price, qtdyContacts);
                log(json);
            }
            if (side == "Buy" && statusLong == "enable")
            {
                String json = bitMEXApi.MarketOrder(pair, "Buy", qtdyContacts);
                log(json);
                JContainer jCointaner = (JContainer)JsonConvert.DeserializeObject(json, (typeof(JContainer)));
                double     price      = double.Parse(jCointaner["price"].ToString().Replace(".", "."));
                price += (price * (fee + profit)) / 100;
                price  = Math.Ceiling(price);
                json   = bitMEXApi.PostOrderPostOnly(pair, "Sell", price, qtdyContacts);
                log(json);
            }
        }
        catch (Exception ex)
        {
            log("ERRO MAKEORDER " + ex.Message + ex.StackTrace);
        }

        log("wait " + intervalOrder + "ms");
        Thread.Sleep(intervalOrder);
    }
示例#2
0
    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&currency=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);
        }
    }
示例#3
0
    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);
        }
    }