示例#1
0
 public void Update(TransaqOrder to)
 {
   if (to.TransactionId != -1L)
     this.TransactionId = to.TransactionId;
   if (to.OrderNo != -1L)
     this.OrderNo = to.OrderNo;
   if (to.Status != string.Empty)
     this.Status = to.Status;
   if (to.Balance != -1.0)
     this.Balance = to.Balance;
   if (to.Price != -1.0)
     this.Price = to.Price;
   if (to.Quantity != -1)
     this.Quantity = to.Quantity;
   if (to.WithdrawTime != string.Empty)
     this.WithdrawTime = to.WithdrawTime;
   if (!(to.Result != string.Empty))
     return;
   this.Result = to.Result;
 }
示例#2
0
 public void Update(TransaqOrder to)
 {
     if (to.TransactionId != -1L)
     {
         this.TransactionId = to.TransactionId;
     }
     if (to.OrderNo != -1L)
     {
         this.OrderNo = to.OrderNo;
     }
     if (to.Status != string.Empty)
     {
         this.Status = to.Status;
     }
     if (to.Balance != -1.0)
     {
         this.Balance = to.Balance;
     }
     if (to.Price != -1.0)
     {
         this.Price = to.Price;
     }
     if (to.Quantity != -1)
     {
         this.Quantity = to.Quantity;
     }
     if (to.WithdrawTime != string.Empty)
     {
         this.WithdrawTime = to.WithdrawTime;
     }
     if (!(to.Result != string.Empty))
     {
         return;
     }
     this.Result = to.Result;
 }
示例#3
0
文件: Transaq.cs 项目: smther/FreeOQ
 private void UpdateOrder(string data)
 {
   if (!this.isConnected)
     return;
   TransaqOrder to = new TransaqOrder(data);
   TransaqOrder transaqOrder = (TransaqOrder) null;
   Order order = (Order) null;
   try
   {
     this.rwTransaqOrderByTrId.EnterUpgradeableReadLock();
     if (!this.transaqOrderByTrId.TryGetValue(to.TransactionId, out transaqOrder))
     {
       this.rwTransaqOrderByTrId.EnterWriteLock();
       this.transaqOrderByTrId.Add(to.TransactionId, to);
     }
     else
     {
       transaqOrder.Update(to);
       to = transaqOrder;
       this.rwTransaqOrderByTrId.EnterWriteLock();
       this.transaqOrderByTrId[to.TransactionId] = to;
     }
   }
   finally
   {
     if (this.rwTransaqOrderByTrId.IsWriteLockHeld)
       this.rwTransaqOrderByTrId.ExitWriteLock();
     this.rwTransaqOrderByTrId.ExitUpgradeableReadLock();
   }
   try
   {
     this.rwOrderByOrdId.EnterReadLock();
     this.orderByOrdId.TryGetValue(to.TransactionId.ToString(), out order);
   }
   finally
   {
     this.rwOrderByOrdId.ExitReadLock();
   }
   if (order == null)
   {
     try
     {
       this.rwOrderByOrdNo.EnterReadLock();
       this.orderByOrdNo.TryGetValue(to.OrderNo, out order);
     }
     finally
     {
       this.rwOrderByOrdNo.ExitReadLock();
     }
     if (order != null)
     {
       order.OrderID = to.TransactionId.ToString();
       try
       {
         this.rwOrderByOrdId.EnterWriteLock();
         this.orderByOrdId.Add(order.OrderID, order);
       }
       finally
       {
         this.rwOrderByOrdId.ExitWriteLock();
       }
     }
     else
     {
       if (!this.OutputUnknownOrderError)
         return;
       this.EmitError(string.Format("Unknown order. TransactionID={0} OrderNo={1}", (object) to.TransactionId, (object) to.OrderNo));
       return;
     }
   }
   if (to.OrderNo != 0L)
   {
     try
     {
       this.rwOrderByOrdNo.EnterUpgradeableReadLock();
       if (!this.orderByOrdNo.ContainsKey(to.OrderNo))
       {
         this.rwOrderByOrdNo.EnterWriteLock();
         this.orderByOrdNo.Add(to.OrderNo, order);
       }
     }
     finally
     {
       if (this.rwOrderByOrdNo.IsWriteLockHeld)
         this.rwOrderByOrdNo.ExitWriteLock();
       this.rwOrderByOrdNo.ExitUpgradeableReadLock();
     }
   }
   if (string.IsNullOrWhiteSpace(to.Status))
     return;
   switch (to.Status)
   {
     case "active":
     case "wait":
     case "watching":
       if (order.Status == OrderStatus.PendingNew && to.OrderNo != 0L)
       {
         this.EmitAccepted(order);
         break;
       }
       else
         break;
     case "cancelled":
       if (to.WithdrawTime == "0")
       {
         this.EmitPendingCancel(order);
         break;
       }
       else if ((double) to.Quantity == to.Balance || order.LeavesQty == to.Balance)
       {
         this.EmitCancelled(order);
         break;
       }
       else if (!this.balanceByOrderNoForCancel.ContainsKey(to.OrderNo))
       {
         this.balanceByOrderNoForCancel.Add(to.OrderNo, to.Balance);
         break;
       }
       else
       {
         this.balanceByOrderNoForCancel[to.OrderNo] = to.Balance;
         break;
       }
     case "disabled":
     case "removed":
       if ((double) to.Quantity == to.Balance || order.LeavesQty == to.Balance)
       {
         this.EmitRejected(order, to.Result);
         break;
       }
       else if (!this.balanceByOrderNoForCancel.ContainsKey(to.OrderNo))
       {
         this.balanceByOrderNoForCancel.Add(to.OrderNo, to.Balance);
         break;
       }
       else
       {
         this.balanceByOrderNoForCancel[to.OrderNo] = to.Balance;
         break;
       }
     case "denied":
     case "failed":
     case "refused":
     case "rejected":
       this.EmitRejected(order, to.Result);
       break;
   }
   if (!order.IsDone)
     return;
   this.RemoveOrder(to.TransactionId, to.OrderNo, true, true, true, false);
 }