Ejemplo n.º 1
0
 internal void InitializeTransaction(IDataReader dr, Dictionary <Guid, Transaction> trans)
 {
     try
     {
         Guid    accountId = (Guid)dr["AccountID"];
         Account account   = _tradingSetting.GetAccount(accountId);
         if (account == null)
         {
             Logger.WarnFormat("account = {0} not exist but exist transaction", accountId);
             return;
         }
         var orderType          = (OrderType)(int)dr["OrderTypeID"];
         var instrumentCategory = (InstrumentCategory)dr["InstrumentCategory"];
         TransactionPhase phase = (TransactionPhase)(byte)dr["Phase"];
         if (phase == TransactionPhase.Canceled)
         {
             return;
         }
         var factory = TransactionFacade.CreateAddTranCommandFactory(orderType, instrumentCategory);
         var command = factory.Create(account, new DBReader(dr), OperationType.None);
         command.Execute();
         var tran = command.Result;
         trans.Add(tran.Id, tran);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
     }
 }
Ejemplo n.º 2
0
        private Transaction CreateCloseTransaction(Order order, Price closePrice, OrderType orderType)
        {
            var factory = TransactionFacade.CreateAddTranCommandFactory(orderType, order.Owner.InstrumentCategory);
            var command = factory.CreateByAutoClose(order.Owner.Owner, order, closePrice, orderType);

            command.Execute();
            return(command.Result);
        }
Ejemplo n.º 3
0
        internal static Transaction CreateTransaction(this Account account, Order originOrder, decimal lot)
        {
            var factory = TransactionFacade.CreateAddTranCommandFactory(originOrder.Owner.OrderType, originOrder.Owner.InstrumentCategory);
            var command = factory.CreateLmtQuantiryOnMaxLotChangeTransaction(account, originOrder, lot);

            command.Execute();
            return(command.Result);
        }
Ejemplo n.º 4
0
        internal Dictionary <Guid, Transaction> Parse(DataSet ds, out Dictionary <Guid, Order> orderDict)
        {
            var trans = new Dictionary <Guid, Transaction>(CAPACITY);

            SettingInitializer.InitializeWithException(ds, "Transaction", dr =>
            {
                Guid accountId  = (Guid)dr["AccountID"];
                Account account = _tradingSetting.GetAccount(accountId);
                if (account == null)
                {
                    Logger.WarnFormat("account = {0} not exist but exist transaction", accountId);
                    return;
                }
                var orderType          = (OrderType)(int)dr["OrderTypeID"];
                var instrumentCategory = (InstrumentCategory)dr["InstrumentCategory"];
                TransactionPhase phase = (TransactionPhase)(byte)dr["Phase"];
                if (phase == TransactionPhase.Canceled)
                {
                    return;
                }
                var factory = TransactionFacade.CreateAddTranCommandFactory(orderType, instrumentCategory);
                var command = factory.Create(account, new DBRow(dr), OperationType.AsNewRecord);
                command.Execute();
                var tran = command.Result;
                trans.Add(tran.Id, tran);
            });

            var orders = this.ParseOrders(ds, trans);

            orderDict = orders;

            SettingInitializer.InitializeWithException(ds, "OrderRelation", dr =>
            {
                var closeOrderId = (Guid)dr["CloseOrderID"];
                if (!orders.ContainsKey(closeOrderId))
                {
                    return;
                }
                Order closeOrder = orders[closeOrderId];
                if (closeOrder != null)
                {
                    var factory = OrderRelationFacade.Default.GetAddOrderRelationFactory(closeOrder);
                    var command = factory.Create(closeOrder, new DBRow(dr));
                    command.Execute();
                }
            });
            return(trans);
        }
Ejemplo n.º 5
0
        private Transaction CutCommon(Dictionary <Guid, decimal> closedLotPerOpenOrderDict, Instrument instrument, bool cutAsBuy, decimal lotBalanceSum, Price setPrice)
        {
            DateTime baseTime = Market.MarketManager.Now;
            var      account  = instrument.Owner;
            var      factory  = TransactionFacade.CreateAddTranCommandFactory(OrderType.Risk, instrument.Setting.Category);
            var      command  = factory.CreateCutTransaction(account, instrument, lotBalanceSum, setPrice, cutAsBuy);

            command.Execute();
            Transaction tran = command.Result;

            if (tran.InstrumentCategory == InstrumentCategory.Physical ||
                _account.Setting().RiskLevelAction == RiskLevelAction.CloseNetPosition || _account.Setting().RiskLevelAction == RiskLevelAction.CloseAll)
            {
                tran.FirstOrder.SplitOrder(closedLotPerOpenOrderDict, true);
            }
            return(tran);
        }
Ejemplo n.º 6
0
        private static AddTransactionCommandFactoryBase GetAddTranCommandFactory(this Protocal.TransactionCommonData tranData)
        {
            var instrument = Settings.Setting.Default.GetInstrument(tranData.InstrumentId);

            return(TransactionFacade.CreateAddTranCommandFactory(tranData.OrderType, instrument.Category));
        }