Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            CurrencyState state    = new CurrencyState();
            Trader        myTrader = new Trader();
            Wallet        myWallet = new Wallet();

            double InitialUSDT = myWallet.GetUSDT();

            Console.WriteLine("Starting balance: {0} BTC || {1} USDT.", myWallet.GetBTC(), myWallet.GetUSDT());
            Console.WriteLine("Press any key to continue..");
            Console.ReadLine();


            while (Analyzer.GetApproval(state.GetClosePrice(), state.GetLowPrice()) && state.UpdatePrice())
            {
                state.UpdatePrice();
                myTrader.UpdateTrades(ref state, myWallet);
            }


            Console.WriteLine("\nEnding balance: {0} BTC || {1} USDT.", myWallet.GetBTC(), myWallet.GetUSDT());
            Console.WriteLine("Net revenue USDT: {0}", ((myWallet.GetBTC() * state.GetClosePrice()) + myWallet.GetUSDT()) - InitialUSDT);
            Console.WriteLine("Total trades: {0} and Loose Sells: {1} Consecutive: {2}", myWallet.totalTrades, myTrader.totalLooseSells, myTrader.consecutiLooseSellsCounter);

            Console.WriteLine("Average Modifier: " + myTrader.buyingPriceModifier);
            Console.WriteLine("Min. revenue: " + myTrader.minRevenue);
            Console.WriteLine("Loose tolerance: " + myTrader.dropTolerance);

            Console.WriteLine("Press any key to exit..");
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public void UpdateTrades(ref CurrencyState state, Wallet myWallet)
        {
            double BTC_open    = state.GetOpenPrice();
            double BTC_close   = state.GetClosePrice();
            double BTC_low     = state.GetLowPrice();
            double BTC_high    = state.GetHighPrice();
            double BTC_average = state.GetAveragePrice();

            double BTC_buyPrice  = myWallet.GetBTCbuyPrice();
            double BTC_sellPrice = myWallet.GetBTCsellPrice();



            Console.WriteLine("BTC Price = {0} || AVERAGE = {1}", BTC_close, BTC_average);

            //BUYING
            if (myWallet.GetBuyAuthorization())
            {
                if (BTC_close < BTC_open && !loosingMoney)
                {
                    myWallet.UpdateBTC(myWallet.GetUSDTfunds() / BTC_close);
                    myWallet.UpdateBuyPrice(BTC_close);

                    Console.WriteLine("\nTrade authorized - Purchase Case 1! {0} BTC bought at {1}.", myWallet.GetBTC(), BTC_close);
                    Console.WriteLine("Current Balance: BTC: {0} || USDT: {1}", myWallet.GetBTC(), myWallet.GetUSDT());
                    Console.WriteLine("Case 1: Current BTC price is lower than last 24hs AVERAGE.\n");// DEBUG INFO

                    return;
                }


                //Buy BTC if last price is lower than average
                else if (BTC_close < BTC_average * 0.99 && loosingMoney)
                {
                    myWallet.UpdateBTC(myWallet.GetUSDTfunds() / BTC_close);
                    myWallet.UpdateBuyPrice(BTC_close);

                    Console.WriteLine("\nTrade authorized - Purchase Case 1! {0} BTC bought at {1}.", myWallet.GetBTC(), BTC_close);
                    Console.WriteLine("Current Balance: BTC: {0} || USDT: {1}", myWallet.GetBTC(), myWallet.GetUSDT());
                    Console.WriteLine("Case 1: Current BTC price is lower than last 24hs AVERAGE.\n");// DEBUG INFO

                    return;
                }



                /*
                 * //Buy BTC if last price is a n% lower than last selling price
                 * else if (BTC_Price < myWallet.GetBTCsellPrice() * buyingPriceModifier && consecutiveLooseSells <= consecutiLooseSellThreshold)
                 * {
                 *  myWallet.UpdateBTC(myWallet.GetUSDTfunds() / state.GetLastPrice());
                 *  myWallet.UpdateBuyPrice(state.GetLastPrice());
                 *
                 *  Console.WriteLine("\nTrade authorized - Purchase Case 2! {0} BTC bought at {1}.", myWallet.GetBTC(), state.GetLastPrice());
                 *  Console.WriteLine("Current Balance: BTC: {0} || USDT: {1}", myWallet.GetBTC(), myWallet.GetUSDT());
                 *  Console.WriteLine("Case 2: Current BTC price is lower than last SELL PRICE.\n"); //DEBUG INFO
                 *
                 *  return;
                 * }
                 */

                else if (BTC_open > BTC_average && loosingMoney)
                {
                    myWallet.UpdateBTC(myWallet.GetUSDTfunds() / BTC_close);
                    myWallet.UpdateBuyPrice(BTC_close);

                    Console.WriteLine("AFTER LOOSE BUY!");//TO BE REMOVED
                    Console.WriteLine("Trade authorized! {0} BTC bought at {1}.", myWallet.GetBTC(), BTC_close);
                    Console.WriteLine("Current Balance: BTC: {0} || USDT: {1}", myWallet.GetBTC(), myWallet.GetUSDT());

                    return;
                }
            }


            //SELLING
            else if (myWallet.GetSellAuthorization())
            {
                //Sells BTC if price reaches or surppases expected revenue.
                if (BTC_close > BTC_buyPrice * minRevenue)
                {
                    Console.WriteLine("\nTrade authorized! - Sale Case 1! {0} BTC sold at {1}.", myWallet.GetBTC(), BTC_close);

                    myWallet.UpdateUSDT(myWallet.GetBTCfunds() * BTC_close + myWallet.GetUSDT());
                    myWallet.UpdateSellPrice(BTC_close);

                    Console.WriteLine("Current Balance: BTC: {0} || USDT: {1}", myWallet.GetBTC(), myWallet.GetUSDT());

                    loosingMoney = false;

                    consecutiLooseSells = 0;

                    return;
                }

                //Sells BTC if price drops lower than a n% to prevent losses.
                else if (BTC_close < BTC_buyPrice * dropTolerance)
                {
                    Console.WriteLine("\nTrade authorized! Sale Case 2! {0} BTC sold at {1}.", myWallet.GetBTC(), BTC_close);

                    myWallet.UpdateUSDT(myWallet.GetBTCfunds() * BTC_close + myWallet.GetUSDT());
                    myWallet.UpdateSellPrice(BTC_close);

                    Console.WriteLine("Current Balance: BTC: {0} || USDT: {1}", myWallet.GetBTC(), myWallet.GetUSDT());

                    //loosingMoney = true;

                    consecutiLooseSells++;

                    if (consecutiLooseSells == 3)
                    {
                        //Console.ReadLine();
                        consecutiLooseSellsCounter++;
                        consecutiLooseSells = 0;
                    }

                    totalLooseSells++;

                    return;
                }
            }
        }