예제 #1
0
파일: ACT.cs 프로젝트: Twistt/CoinTrader
        private async void Form1_Load(object sender, EventArgs e)
        {
            Exchange = new BinanceWrapper();


            //Get a list of all coins (and whether we have any)
            await Exchange.GetBalances();

            var usdt = Coin.AllCoins.Where(c => c.Currency == "USDT").FirstOrDefault();
            var btc  = Coin.AllCoins.Where(c => c.Currency == "BTC").FirstOrDefault();

            //Get a list of all the stuff we ahve bought and sold (to establish profit and baseline)
            //await Exchange.GetOrderHistory();
            foreach (var coin in Coin.AllCoins.Where(c => c.Balance > 0))
            {
                var mostrecentorder = Order.AllOrders.Where(o => o.Exchange == "BTC-" + coin.Currency).OrderByDescending(o => o.TimeStamp).FirstOrDefault();
                if (mostrecentorder != null)
                {
                    coin.LastPurchasePrice = mostrecentorder.PricePerUnit;
                }
                var candlestick = await Exchange.GetCandleSticks(market, TimeInterval.Minutes_15);

                c.Candles.AddRange(candlestick);
                try
                {
                    flowLayoutPanel1.Controls.Add(CreateCurrencyGroup(coin));
                }
                catch (Exception) { }
            }
            //FillOrders();
            //FillAlerts();
            timerTicker.Tick += UpdateCurrencyTickers;
            timerTicker.Start();
            timerUpdateCurrencies.Tick += TimerUpdateCurrencies_Tick;
            timerUpdateCurrencies.Start();

            //This handles new currencies (trading on the exchange and not through this interface)
            if (Coin.AllCoins.Count > 0)
            {
                BTCValue = Coin.AllCoins.Where(c => c.Currency == "BTC").First().ValueInUSD;
            }
            this.Text = "CryptoDayTrader BTC:" + BTCValue;

            lblTotalPortfolioValueUSD.Text = "Total Value in USD: $" + Math.Round(Coin.AllCoins.Sum(c => (c.LastPurchasePrice * c.Balance) * BTCValue), 4).ToString();
            lblTotalPortfolioValueBTC.Text = "Total Value in BTC: " + Coin.AllCoins.Sum(c => (c.LastPurchasePrice * c.Balance)).ToString();
            Task.Factory.StartNew(() => {
                //This adds ADDITIONAL information to currencies - so we dont need it right away.
                Exchange.GetCurrencies();
            });
        }