/// Handler削除(追加時に得たCancelKeyを使う) public void Remove(CancelKey key) { if (_executeLock) { throw new Exception("実行最中の削除はできません"); } GearDispatcherHandler <TFunc> rmhandler = null; var enumerator = _list.GetEnumerator(); while (enumerator.MoveNext()) { GearDispatcherHandler <TFunc> handler = enumerator.Current; if ((CancelKey)handler == key) { rmhandler = handler; break; } } if (rmhandler != null) { _list.Remove(rmhandler); } }
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)); }
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 void Remove(CancelKey key) { GenericGearDispatcher.Remove(key); }