public static ArbitrageData FromSimpleArbitrageOpened(ArbitrageBuyOrder buyOrder, ArbitrageSellOrder sellOrder)
        {
            if (buyOrder == null)
            {
                throw new ArgumentNullException(nameof(buyOrder));
            }
            if (sellOrder == null)
            {
                throw new ArgumentNullException(nameof(sellOrder));
            }

            var baseCurrency =
                buyOrder.BaseCurrency == sellOrder.BaseCurrency ?
                buyOrder.BaseCurrency : throw new InvalidOperationException("The base currency between buy order and sell order must be the same currency.");
            var quoteCurrency =
                buyOrder.QuoteCurrency == sellOrder.QuoteCurrency ?
                buyOrder.QuoteCurrency : throw new InvalidOperationException("The quote currency between buy order and sell order must be the same currency.");

            //Defaults to zero.
            decimal originalBaseCurrencyQty  = 0;
            decimal originalQuoteCurrencyQty = 0;

            originalQuoteCurrencyQty += buyOrder.Price * buyOrder.Quantity;
            originalBaseCurrencyQty  += sellOrder.Quantity;

            return(new ArbitrageData(baseCurrency, quoteCurrency, originalBaseCurrencyQty, originalQuoteCurrencyQty));
        }
Beispiel #2
0
        public static SimpleArbitrage CreateFrom(
            decimal estimatedProfits, string baseCurrency, string quoteCurrency,
            int buyFrom, decimal buyPrice, decimal buyAmounts,
            int sellTo, decimal sellPrice, decimal sellAmounts,
            StopLossSetting buyStopLossSetting, StopLossSetting sellStopLossSetting)
        {
            var arbitrageId = Guid.NewGuid().ToString();

            //無條件捨去至 N 位
            //It seems Binance only support max to 6.
            int     roundedNumber      = 6;
            decimal pow                = (decimal)Math.Pow(10, roundedNumber);
            decimal roundedBuyAmounts  = Math.Floor(buyAmounts * (pow)) / pow;
            decimal roundedSellAmounts = Math.Floor(sellAmounts * (pow)) / pow;

            var buySlipPrice = buyStopLossSetting.GetSlipPrice(buyPrice, baseCurrency, quoteCurrency);
            var buyOrder     = new ArbitrageBuyOrder(
                Guid.NewGuid().ToString(),
                buyFrom,
                baseCurrency,
                quoteCurrency,
                buyPrice,
                roundedBuyAmounts,
                buySlipPrice
                );

            var sellSlipPrice = sellStopLossSetting.GetSlipPrice(sellPrice, baseCurrency, quoteCurrency);
            var sellOrder     = new ArbitrageSellOrder(
                Guid.NewGuid().ToString(),
                sellTo,
                baseCurrency,
                quoteCurrency,
                sellPrice,
                roundedSellAmounts,
                sellSlipPrice
                );

            var arbitrageData = ArbitrageData.FromSimpleArbitrageOpened(buyOrder, sellOrder);

            return(new SimpleArbitrage(
                       arbitrageId,
                       buyOrder,
                       sellOrder,
                       estimatedProfits,
                       arbitrageData,
                       SimpleArbitrageStatus.Opened
                       ));
        }
Beispiel #3
0
        private SimpleArbitrage(string arbitrageId, ArbitrageBuyOrder buyOrder, ArbitrageSellOrder sellOrder, decimal estimatedProfits, ArbitrageData arbitrageData, SimpleArbitrageStatus status) : this()
        {
            this.ArbitrageId     = arbitrageId ?? throw new ArgumentNullException(nameof(arbitrageId));
            this.BuyOrder        = buyOrder ?? throw new ArgumentNullException(nameof(buyOrder));
            this.SellOrder       = sellOrder ?? throw new ArgumentNullException(nameof(sellOrder));
            this.EstimateProfits = estimatedProfits;
            this.ArbitrageData   = arbitrageData ?? throw new ArgumentNullException(nameof(arbitrageData));
            //this.Status = status ?? throw new ArgumentNullException(nameof(status));
            this._simpleArbitrageStatusId = status != null ? status.Id : throw new ArgumentNullException(nameof(status));
            this.ActualProfits            = 0;
            this.IsSuccess     = false;
            this.FailureReason = String.Empty;

            this.AddDomainEvent(
                new SimpleArbitrageOpenedDomainEvent(this));
        }