示例#1
0
        /// <summary>
        /// Returns Jurisdiction by code.
        /// </summary>
        /// <param name="code">The jurisdiction code.</param>
        /// <param name="returnAllGroups">True, to return all jurisdiction groups.</param>
        /// <returns></returns>
        public static JurisdictionDto GetJurisdiction(string code, bool returnAllGroups)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = OrderCache.CreateCacheKey("jurisdiction-code", code, returnAllGroups.ToString());

            JurisdictionDto dto = null;

            // check cache first
            object cachedObject = OrderCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (JurisdictionDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                DataCommand cmd = OrderDataHelper.CreateConfigDataCommand();
                cmd.CommandText = "[ecf_Jurisdiction_JurisdictionCode]";
                cmd.Parameters  = new DataParameters();
                cmd.Parameters.Add(new DataParameter("ApplicationId", OrderConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier));
                cmd.Parameters.Add(new DataParameter("JurisdictionCode", code, DataParameterType.NVarChar, 50));
                cmd.Parameters.Add(new DataParameter("ReturnAllGroups", returnAllGroups, DataParameterType.Bit));
                cmd.DataSet      = new JurisdictionDto();
                cmd.TableMapping = DataHelper.MapTables("Jurisdiction", "JurisdictionGroup", "JurisdictionRelation");

                DataResult results = DataService.LoadDataSet(cmd);

                dto = (JurisdictionDto)results.DataSet;
            }

            return(dto);
        }
示例#2
0
 //重载OnRecvDataMsg方法,接收行情数据
 // 请注意:
 //  1. 不要在这个函数里做耗时操作
 //  2. 只在这个函数里做数据获取工作 -- 将数据复制到其它数据缓存区,由其它线程做业务逻辑处理
 public override void OnRecvDataMsg(TDFMSG msg)
 {
     if (msg.MsgID == TDFMSGID.MSG_DATA_MARKET)
     {
         //行情消息
         TDFMarketData[] marketDataArr = msg.Data as TDFMarketData[];
         MarketDataCache.Enqueue(marketDataArr);
     }
     else if (msg.MsgID == TDFMSGID.MSG_DATA_TRANSACTION)
     {
         //逐笔成交
         TDFTransaction[] transactionDataArr = msg.Data as TDFTransaction[];
         TransactionCache.Enqueue(transactionDataArr);
     }
     else if (msg.MsgID == TDFMSGID.MSG_DATA_ORDER)
     {
         //逐笔委托
         TDFOrder[] orderDataArr = msg.Data as TDFOrder[];
         OrderCache.Enqueue(orderDataArr);
     }
     else if (msg.MsgID == TDFMSGID.MSG_DATA_ORDERQUEUE)
     {
         //委托队列
         TDFOrderQueue[] orderQueueDataArr = msg.Data as TDFOrderQueue[];
         OrderQueueCache.Enqueue(orderQueueDataArr);
     }
 }
示例#3
0
 public void SetUp()
 {
     _tableNumber     = 5;
     _requestingUser  = "******";
     _orderRepository = new Mock <IOrderRepository>();
     _sut             = new OrderCache(_orderRepository.Object);
 }
示例#4
0
 /// <summary>
 /// Delete an estate object.
 /// </summary>
 /// <param name="key">Key of object to delete.</param>
 /// <returns>True if object was successfully deleted.</returns>
 public static bool DeleteObject(int key)
 {
     if (DealCache.ContainsKey(key))
     {
         return false;
     }
     OrderCache.Query (new SqlFieldsQuery
         ($"delete from Orders where ObjectID={key};"));
     BookmarkCache.Query (new SqlFieldsQuery
         ($"delete from Bookmarks where ObjectID={key};"));
     MatchCache.Query (new SqlFieldsQuery
         ($"delete from Matches where ObjectID={key};"));
     ObjectCache.Remove(key);
     return true;
 }
示例#5
0
        /// <summary>
        /// Gets the jurisdictions and jurisdiction groups for the specified jurisdiction type.
        /// </summary>
        /// <param name="jurisdictionType">JurisdictionType. 1 - tax, 2 - shipping. null - all jurisdictions.</param>
        /// <returns></returns>
        public static JurisdictionDto GetJurisdictions(JurisdictionType?jurisdictionType)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = OrderCache.CreateCacheKey("jurisdictions", jurisdictionType.HasValue ? jurisdictionType.Value.ToString() : String.Empty);

            JurisdictionDto dto = null;

            // check cache first
            object cachedObject = OrderCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (JurisdictionDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                DataCommand cmd = OrderDataHelper.CreateConfigDataCommand();
                cmd.CommandText = "[ecf_Jurisdiction]";
                cmd.Parameters  = new DataParameters();
                cmd.Parameters.Add(new DataParameter("ApplicationId", OrderConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier));
                if (jurisdictionType.HasValue)
                {
                    cmd.Parameters.Add(new DataParameter("JurisdictionType", jurisdictionType.Value.GetHashCode(), DataParameterType.Int));
                }
                cmd.DataSet      = new JurisdictionDto();
                cmd.TableMapping = DataHelper.MapTables("Jurisdiction", "JurisdictionGroup", "JurisdictionRelation");

                DataResult results = DataService.LoadDataSet(cmd);

                dto = (JurisdictionDto)results.DataSet;

                // Insert to the cache collection
                OrderCache.Insert(cacheKey, dto, OrderConfiguration.Instance.Cache.PaymentCollectionTimeout);
            }

            return(dto);
        }
示例#6
0
        /// <summary>
        /// Gets the shipping methods.
        /// </summary>
        /// <param name="languageid">The languageid.</param>
        /// <param name="returnInactive">if set to <c>true</c> [return inactive].</param>
        /// <returns></returns>
        public static ShippingMethodDto GetShippingMethods(string languageid, bool returnInactive)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = OrderCache.CreateCacheKey("shipping-methods", languageid, returnInactive.ToString());

            ShippingMethodDto dto = null;

            // check cache first
            object cachedObject = OrderCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (ShippingMethodDto)cachedObject;
            }


            // Load the object
            if (dto == null)
            {
                DataCommand cmd = OrderDataHelper.CreateConfigDataCommand();
                cmd.CommandText = "[ecf_ShippingMethod_Language]";
                cmd.Parameters  = new DataParameters();
                cmd.Parameters.Add(new DataParameter("ApplicationId", OrderConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier));
                cmd.Parameters.Add(new DataParameter("LanguageId", String.IsNullOrEmpty(languageid) ? null : languageid, DataParameterType.NVarChar, 10));
                cmd.Parameters.Add(new DataParameter("ReturnInactive", returnInactive, DataParameterType.Bit));
                cmd.DataSet      = new ShippingMethodDto();
                cmd.TableMapping = DataHelper.MapTables("ShippingOption", "ShippingOptionParameter", "ShippingMethod", "ShippingMethodParameter", "ShippingMethodCase", "ShippingCountry", "ShippingRegion", "ShippingPaymentRestriction", "Package", "ShippingPackage");

                DataResult results = DataService.LoadDataSet(cmd);

                dto = (ShippingMethodDto)results.DataSet;

                // Insert to the cache collection
                OrderCache.Insert(cacheKey, dto, OrderConfiguration.Instance.Cache.ShippingCollectionTimeout);
            }

            return(dto);
        }
示例#7
0
 public void ClearCache()
 {
     TDFMarketData[] tmp;
     while (MarketDataCache.TryDequeue(out tmp) == true)
     {
         ;
     }
     TDFTransaction[] tmp2;
     while (TransactionCache.TryDequeue(out tmp2) == true)
     {
         ;
     }
     TDFOrder[] tmp3;
     while (OrderCache.TryDequeue(out tmp3) == true)
     {
         ;
     }
     TDFOrderQueue[] tmp4;
     while (OrderQueueCache.TryDequeue(out tmp4) == true)
     {
         ;
     }
 }
示例#8
0
        /// <summary>
        /// Put Order entity into the cache. <br/>
        /// NOTE: usually order is put with empty AgentID. <br/>
        /// Referential integrity check is done on: <br/>
        /// Order.ClientID - Person.key <br/>
        /// Order.ObjectID - EstateObject.key
        /// </summary>
        /// <param name="value"></param>
        public static void PutOrder (Order value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if Person with key = value.ClientID is not found.
                if (!(PersonCache.ContainsKey(value.ClientID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Order cache.")
                    {
                        Operation = "put",
                        TableName = "Order",
                        FieldName = "ClientID",
                        ReadableMessage = $"Can not put new entry into Order cache because Person with key {value.ClientID} does not exist."
                    };
                }

                // Error if EstateObject with key = value.ObjectID is not found.
                if (!(ObjectCache.ContainsKey(value.ObjectID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Order cache.")
                    {
                        Operation = "put",
                        TableName = "Order",
                        FieldName = "ObjectID",
                        ReadableMessage = $"Can not put new entry into Order cache because EstateObject with key {value.ObjectID} does not exist."
                    };
                }

                // Normal operation
                long key = (((long)value.ClientID)<<32) + value.ObjectID;
                OrderCache.Put (key, value);
                tx.Commit();
            }
        }
示例#9
0
        /// <summary>
        /// Gets the countries.
        /// </summary>
        /// <param name="returnInactive">If true, all countries will be returned, otherwise only visible.</param>
        /// <returns></returns>
        public static CountryDto GetCountries(bool returnInactive)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = OrderCache.CreateCacheKey("countries", returnInactive.ToString());

            CountryDto dto = null;

            // check cache first
            object cachedObject = OrderCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (CountryDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                DataCommand cmd = OrderDataHelper.CreateConfigDataCommand();
                cmd.CommandText = "[ecf_Country]";
                cmd.Parameters  = new DataParameters();
                cmd.Parameters.Add(new DataParameter("ApplicationId", OrderConfiguration.Instance.ApplicationId, DataParameterType.UniqueIdentifier));
                cmd.Parameters.Add(new DataParameter("ReturnInactive", returnInactive, DataParameterType.Bit));
                cmd.DataSet      = new CountryDto();
                cmd.TableMapping = DataHelper.MapTables("Country", "StateProvince");

                DataResult results = DataService.LoadDataSet(cmd);

                dto = (CountryDto)results.DataSet;

                // Insert to the cache collection
                OrderCache.Insert(cacheKey, dto, OrderConfiguration.Instance.Cache.CountryCollectionTimeout);
            }

            return(dto);
        }
示例#10
0
        private void initTables()
        {
            _oc          = new OrderCache(_app);
            _oc.OnOrder += _oc_OnOrder;
            _oc.Start();
            state = OrderState.ConnectionPending;

            PST = new PositionTable(_app);
            PST.WantData(PST.TqlForPositions(), true, false);
            PST.OnPosition += PST_OnPosition;
            PST.Start();

            XPAT = new XPermsAccountsTable(_app);
            XPAT.OnXPermsAccounts += XPAT_OnXPermsAccounts;
            XPAT.WantData(XPAT.TqlForXPermsAccounts(), true, false);
            XPAT.Start();

            TBL         = new LiveQuoteTable(_app);
            TBL.OnData += TBL_OnData;

            _bw.RunWorkerAsync();

            _conn = true;
        }
示例#11
0
        private void initTables()
        {
            _oc = new OrderCache(_app);
            _oc.OnOrder += _oc_OnOrder;
            _oc.Start();
            state = OrderState.ConnectionPending;

            PST = new PositionTable(_app);
            PST.WantData(PST.TqlForPositions(), true, false);
            PST.OnPosition += PST_OnPosition;
            PST.Start();

            XPAT = new XPermsAccountsTable(_app);
            XPAT.OnXPermsAccounts += XPAT_OnXPermsAccounts;
            XPAT.WantData(XPAT.TqlForXPermsAccounts(), true, false);
            XPAT.Start();

            TBL = new LiveQuoteTable(_app);
            TBL.OnData += TBL_OnData;

            _bw.RunWorkerAsync();

            _conn = true;
        }
示例#12
0
        public void placeOrder(OrderDirections directions)
        {
            cancelOrder();
            cache           = new OrderCache(app);
            this.directions = directions;
            OrderBuilder bld = new OrderBuilder(cache);

            state = State.ConnectionPending;
            using (OrderWatcher watch = new OrderWatcher(cache, bld.OrderTag)) {
                cache.Start();
                while (state != State.ConnectionDead && state != State.OrderFinished)
                {
                    if (!WaitAny(10000, watch.WaitHandles))
                    {
                        WriteLine("TIMED OUT WaitAny(10000) WAITING FOR RESPONSE");
                        break;
                    }
                    OrderWatcher.Action action;
                    while (watch.GetNext(out action, out ord))
                    {
                        switch (action)
                        {
                        case OrderWatcher.Action.Live:
                            if (state == State.ConnectionPending)
                            {
                                WriteLine("SUBMITTING ORDER");
                                state = State.OrderPending;
                                bld.SetAccount(Configuration.getValue("Configuration/Account/Bank"),
                                               Configuration.getValue("Configuration/Account/Branch"),
                                               Configuration.getValue("Configuration/Account/Customer"),
                                               Configuration.getValue("Configuration/Account/Deposit"));
                                bld.SetBuySell(OrderBuilder.BuySell.BUY);
                                bld.SetExpiration(OrderBuilder.Expiration.DAY);
                                bld.SetRoute(directions.Route);
                                bld.SetSymbol(directions.Symbol, getExchange(directions), OrderBuilder.SecurityType.STOCKOPT);
                                bld.SetVolume(directions.Size);
                                bld.SetPriceLimit(directions.LimitPrice);
                                if (directions.Simulated)
                                {
                                    WriteLine("Am sending simulated order");
                                }
                                else
                                {
                                    WriteLine("Am sending real order");
                                    cache.SubmitOrder(bld);
                                }
                            }
                            break;

                        case OrderWatcher.Action.Dead:
                            WriteLine("CONNECTION FAILED");
                            state = State.ConnectionDead;
                            break;

                        case OrderWatcher.Action.Order:
                            DisplayOrder(ord);
                            if (state == State.OrderPending && ord.Type == "UserSubmitOrder")
                            {
                                if (ord.CurrentStatus == "COMPLETED")
                                {
                                    WriteLine("Order Completed");
                                    state = State.OrderFinished;
                                }
                                else
                                {
                                    WriteLine("Order UNEXPECTEDLY FINISHED");
                                    state = State.OrderFinished;
                                }
                            }
                            else if (state == State.CancelPending)
                            {
                                if (ord.CurrentStatus == "COMPLETED" || ord.CurrentStatus == "DELETED")
                                {
                                    state = State.OrderFinished;
                                }
                            }

                            if (ord.Type == "ExchangeTradeOrder")
                            {
                                WriteLine("GOT FILL FOR {0} {1} AT {2}", ord.Buyorsell, ord.Volume, ord.Price);
                            }
                            if (ord.Type == "ExchangeKillOrder")
                            {
                                WriteLine("GOT KILL");
                            }

                            break;
                        } // end switch
                    }     // end while getNext
                }         // end while state
            }             // end using watch
            WriteLine("DONE PLACING ORDER");
        }
示例#13
0
        public void placeOrder(OrderDirections directions)
        {
            cancelOrder();
              cache = new OrderCache(app);
              this.directions = directions;
              OrderBuilder bld = new OrderBuilder(cache);
              state = State.ConnectionPending;
              using (OrderWatcher watch = new OrderWatcher(cache, bld.OrderTag)) {
            cache.Start();
            while (state != State.ConnectionDead && state != State.OrderFinished) {
              if (!WaitAny(10000, watch.WaitHandles) ) {
            WriteLine("TIMED OUT WaitAny(10000) WAITING FOR RESPONSE");
            break;
              }
              OrderWatcher.Action action;
              while (watch.GetNext(out action, out ord)) {
            switch (action) {
            case OrderWatcher.Action.Live:
              if (state == State.ConnectionPending) {
            WriteLine("SUBMITTING ORDER");
            state = State.OrderPending;
            bld.SetAccount(Configuration.getValue("Configuration/Account/Bank"),
                   Configuration.getValue("Configuration/Account/Branch"),
                   Configuration.getValue("Configuration/Account/Customer"),
                   Configuration.getValue("Configuration/Account/Deposit"));
            bld.SetBuySell(OrderBuilder.BuySell.BUY);
            bld.SetExpiration(OrderBuilder.Expiration.DAY);
            bld.SetRoute(directions.Route);
            bld.SetSymbol(directions.Symbol, getExchange(directions), OrderBuilder.SecurityType.STOCKOPT);
            bld.SetVolume(directions.Size);
            bld.SetPriceLimit(directions.LimitPrice);
            if (directions.Simulated) {
              WriteLine("Am sending simulated order");
            }
            else {
              WriteLine("Am sending real order");
              cache.SubmitOrder(bld);
            }
              }
              break;
            case OrderWatcher.Action.Dead:
              WriteLine("CONNECTION FAILED");
              state = State.ConnectionDead;
              break;
            case OrderWatcher.Action.Order:
              DisplayOrder(ord);
              if( state==State.OrderPending && ord.Type=="UserSubmitOrder" ) {
            if( ord.CurrentStatus=="COMPLETED") {
            WriteLine("Order Completed");
            state = State.OrderFinished;
            }
            else {
              WriteLine("Order UNEXPECTEDLY FINISHED" );
              state = State.OrderFinished;
            }
              }
              else if (state == State.CancelPending) {
            if( ord.CurrentStatus=="COMPLETED" || ord.CurrentStatus=="DELETED" )
              state = State.OrderFinished;
              }

              if (ord.Type == "ExchangeTradeOrder")
            WriteLine("GOT FILL FOR {0} {1} AT {2}", ord.Buyorsell, ord.Volume, ord.Price);
              if (ord.Type == "ExchangeKillOrder")
            WriteLine("GOT KILL");

              break;
            } // end switch
              } // end while getNext
            } // end while state
              } // end using watch
              WriteLine("DONE PLACING ORDER");
        }