internal void Place(Account owner, Protocal.TransactionData tranData, out string tranCode) { if (this.IsPriceOutOfDate(owner, tranData)) { throw new TransactionServerException(TransactionError.PriceIsOutOfDate); } var tran = this.CreateTran(owner, tranData, out tranCode); Logger.InfoFormat("place tranid = {0}, subType = {1}", tran.Id, tran.SubType); this.PreCheck(owner, tran); this.Verify(owner, tran, tranData.PlaceByRiskMonitor, tranData.AppType, PlaceContext.Empty); if (!tran.CanAutoAcceptPlace()) { tran.ChangePhaseToPlacing(); TransactionExpireChecker.Default.Add(tran); tran.Owner.InvalidateInstrumentCacheAndBroadcastChanges(tran); return; } if (tran.ShouldAutoFill() && tran.IsPriceInRangeOfAutoFill()) { foreach (var eachOrder in tran.Orders) { eachOrder.IsAutoFill = true; } } owner.InvalidateInstrumentCacheAndBroadcastChanges(tran); Logger.InfoFormat("begin place to engine accountId = {0}, tranId = {1}", owner.Id, tran.Id); this.PlaceToEngine(owner, tran); }
private Transaction CreateTran(Account account, Protocal.TransactionData tranData, out string tranCode) { var tran = account.CreateTransaction(tranData); tranCode = tran.Code; tran.ChangePhaseToPlaced(); tran.PlacePhase = PlacePhase.Received; account.InvalidateInstrumentCache(tran); return(tran); }
public TransactionError Place(Protocal.TransactionData tranData) { try { return(ServerFacade.Default.Server.Place(tranData)); } catch (Exception ex) { Logger.Error(ex); return(TransactionError.RuntimeError); } }
private bool IsChangeToIfDone(Protocal.TransactionData tranData) { if (tranData.SubType != TransactionSubType.Amend) { return(false); } foreach (var eachOrderData in tranData.Orders) { if (eachOrderData.IfDoneOrderSetting != null) { return(true); } } return(false); }
private bool IsPriceOutOfDate(Account owner, Protocal.TransactionData tranData) { var systemParameter = Settings.Setting.Default.SystemParameter; if (systemParameter.MaxPriceDelayForSpotOrder == null) { return(false); } if (tranData.OrderType == OrderType.SpotTrade) { foreach (var eachOrderNode in tranData.Orders) { if (this.IsOrderPriceOutOfDate(owner, tranData, eachOrderNode, systemParameter)) { return(true); } } } return(false); }
private bool IsOrderPriceOutOfDate(Account owner, Protocal.TransactionData tranData, Protocal.OrderData orderNode, SystemParameter systemParameter) { if (orderNode.PriceIsQuote != null && !orderNode.PriceIsQuote.Value) { DateTime timestamp = orderNode.PriceTimestamp.Value; var instrument = owner.GetOrCreateInstrument(tranData.InstrumentId); var submitor = Settings.Setting.Default.GetCustomer(tranData.SubmitorId); Quotation quotation = instrument.GetQuotation(submitor); if (quotation != null) { TimeSpan diff = (quotation.Timestamp - timestamp); if (diff >= systemParameter.MaxPriceDelayForSpotOrder) { string message = string.Format("Pirce is out of date, instrument id = {0}, last price timestamp = {1}, setprice timestamp = {2}, diff = {3}{4}{5}", tranData.InstrumentId, quotation.Timestamp, timestamp, diff, Environment.NewLine, tranData.ToString()); Logger.Warn(message); return(true); } } } return(false); }
private TransactionError PlaceCommon(Protocal.TransactionData tranData, out string tranCode) { _readWriteLock.EnterReadLock(); tranCode = null; try { Logger.Warn("Place order"); var account = GetAccount(tranData.AccountId); TransactionError tranError = account.Place(tranData, out tranCode); return(tranError); } catch (Exception ex) { Logger.Error(ex); return(TransactionError.RuntimeError); } finally { _readWriteLock.ExitReadLock(); } }
internal static TransactionData ToTransactionData(Token token, XmlNode tran) { string tranCode = string.Empty; Protocal.TransactionData tranData = TransactionParser.ParseTransaction(tran); tranData.PlaceByRiskMonitor = token.AppType == AppType.RiskMonitor ? true : false; tranData.Id = Guid.Parse(tran.Attributes["ID"].Value); tranData.Orders = new List <OrderData>(); InstrumentCategory instrumentCategory = InstrumentCategory.Forex; if (tran.Attributes["InstrumentCategory"] != null) { instrumentCategory = (InstrumentCategory)Enum.Parse(typeof(InstrumentCategory), tran.Attributes["InstrumentCategory"].Value); } foreach (XmlNode orderNode in tran.ChildNodes) { if (orderNode.Name == "Order") { OrderData orderData = null; if (tranData.OrderType == OrderType.BinaryOption) { orderData = OrderDataHelper.InitializeBOData(orderNode); } else if (instrumentCategory == InstrumentCategory.Forex) { orderData = OrderDataHelper.Initialize(orderNode); } else { orderData = OrderDataHelper.InitializePhysicalData(orderNode); } tranData.Orders.Add(orderData); } } return(tranData); }
static Protocal.TransactionData CreateTransactionData() { Protocal.TransactionData tranData = new Protocal.TransactionData(); tranData.Id = Guid.NewGuid(); tranData.InstrumentId = Guid.Parse("33C4C6E2-E33C-4A21-A01A-35F4EC647890"); tranData.AccountId = Guid.Parse("B940D4B7-4A4E-46DF-8EA4-77B0C3CC1A6B"); tranData.Type = iExchange.Common.TransactionType.Single; tranData.SubType = iExchange.Common.TransactionSubType.None; tranData.OrderType = iExchange.Common.OrderType.SpotTrade; tranData.ExpireType = iExchange.Common.ExpireType.Day; var baseTime = DateTime.Now; tranData.BeginTime = baseTime; tranData.EndTime = baseTime.AddMinutes(30); tranData.SubmitTime = baseTime; tranData.SubmitorId = Guid.Parse("CB58B47D-A705-42DD-9308-6C6B26CE79A7"); tranData.Orders = new List <Protocal.OrderData>(); var order = CreateOrderData(); tranData.Orders.Add(order); return(tranData); }
public TransactionError PlaceHistoryOrder(Protocal.TransactionData tranData) { return(TransactionError.OK); //return ServerFacade.Default.Server.Book(tranData); }
public void PlaceByModel(Protocal.TransactionData tranData) { ServerFacade.Default.Server.Place(tranData); }
protected AddTransactionCommandBase(Account account, Protocal.TransactionData tran, AddTransactionCommandVisitorBase visitor) : this(account, tran.PlaceByRiskMonitor, visitor) { this.TransactionData = tran; }
internal TransactionError Place(Protocal.TransactionData tranData, out string tranCode) { return(PlaceCommon(tranData, out tranCode)); }
public TransactionError Place(Protocal.TransactionData tranData) { string tranCode; return(PlaceCommon(tranData, out tranCode)); }