Exemple #1
0
        public async Task <CancelKey> SubmitExchangeOrder(string AccountId, TokenTradeOrder order)
        {
            CheckSyncState();
            var acct = await _dex.GetExchangeAccount(AccountId);

            return(await _dex.AddOrderAsync(acct, order));
        }
Exemple #2
0
        async Task <CancelKey> INodeAPI.SubmitExchangeOrder(TokenTradeOrder order)
        {
            var request = new SubmitExchangeOrderRequest()
            {
                TokenTradeOrderJson = Json(order)
            };
            var result = await SubmitExchangeOrderAsync(request);

            return(FromJson <CancelKey>(result.CancelKeyJson));
        }
        public async Task <CancelKey> SubmitExchangeOrder(TokenTradeOrder reqOrder)
        {
            CancelKey key;
            var       result = reqOrder.VerifySignature(reqOrder.AccountID);

            if (!result ||
                reqOrder.TokenName == null ||
                reqOrder.Price <= 0 ||
                reqOrder.Amount <= 0)
            {
                key = new CancelKey()
                {
                    Key = string.Empty, State = OrderState.BadOrder
                };
                return(key);
            }

            // verify the balance.
            var acct = await NodeService.Dealer.GetExchangeAccount(reqOrder.AccountID, true);

            if (acct == null)
            {
                return(new CancelKey()
                {
                    Key = string.Empty, State = OrderState.BadOrder
                });
            }

            if (reqOrder.BuySellType == OrderType.Sell)
            {
                if (acct.Balance.ContainsKey(reqOrder.TokenName) && acct.Balance[reqOrder.TokenName] < reqOrder.Amount)
                {
                    return new CancelKey()
                           {
                               Key = string.Empty, State = OrderState.InsufficientFunds
                           }
                }
                ;
            }
            else
            {
                // buy order
                if (acct.Balance.ContainsKey(LyraGlobal.LYRATICKERCODE) && acct.Balance[LyraGlobal.LYRATICKERCODE] < reqOrder.Amount * reqOrder.Price)
                {
                    return new CancelKey()
                           {
                               Key = string.Empty, State = OrderState.InsufficientFunds
                           }
                }
                ;
            }

            return(await NodeService.Dealer.AddOrderAsync(acct, reqOrder));
        }
Exemple #4
0
        public async Task <CancelKey> AddOrderAsync(ExchangeAccount acct, TokenTradeOrder order)
        {
            order.CreatedTime = DateTime.Now;
            var item = new ExchangeOrder()
            {
                ExchangeAccountId = acct.Id,
                Order             = order,
                CanDeal           = true,
                State             = DealState.Placed,
                ClientIP          = null
            };
            await _queue.InsertOneAsync(item);

            OnNewOrder?.Invoke(this, new EventArgs());

            var key = new CancelKey()
            {
                State = OrderState.Placed,
                Key   = item.Id.ToString(),
                Order = order
            };

            return(key);
        }
 public async Task <CancelKey> SubmitExchangeOrder(TokenTradeOrder order)
 {
     return(await PostBlock <CancelKey>("SubmitExchangeOrder", order));
 }