Ejemplo n.º 1
0
        private void BuyAsset(IIndexedOhlcv indexedCandle, decimal premium, IDictionary <IEnumerable <IOhlcv>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.BackingList, out decimal availableQuoteCurrency))
            {
                var     nextIOhlcvData  = indexedCandle.Next;
                decimal baseCurrencyQte = (availableQuoteCurrency - premium) / nextIOhlcvData.Open;

                if (_buyCompleteBaseCurrencies)
                {
                    baseCurrencyQte = Math.Floor(baseCurrencyQte);
                }

                decimal quoteCurrencyQte = nextIOhlcvData.Open * baseCurrencyQte + premium;

                // EUR/USD (1€ = 1000$) ; flat exchange fee ratio percent = 0.1
                // you buy 2000$
                // Total 2€, fee = 2 * 0.001 = 0.002, net = 2 - 0.002 = 1.998 €
                baseCurrencyQte -= _flatExchangeFee * baseCurrencyQte;
                var quoteCurrencyFee = _flatExchangeFee * nextIOhlcvData.Open;

                assetCashMap[indexedCandle.BackingList] -= quoteCurrencyQte;

                transactions.Add(new Transaction(indexedCandle.BackingList, nextIOhlcvData.Index, nextIOhlcvData.DateTime, TransactionType.Buy, baseCurrencyQte, quoteCurrencyQte));
                OnBought?.Invoke(indexedCandle.BackingList, nextIOhlcvData.Index, nextIOhlcvData.DateTime, nextIOhlcvData.Open, baseCurrencyQte, quoteCurrencyQte, assetCashMap[indexedCandle.BackingList]);
            }
        }
Ejemplo n.º 2
0
        private void BuyAsset(IIndexedOhlcv indexedCandle, decimal premium, IDictionary <IEnumerable <IOhlcv>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.BackingList, out decimal cash))
            {
                var     nextCandle = indexedCandle.Next;
                decimal quantity   = (cash - premium) / nextCandle.Open;

                if (_buyInCompleteQuantity)
                {
                    quantity = Math.Floor(quantity);
                }

                decimal cashToBuyAsset = nextCandle.Open * quantity + premium;

                // EUR/USD (1€ = 1000$) ; flat exchange fee ratio percent = 0.1
                // you buy 2000$
                // Total 2€, fee = 2 * 0.001 = 0.002, net = 2 - 0.002 = 1.998 €
                quantity -= _flatExchangeFee * quantity;
                //var quoteCurrencyFee = _flatExchangeFee * nextCandle.Open;

                assetCashMap[indexedCandle.BackingList] -= cashToBuyAsset;

                transactions.Add(new Transaction(indexedCandle.BackingList, nextCandle.Index, nextCandle.DateTime, TransactionType.Buy, quantity, cashToBuyAsset));
                OnBought?.Invoke(indexedCandle.BackingList, nextCandle.Index, nextCandle.DateTime, nextCandle.Open, quantity, cashToBuyAsset, assetCashMap[indexedCandle.BackingList]);
            }
        }
Ejemplo n.º 3
0
    public override bool Buy(Cell cell, IShop shop)
    {
        if (PlayerAttributes.RemoveMoney(cell.Properties.Cost) && (BoostDatabase.Boosts.Count < BoostsHandler.MaxBoosts))
        {
            OnBought?.Invoke(this);
            return(true);
        }

        //TODO: message
        return(false);
    }
Ejemplo n.º 4
0
        private void BuyAsset(IndexedCandle indexedCandle, decimal premium, IDictionary <IList <Candle>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.Candles, out decimal cash))
            {
                var nextCandle = indexedCandle.Next;
                int quantity   = Convert.ToInt32(Math.Floor((cash - premium) / nextCandle.Open));

                decimal cashOut = nextCandle.Open * quantity + premium;
                assetCashMap[indexedCandle.Candles] -= cashOut;

                transactions.Add(new Transaction(indexedCandle.Candles, nextCandle.Index, nextCandle.DateTime, TransactionType.Buy, quantity, cashOut));
                OnBought?.Invoke(indexedCandle.Candles, nextCandle.Index, nextCandle.DateTime, nextCandle.Open, quantity, cashOut, assetCashMap[indexedCandle.Candles]);
            }
        }
Ejemplo n.º 5
0
        private void BuyAsset(IIndexedOhlcv indexedCandle, decimal premium, IDictionary <IEnumerable <IOhlcv>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.BackingList, out decimal cash))
            {
                var nextIOhlcvData = indexedCandle.Next;
                int quantity       = Convert.ToInt32(Math.Floor((cash - premium) / nextIOhlcvData.Open));

                decimal cashOut = nextIOhlcvData.Open * quantity + premium;
                assetCashMap[indexedCandle.BackingList] -= cashOut;

                transactions.Add(new Transaction(indexedCandle.BackingList, nextIOhlcvData.Index, nextIOhlcvData.DateTime, TransactionType.Buy, quantity, cashOut));
                OnBought?.Invoke(indexedCandle.BackingList, nextIOhlcvData.Index, nextIOhlcvData.DateTime, nextIOhlcvData.Open, quantity, cashOut, assetCashMap[indexedCandle.BackingList]);
            }
        }
Ejemplo n.º 6
0
        private void BuyAsset(IIndexedOhlcv indexedCandle, IFeeCalculator calculator, IDictionary <IEnumerable <IOhlcv>, decimal> assetCashMap, IList <Transaction> transactions)
        {
            if (assetCashMap.TryGetValue(indexedCandle.BackingList, out decimal cash))
            {
                var nextCandle = indexedCandle.Next;

                //Use calculator to determine transaction quantities, costs, etc.
                var transaction = calculator.BuyAsset(nextCandle, cash, nextCandle, _buyInCompleteQuantity);

                assetCashMap[nextCandle.BackingList] -= transaction.AbsoluteCashFlow; //cash to buy asset

                transactions.Add(transaction);
                OnBought?.Invoke(indexedCandle.BackingList, nextCandle.Index, nextCandle.DateTime, nextCandle.Open, transaction.Quantity, transaction.AbsoluteCashFlow, assetCashMap[indexedCandle.BackingList]);
            }
        }