Пример #1
0
        async Task RefreshArb()
        {
            IList <IList <object> > results = await sheet.Read(arbAlarmTab, "B:K");

            List <string[]> dataToWrite = new List <string[]>(results.Count);

            TradingPair bestBtcUsdAsk = Coin.bitcoin.Best(Coin.usd, false);
            TradingPair bestBtcUsdBid = Coin.bitcoin.Best(Coin.usd, true);
            TradingPair bestEthUsdAsk = Coin.ethereum.Best(Coin.usd, false);
            TradingPair bestEthUsdBid = Coin.ethereum.Best(Coin.usd, true);

            for (int iRow = 0; iRow < results.Count; iRow++)
            {
                dataToWrite.Add(new string[2]
                {
                    "", ""
                });

                IList <object> row = results[iRow];
                if (row[9]?.ToString() == "TRUE")
                {
                    string       coinName        = row[0].ToString();
                    Coin         quoteCoin       = Coin.FromName(coinName);
                    string       bidExchangeName = row[2].ToString();
                    ExchangeName bidExchange     = (ExchangeName)Enum.Parse(typeof(ExchangeName),
                                                                            bidExchangeName);
                    string bidCurrencyName = row[3].ToString();
                    Coin   bidBaseCoin     = Coin.FromName(bidCurrencyName);

                    string       askExchangeName = row[5].ToString();
                    ExchangeName askExchange     = (ExchangeName)Enum.Parse(typeof(ExchangeName),
                                                                            askExchangeName);
                    string askCurrencyName = row[6].ToString();
                    Coin   askBaseCoin     = Coin.FromName(askCurrencyName);

                    decimal purchasePriceInBase;
                    if (askBaseCoin == Coin.ethereum)
                    {
                        purchasePriceInBase = arbPurchasePriceETH;
                    }
                    else
                    {
                        purchasePriceInBase = arbPurchasePriceBTC;
                    }

                    (decimal purchaseAmount, decimal quantity) = await quoteCoin.CalcPurchasePrice(
                        askExchange, askBaseCoin,
                        purchasePriceInBase : purchasePriceInBase);

                    if (askBaseCoin == Coin.bitcoin)
                    {
                        purchaseAmount *= bestBtcUsdAsk.askPrice;
                    }
                    else
                    {
                        purchaseAmount *= bestEthUsdAsk.askPrice;
                    }

                    decimal sellAmount = await quoteCoin.CalcSellPrice(
                        bidExchange, bidBaseCoin,
                        quantityOfCoin : quantity * 2);

                    sellAmount /= 2;
                    if (bidBaseCoin == Coin.bitcoin)
                    {
                        sellAmount *= bestBtcUsdBid.bidPrice;
                    }
                    else
                    {
                        sellAmount *= bestEthUsdBid.bidPrice;
                    }

                    dataToWrite[iRow][0] = purchaseAmount.ToString();
                    dataToWrite[iRow][1] = sellAmount.ToString();
                }
            }


            await sheet.Write(arbAlarmTab, "L:M", dataToWrite);
        }