Example #1
0
        private async Task AnalizeBuy()
        {
            foreach (var stock in Settings.Stocks)
            {
                var data      = MarketData.GetData()[stock];
                var lastIndex = data.Count - 1;

                if (lastIndex < 2)
                {
                    return;
                }

                var p0 = Convert.ToDouble(data[lastIndex - 0].Price());
                var p1 = Convert.ToDouble(data[lastIndex - 1].Price());
                var p2 = Convert.ToDouble(data[lastIndex - 2].Price());

                var buyVolume = 5;

                if (p0 > p1 && p1 > p2 && p0 - p1 > p1 - p2 && AlpacaData.GetPositionCount(stock) == 0 &&
                    AlpacaData.GetAccountData().Equity() - p0 * buyVolume >= 0)
                {
                    await Buy(stock, p0, buyVolume);
                }

                //if ((p0 < p1 || p0 - p1 < p1 - p2) && AlpacaData.GetPositionCount(stock) > 0)
                //    await Sell(stock, p2);
            }
        }
Example #2
0
 private async void UpdateMarketData(object sender, EventArgs e)
 {
     _marketDataUpdater.Stop();
     //await MarketData.Update();
     MarketData.UpdateFake();
     _marketDataUpdater.Start();
     //await AnalizeBuy();
     Plot.Update(ref MarketData.GetData());
     Legend.Update(ref MarketData.GetData(), AlpacaData.GetAccountData(), AlpacaData.GetPositionns());
 }
Example #3
0
        private async void UpdateAlpacaData(object sender, EventArgs e)
        {
            _accountDataUpdater.Stop();
            await AlpacaData.Update();

            _accountDataUpdater.Start();
            await AnalizeSell();

            UpdatePositions();
            Legend.Update(ref MarketData.GetData(), AlpacaData.GetAccountData(), AlpacaData.GetPositionns());
        }
Example #4
0
        private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var tb = (TextBlock)sender;

            foreach (var price in _stockTextBlocks)
            {
                if (!price.Value.Equals(tb))
                {
                    continue;
                }
                Settings.SelectedStock = price.Key;
                break;
            }
            SelectedStockChenged.Invoke(sender, new EventArgs());
            Update(ref MarketData.GetData(), AlpacaData.GetAccountData(), AlpacaData.GetPositionns());
        }
Example #5
0
 private void SelectedStockChenged(object sender, EventArgs e)
 {
     Plot.Update(ref MarketData.GetData());
 }
Example #6
0
 private void PlotCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     Update(ref MarketData.GetData());
 }
Example #7
0
 private void LegendCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     Update(ref MarketData.GetData(), AlpacaData.GetAccountData(), AlpacaData.GetPositionns());
 }