Exemplo n.º 1
0
        private async Task UpdateCurrencyCycles()
        {
            IExchange exchange = this.exchange;

            if (!exchange.Connected)
            {
                await exchange.ConnectReadOnly();
            }

            this.tickers = await exchange.GetTicker();

            Matrix <ArbitragePath> arbitrage1 = Matrix <Ticker> .FromArray(NullRing <Ticker> .Instance, this.tickers)
                                                .Map(new ArbitragePathSemiring(false), (y, x, value) =>
            {
                decimal multiplier = 0;
                if (value.LowestAskPrice != 0)
                {
                    multiplier = 1m / value.LowestAskPrice * (1m - exchange.FeePercentage * 0.01m);
                }

                if (x == y)
                {
                    return(new ArbitragePath(multiplier, new List <string> {
                        exchange.Currencies[(int)x]
                    }));
                }
                else
                {
                    return(new ArbitragePath(multiplier, new List <string> {
                        exchange.Currencies[(int)x], exchange.Currencies[(int)y]
                    }));
                }
            });

            Matrix <ArbitragePath> arbitrage  = arbitrage1;
            Matrix <ArbitragePath> arbitrageN = arbitrage1;

            for (int tradeCount = 1; tradeCount < this.maximumTradeCount; tradeCount++)
            {
                arbitrageN = arbitrage1 * arbitrageN;
                arbitrage  = arbitrage + arbitrageN;
            }

            await this.Dispatcher.InvokeAsync(() =>
            {
                if (this.CurrencyCyclesListView.Items.Count != exchange.Currencies.Count)
                {
                    this.CurrencyCyclesListView.Items.Clear();
                    for (int i = 0; i < exchange.Currencies.Count; i++)
                    {
                        this.CurrencyCyclesListView.Items.Add(new CurrencyCycleListViewItem {
                            Name = exchange.Currencies[i], Exchange = exchange, ArbitragePath = new ArbitragePath(0, new List <string>())
                        });
                    }
                }

                this.suppressExecutionUpdate = true;
                int selectedIndex            = this.CurrencyCyclesListView.SelectedIndex;
                for (int i = 0; i < exchange.Currencies.Count; i++)
                {
                    ArbitragePath arbitragePath          = arbitrage[(uint)i, (uint)i];
                    this.CurrencyCyclesListView.Items[i] = new CurrencyCycleListViewItem {
                        Name = exchange.Currencies[i], Exchange = exchange, ArbitragePath = arbitragePath
                    };
                }
                this.CurrencyCyclesListView.SelectedIndex = selectedIndex;
                this.suppressExecutionUpdate = false;
            });

            this.executionCycle = (CurrencyCycleListViewItem?)this.CurrencyCyclesListView.SelectedItem;
            await this.UpdateExecution();
        }