Exemplo n.º 1
0
        // Returns merge amount
        public MergeResultData MergeWith(OpenTrade secondTrade)
        {
            MergeResultData mergeResultData;

            if (Amount > secondTrade.Amount)
            {
                var amountResidue = Amount - secondTrade.Amount;
                var mergeFee      = Fee * (secondTrade.Amount / Amount);
                var feeResidue    = Fee - mergeFee;

                mergeResultData = new MergeResultData(secondTrade.Amount, mergeFee + secondTrade.Fee);

                SetResidue(amountResidue, feeResidue);
                secondTrade.SetResidue(decimal.Zero, decimal.Zero);
            }

            else
            {
                var secondTradeAmountResidue = secondTrade.Amount - Amount;
                var secondTradeMergeFee      = secondTrade.Fee * (Amount / secondTrade.Amount);
                var secondTradeFeeResidue    = secondTrade.Fee - secondTradeMergeFee;

                mergeResultData = new MergeResultData(Amount, secondTradeMergeFee + Fee);

                secondTrade.SetResidue(secondTradeAmountResidue, secondTradeFeeResidue);
                SetResidue(decimal.Zero, decimal.Zero);
            }

            return(mergeResultData);
        }
Exemplo n.º 2
0
        public static ClosedTrade Create(OpenTrade firstTrade, OpenTrade secondTrade, MergeResultData mergeResult, decimal traderFee)
        {
            OpenTrade buyTrade  = default;
            OpenTrade sellTrade = default;

            switch (firstTrade.Side)
            {
            case TradeSide.Buy:
                buyTrade  = firstTrade;
                sellTrade = secondTrade;
                break;

            case TradeSide.Sell:
                buyTrade  = secondTrade;
                sellTrade = firstTrade;
                break;
            }

            return(new ClosedTrade
                   (
                       accountId: sellTrade.AccountId,
                       datetime: sellTrade.Datetime,
                       firstCurrency: sellTrade.FirstCurrency,
                       secondCurrency: sellTrade.SecondCurrency,
                       openPrice: buyTrade.Price,
                       closePrice: sellTrade.Price,
                       amount: mergeResult.Amount,
                       roundFee: mergeResult.ExchangeFee,
                       exchangeFeeCurrency: Currency.USD,
                       traderFee: traderFee
                   ));
        }
Exemplo n.º 3
0
        public MergeResultData GetPotentialMergeData(OpenTrade secondTrade)
        {
            MergeResultData mergeResultData;

            if (Amount > secondTrade.Amount)
            {
                var mergeFee = Fee * (secondTrade.Amount / Amount) + secondTrade.Fee;
                mergeResultData = new MergeResultData(secondTrade.Amount, mergeFee);
            }

            else
            {
                var mergeFee = secondTrade.Fee * (Amount / secondTrade.Amount) + Fee;
                mergeResultData = new MergeResultData(Amount, mergeFee);
            }

            return(mergeResultData);
        }