コード例 #1
0
        public string AddLimitOrder(
            long nonce,
            decimal fee,
            string tradingPair,
            string side,
            decimal price,
            decimal amount,
            int expiryBlocks,
            string owner)
        {
            TradeServices tradeServices = new TradeServices();
            DataServices  dataServices  = new DataServices();

            tradeServices.ValidateOrder(tradingPair, side, owner, amount, price);

            TransactionOrderLimit order = new TransactionOrderLimit();

            order.Nonce            = nonce;
            order.TradingPair      = tradingPair;
            order.Side             = side;
            order.Price            = price;
            order.Amount           = amount;
            order.ExpiryBlockIndex = dataServices.LastBlock.Header.Index + expiryBlocks;
            order.Owner            = owner;
            order.TransactionId    = GenerateTransactionId(order);

            //Check if same transaction has already been received
            if (IsTransactionInPending(order.TransactionId))
            {
                return(order.TransactionId);
            }

            //Verify fee account balance
            if (!HasSufficientBalanceFee(owner, fee))
            {
                throw new ValidationException(ResponseCodes.InsufficientFundsForFee, ResponseMessages.InsufficientFundsForFee);
            }

            ApplicationState.PendingRecordsAdd(order);

            return(order.TransactionId);
        }
コード例 #2
0
        public List <string> AddMarketOrder(
            long nonce,
            decimal fee,
            string tradingPair,
            string side,
            decimal amount,
            string owner)
        {
            //Verify fee account balance
            if (!HasSufficientBalanceFee(owner, fee))
            {
                throw new ValidationException(ResponseCodes.InsufficientFundsForFee, ResponseMessages.InsufficientFundsForFee);
            }

            TradeServices tradeServices = new TradeServices();

            var marketLookupSide = side == TradeSides.Buy ? TradeSides.Sell : TradeSides.Buy;
            var marketPrice      = tradeServices.GetMarketPrice(tradingPair, marketLookupSide);

            if (marketPrice == null)
            {
                throw new ValidationException(ResponseCodes.NotEnoughOrdersAvailable, ResponseMessages.NotEnoughOrdersAvailable);
            }

            tradeServices.ValidateOrder(tradingPair, side, owner, amount, marketPrice.Value);

            //Generate transaction Id
            TransactionOrderMarket order = new TransactionOrderMarket();

            order.Nonce         = nonce;
            order.TradingPair   = tradingPair;
            order.Side          = side;
            order.Amount        = amount;
            order.Owner         = owner;
            order.TransactionId = GenerateTransactionId(order);

            //Make the trade
            var transactionIds = tradeServices.MakeTrade(order.TransactionId, tradingPair, side, amount, owner);

            return(transactionIds);
        }