Exemple #1
0
        private static void GenerateBTCProfitRecordings()
        {
            ProfitRecording pf = new ProfitRecording();

            var     luno      = LunoApi.GetLunoResult(0.00001M, LunoSymbolEnum.XBTZAR);
            decimal bestprice = ((luno.ask.price + luno.bid.price) / 2);

            //var bitlishUSD = BitlishApi.GetBestPrices(BitlsihSymbolEnum.BtcUsd, 0.01m);
            //var bitlishEUR = BitlishApi.GetBestPrices(BitlsihSymbolEnum.BtcEur, 0.01m);

            var cexUSD = CexApi.GetBestPrices(CEXSymbolEnum.Btc_Usd, 0.01m);
            var cexEUR = CexApi.GetBestPrices(CEXSymbolEnum.Btc_Eur, 0.01m);
            var cexGBP = CexApi.GetBestPrices(CEXSymbolEnum.Btc_Gbp, 0.01m);

            var bitfinexUSD = BitfinexApi.GetBestPrices(BitfinexSymbolEnum.BtcUsd, 0.01m);

            var bitstampUSD = BitstampApi.GetBestPrices(BitstampSymbolEnum.BTCUSD, 0.01m);
            var bitstampEUR = BitstampApi.GetBestPrices(BitstampSymbolEnum.BTCEUR, 0.01m);


            decimal usdzar = 0m;
            decimal eurzar = 0m;
            decimal rubzar = 0m;
            decimal gbpzar = 0m;


            try
            {
                usdzar = CurrencyHelper.ConvertToZAR(1, CurrencyHelper.CurrencyEnum.Usd);
                eurzar = CurrencyHelper.ConvertToZAR(1, CurrencyHelper.CurrencyEnum.Eur);
                // rubzar = CurrencyHelper.ConvertToZAR(1, CurrencyHelper.CurrencyEnum.Rub);
                gbpzar = CurrencyHelper.ConvertToZAR(1, CurrencyHelper.CurrencyEnum.Gbp);
            }
            catch
            {
                // failed to get live rates - use latest
                ProfitRecording recEUR = GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.EUR, "BTC");
                ProfitRecording recUSD = GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.USD, "BTC");
                ProfitRecording recGBP = GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.GBP, "BTC");

                eurzar = recEUR.CurrencyToZARExchangeRate;
                usdzar = recUSD.CurrencyToZARExchangeRate;
                gbpzar = recGBP.CurrencyToZARExchangeRate;
            }

            decimal profPerc = 0;

            //// Bitlish USD;

            //try
            //{
            //    profPerc = GetProfit(bitlishUSD.ask.price, luno.bid.price, usdzar, 0.4M, 4.84M, 4000);

            //    pf = new ProfitRecording();
            //    pf.Exchange = enExchange.Bitlish;
            //    pf.Currency = enCurrency.USD;
            //    pf.LunoBid = luno.bid.price;
            //    pf.ExchangeAsk = bitlishUSD.ask.price;
            //    pf.CurrencyToZARExchangeRate = usdzar;
            //    pf.ProfitPerc = profPerc;
            //    pf.ArbSymblol = "BTC";
            //    pf.Save();
            //}
            //catch
            //{// duplicate last recording

            //    ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitlish, enCurrency.USD, "BTC");
            //    pf = new ProfitRecording();
            //    pf.Exchange = pflast.Exchange;
            //    pf.Currency = pflast.Currency;
            //    pf.LunoBid = pflast.LunoBid;
            //    pf.ExchangeAsk = pflast.ExchangeAsk;
            //    pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate;
            //    pf.ProfitPerc = pflast.ProfitPerc;
            //    pf.ArbSymblol = "BTC";
            //    pf.Save();
            //}

            //// Bitlish EUR;
            //try
            //{
            //    profPerc = GetProfit(bitlishEUR.ask.price, luno.bid.price, eurzar, 0.4M, 4.35M, 4000);
            //    pf = new ProfitRecording();
            //    pf.Exchange = enExchange.Bitlish;
            //    pf.Currency = enCurrency.EUR;
            //    pf.LunoBid = luno.bid.price;
            //    pf.ExchangeAsk = bitlishEUR.ask.price;
            //    pf.CurrencyToZARExchangeRate = eurzar;
            //    pf.ProfitPerc = profPerc;
            //    pf.ArbSymblol = "BTC";
            //    pf.Save();
            //}
            //catch
            //{// duplicate last recording
            //    ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitlish, enCurrency.EUR, "BTC");
            //    pf = new ProfitRecording();
            //    pf.Exchange = pflast.Exchange;
            //    pf.Currency = pflast.Currency;
            //    pf.LunoBid = pflast.LunoBid;
            //    pf.ExchangeAsk = pflast.ExchangeAsk;
            //    pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate;
            //    pf.ProfitPerc = pflast.ProfitPerc;
            //    pf.ArbSymblol = "BTC";
            //    pf.Save();
            //}


            // CEX USD;
            try
            {
                profPerc       = GetProfit(cexUSD.ask.price, luno.bid.price, usdzar, 0.4M, 2.99M, 3000);
                pf             = new ProfitRecording();
                pf.Exchange    = enExchange.Cex;
                pf.Currency    = enCurrency.USD;
                pf.LunoBid     = luno.bid.price;
                pf.ExchangeAsk = cexUSD.ask.price;
                pf.CurrencyToZARExchangeRate = usdzar;
                pf.ProfitPerc = profPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }
            catch
            {// duplicate last recording
                ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.USD, "BTC");
                pf             = new ProfitRecording();
                pf.Exchange    = pflast.Exchange;
                pf.Currency    = pflast.Currency;
                pf.LunoBid     = pflast.LunoBid;
                pf.ExchangeAsk = pflast.ExchangeAsk;
                pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate;
                pf.ProfitPerc = pflast.ProfitPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }

            // CEX EUR;
            try
            {
                profPerc       = GetProfit(cexEUR.ask.price, luno.bid.price, eurzar, 0.4M, 2.99M, 3000);
                pf             = new ProfitRecording();
                pf.Exchange    = enExchange.Cex;
                pf.Currency    = enCurrency.EUR;
                pf.LunoBid     = luno.bid.price;
                pf.ExchangeAsk = cexEUR.ask.price;
                pf.CurrencyToZARExchangeRate = eurzar;
                pf.ProfitPerc = profPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }
            catch
            {// duplicate last recording
                ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.EUR, "BTC");
                pf             = new ProfitRecording();
                pf.Exchange    = pflast.Exchange;
                pf.Currency    = pflast.Currency;
                pf.LunoBid     = pflast.LunoBid;
                pf.ExchangeAsk = pflast.ExchangeAsk;
                pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate;
                pf.ProfitPerc = pflast.ProfitPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }

            // CEX GBP;
            try
            {
                profPerc       = GetProfit(cexGBP.ask.price, luno.bid.price, gbpzar, 0.4M, 2.99M, 2000);
                pf             = new ProfitRecording();
                pf.Exchange    = enExchange.Cex;
                pf.Currency    = enCurrency.GBP;
                pf.LunoBid     = luno.bid.price;
                pf.ExchangeAsk = cexGBP.ask.price;
                pf.CurrencyToZARExchangeRate = gbpzar;
                pf.ProfitPerc = profPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }
            catch { // duplicate last recording
                ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Cex, enCurrency.GBP, "BTC");
                pf             = new ProfitRecording();
                pf.Exchange    = pflast.Exchange;
                pf.Currency    = pflast.Currency;
                pf.LunoBid     = pflast.LunoBid;
                pf.ExchangeAsk = pflast.ExchangeAsk;
                pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate;
                pf.ProfitPerc = pflast.ProfitPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }

            // Bitfinex USD;
            try
            {
                profPerc       = GetProfit(bitfinexUSD.ask.price, luno.bid.price, usdzar, 0.4M, 3.5M, 2000);
                pf             = new ProfitRecording();
                pf.Exchange    = enExchange.Bitfinex;
                pf.Currency    = enCurrency.USD;
                pf.LunoBid     = luno.bid.price;
                pf.ExchangeAsk = bitfinexUSD.ask.price;
                pf.CurrencyToZARExchangeRate = usdzar;
                pf.ProfitPerc = profPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }
            catch
            { // duplicate last recording
                ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitfinex, enCurrency.USD, "BTC");
                pf             = new ProfitRecording();
                pf.Exchange    = pflast.Exchange;
                pf.Currency    = pflast.Currency;
                pf.LunoBid     = pflast.LunoBid;
                pf.ExchangeAsk = pflast.ExchangeAsk;
                pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate;
                pf.ProfitPerc = pflast.ProfitPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }


            // BitStamp USD;
            try
            {
                profPerc       = GetProfit(bitstampUSD.ask.price, luno.bid.price, usdzar, 0.4M, 5.25M, 2000);
                pf             = new ProfitRecording();
                pf.Exchange    = enExchange.Bitstamp;
                pf.Currency    = enCurrency.USD;
                pf.LunoBid     = luno.bid.price;
                pf.ExchangeAsk = bitstampUSD.ask.price;
                pf.CurrencyToZARExchangeRate = usdzar;
                pf.ProfitPerc = profPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }
            catch
            { // duplicate last recording
                ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitstamp, enCurrency.USD, "BTC");
                pf             = new ProfitRecording();
                pf.Exchange    = pflast.Exchange;
                pf.Currency    = pflast.Currency;
                pf.LunoBid     = pflast.LunoBid;
                pf.ExchangeAsk = pflast.ExchangeAsk;
                pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate;
                pf.ProfitPerc = pflast.ProfitPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }

            // BitStamp EUR;
            try
            {
                profPerc       = GetProfit(bitstampEUR.ask.price, luno.bid.price, eurzar, 0.4M, 5.25M, 2000);
                pf             = new ProfitRecording();
                pf.Exchange    = enExchange.Bitstamp;
                pf.Currency    = enCurrency.EUR;
                pf.LunoBid     = luno.bid.price;
                pf.ExchangeAsk = bitstampEUR.ask.price;
                pf.CurrencyToZARExchangeRate = eurzar;
                pf.ProfitPerc = profPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }
            catch
            { // duplicate last recording
                ProfitRecording pflast = ProfitRecording.GetLatestByExchangeAndCurrnecy(enExchange.Bitstamp, enCurrency.EUR, "BTC");
                pf             = new ProfitRecording();
                pf.Exchange    = pflast.Exchange;
                pf.Currency    = pflast.Currency;
                pf.LunoBid     = pflast.LunoBid;
                pf.ExchangeAsk = pflast.ExchangeAsk;
                pf.CurrencyToZARExchangeRate = pflast.CurrencyToZARExchangeRate;
                pf.ProfitPerc = pflast.ProfitPerc;
                pf.ArbSymblol = "BTC";
                pf.Save();
            }
        }