Exemplo n.º 1
0
        protected void ProcessNewOrder(object param)
        {
            try
            {
                lock (tLock)
                {
                    Wrapper wrapper = (Wrapper)param;
                    Order   order   = OrderConverter.ConvertNewOrder(wrapper);
                    string  sender  = (string)wrapper.GetField(OrderFields.SENDER);

                    if (!string.IsNullOrEmpty(sender) && TestingModules.ContainsKey(sender))
                    {
                        SentOrders.Add(order.ClOrdId, sender);

                        QuickFix.Message nos = FIXMessageCreator.CreateNewOrderSingle(order.ClOrdId, order.Security.Symbol, order.Side, order.OrdType, order.SettlType,
                                                                                      order.TimeInForce, order.EffectiveTime, order.OrderQty, order.Price, order.StopPx,
                                                                                      order.Account, order.Exchange);

                        Session.SendToTarget(nos, SessionID);

                        SendersDict.Add(nos.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum), sender);
                        KeysDict.Add(nos.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum), order.ClOrdId);
                    }
                    else
                    {
                        throw new Exception("Cannot create an order for unknown sender");
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("Critical error processing new order @{0}:{1}", Configuration.Name, ex.Message), Fwk.Main.Common.Util.Constants.MessageType.Error);
            }
        }
Exemplo n.º 2
0
        public override bool Initialize(OnMessageReceived pOnPublishMessage, OnLogMessage pOnLogMsg, string configFile)
        {
            try
            {
                this.ModuleConfigFile  = configFile;
                this.DoPublishMessage += pOnPublishMessage;
                this.OnLogMsg         += pOnLogMsg;

                if (LoadConfig(configFile))
                {
                    SentOrders     = new Dictionary <string, string>();
                    SendersDict    = new Dictionary <int, string>();
                    KeysDict       = new Dictionary <int, string>();
                    TestingModules = new Dictionary <string, ICommunicationModule>();

                    FIXMessageCreator = new FIXMessageCreator();

                    string path = Configuration.InitiatorCfg;
                    TestingModulesInitialized = false;

                    SessionSettings  = new SessionSettings(path);
                    FileStoreFactory = new FileStoreFactory(SessionSettings);
                    ScreenLogFactory = new ScreenLogFactory(SessionSettings);
                    MessageFactory   = new QuickFix.FIX44.MessageFactory();

                    Initiator = new SocketInitiator(this, FileStoreFactory, SessionSettings, ScreenLogFactory);

                    Initiator.Start();

                    return(true);
                }
                else
                {
                    DoLog("Error initializing config file " + configFile, Constants.MessageType.Error);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                DoLog("Critic error initializing " + configFile + ":" + ex.Message, Constants.MessageType.Error);
                return(false);
            }
        }