Ejemplo n.º 1
0
        public void SplitCancelCopy()
        {
            lasto = new OrderImpl();
            oc = 0;
            cancels.Clear();
            ost = new OversellTracker();
            ost.SendOrderEvent += new OrderDelegate(ost_SendOrderEvent);
            ost.SendDebugEvent += new DebugDelegate(rt.d);
            ost.SendCancelEvent += new LongDelegate(ost_SendCancelEvent);

            ost.Split = true;
            // take a position
            ost.GotPosition(new PositionImpl("TST", 100, 300));
            // over sell
            Order o = new SellMarket("TST", 500);
            o.id = 5;
            ost.sendorder(o);
            // verify that only flat was sent
            Assert.AreEqual(2, oc);
            Assert.AreEqual(-200, lasto.size);
            // make sure we've not canceled
            Assert.AreEqual(0, cancels.Count);
            // cancel original order
            ost.sendcancel(5);
            // ensure two cancels sent
            Assert.AreEqual(2, cancels.Count);
            // ensure different cancels
            Assert.AreEqual(5, cancels[0]);
            Assert.AreNotEqual(5, cancels[1]);

            // do it again

            // take a position
            ost.GotPosition(new PositionImpl("TST", 100, 300));

            // over sell
            o = new SellMarket("TST", 500);
            o.id = 10;
            ost.sendorder(o);
            // verify that only flat was sent
            Assert.AreEqual(4, oc);
            Assert.AreEqual(-200, lasto.size);
            // make sure we've not canceled
            Assert.AreEqual(2, cancels.Count);
            // cancel original order
            ost.sendcancel(10);
            // ensure two cancels sent
            Assert.AreEqual(4, cancels.Count);
            // ensure different cancels
            Assert.AreEqual(10, cancels[2]);
            Assert.AreNotEqual(10, cancels[3]);


        }
Ejemplo n.º 2
0
 public void TestNormal()
 {
     lasto = new OrderImpl();
     oc = 0;
     ost = new OversellTracker();
     ost.SendOrderEvent += new OrderDelegate(ost_SendOrderEvent);
     ost.SendDebugEvent += new DebugDelegate(rt.d);
     // take a position
     ost.GotPosition(new PositionImpl("TST"));
     // over sell
     ost.sendorder(new SellMarket("TST", 500));
     // verify that was sent
     Assert.AreEqual(1, oc);
     Assert.AreEqual(-500, lasto.size);
 }
Ejemplo n.º 3
0
        public void TestOverSellAdjust()
        {
            lasto = new OrderImpl();
            oc = 0;
            ost = new OversellTracker();
            ost.SendOrderEvent += new OrderDelegate(ost_SendOrderEvent);
            ost.SendDebugEvent += new DebugDelegate(rt.d);

            ost.Split = true;
            // take a position
            ost.GotPosition(new PositionImpl("TST", 100, 300));
            // over sell
            ost.sendorder(new SellMarket("TST", 500));
            // verify that only flat was sent
            Assert.AreEqual(2, oc);
            Assert.AreEqual(-200, lasto.size);
        }
Ejemplo n.º 4
0
        public void SplitWithPartialFillRoundMinsize100()
        {
            lasto = new OrderImpl();
            oc = 0;
            ost = new OversellTracker();
            ost.SendOrderEvent += new OrderDelegate(ost_SendOrderEvent);
            ost.SendDebugEvent += new DebugDelegate(rt.d);
            ost.MinLotSize = 100;

            ost.Split = true;
            // take a position
            ost.GotPosition(new PositionImpl("TST", 100, 58));
            // over sell
            Order o = new SellMarket("TST", 100);
            o.id = 1;
            ost.sendorder(o);
            // verify that flat and adjustment were sent
            Assert.AreEqual(1, oc);
            Assert.AreEqual(-100, lasto.size);
        }
Ejemplo n.º 5
0
        public bool Start()
        {
            try
            {
                if (_connected) return true;
                ost = new OversellTracker(pt);
                ost.Split = OversellSplit;
                ost.SendOrderEvent += new OrderDelegate(ost_SendOrderEvent);
                ost.SendDebugEvent += new DebugDelegate(ost_SendDebugEvent);
                debug(Util.TLSIdentity());
                debug("Attempting to start: " + PROGRAM);
                // basic structures needed for operation
                stiEvents = new STIEvents();
                stiOrder = new STIOrderMaint();
                stiPos = new STIPosition();
                stiQuote = new STIQuote();
                stiBook = new STIBook();
                stiApp = new STIApp();
                _bw = new Thread(new ParameterizedThreadStart(background));
                _runbg = true;
                _bw.Start();
                ptt.GotCancelEvent+=new LongDelegate(tl.newCancel);
                ptt.GotFillEvent+=new FillDelegate(tl.newFill);
                ptt.GotOrderEvent+=new OrderDelegate(tl.newOrder);
                ptt.SendDebugEvent += new DebugDelegate(ptt_SendDebugEvent);
                ptt.UseBidAskFills = isPaperTradeUsingBidAsk;

                stiEvents.OnSTIShutdown += new _ISTIEventsEvents_OnSTIShutdownEventHandler(stiEvents_OnSTIShutdown);
                stiEvents.SetOrderEventsAsStructs(true);

                stiEvents.OnSTIOrderUpdate += new _ISTIEventsEvents_OnSTIOrderUpdateEventHandler(stiEvents_OnSTIOrderUpdate);
                stiEvents.OnSTIOrderUpdateXML += new _ISTIEventsEvents_OnSTIOrderUpdateXMLEventHandler(stiEvents_OnSTIOrderUpdateXML);
                stiEvents.OnSTITradeUpdate += new _ISTIEventsEvents_OnSTITradeUpdateEventHandler(stiEvents_OnSTITradeUpdate);
                stiEvents.OnSTITradeUpdateXML += new _ISTIEventsEvents_OnSTITradeUpdateXMLEventHandler(stiEvents_OnSTITradeUpdateXML);
                stiPos.OnSTIPositionUpdate += new _ISTIPositionEvents_OnSTIPositionUpdateEventHandler(stiPos_OnSTIPositionUpdate);
                stiPos.OnSTIPositionUpdateXML += new _ISTIPositionEvents_OnSTIPositionUpdateXMLEventHandler(stiPos_OnSTIPositionUpdateXML);
                stiQuote.OnSTIQuoteUpdate += new _ISTIQuoteEvents_OnSTIQuoteUpdateEventHandler(stiQuote_OnSTIQuoteUpdate);
                stiQuote.OnSTIQuoteSnap += new _ISTIQuoteEvents_OnSTIQuoteSnapEventHandler(stiQuote_OnSTIQuoteSnap);
                stiEvents.OnSTIOrderRejectMsg += new _ISTIEventsEvents_OnSTIOrderRejectMsgEventHandler(stiEvents_OnSTIOrderRejectMsg);
                stiEvents.OnSTIOrderRejectXML += new _ISTIEventsEvents_OnSTIOrderRejectXMLEventHandler(stiEvents_OnSTIOrderRejectXML);
                stiEvents.OnSTIOrderReject += new _ISTIEventsEvents_OnSTIOrderRejectEventHandler(stiEvents_OnSTIOrderReject);
                stiQuote.OnSTIQuoteUpdateXML += new _ISTIQuoteEvents_OnSTIQuoteUpdateXMLEventHandler(stiQuote_OnSTIQuoteUpdateXML);
                stiQuote.OnSTIQuoteSnapXML += new _ISTIQuoteEvents_OnSTIQuoteSnapXMLEventHandler(stiQuote_OnSTIQuoteSnapXML);
                stiPos.GetCurrentPositions();

                tl.newAcctRequest += new StringDelegate(tl_newAcctRequest);
                tl.newProviderName = Providers.Sterling;
                tl.newSendOrderRequest += new OrderDelegateStatus(tl_gotSrvFillRequest);
                tl.newPosList += new PositionArrayDelegate(tl_gotSrvPosList);
                tl.newRegisterSymbols += new SymbolRegisterDel(tl_newRegisterSymbols);
                tl.newOrderCancelRequest += new LongDelegate(tl_OrderCancelRequest);
                tl.newFeatureRequest += new MessageArrayDelegate(tl_newFeatureRequest);
                tl.newUnknownRequest += new UnknownMessageDelegate(tl_newUnknownRequest);
                tl.newImbalanceRequest += new VoidDelegate(tl_newImbalanceRequest);
                tl.SendDebugEvent += new DebugDelegate(tl_SendDebugEvent);
                stiApp.SetModeXML(UseXmlMode);
                string trader = stiApp.GetTraderName().ToUpper();
                debug("trader: " + trader);
                if (!accts.Contains(trader))
                {
                    accts.Add(trader);
                    debug("accounts: " + string.Join(",", Accounts));
                }

                if(VerboseDebugging)
                    debug("Verbose Mode On.");
                if (isPaperTradeEnabled)
                    debug("Papertrading enabled.");

            }
            catch (Exception ex)
            {
                debug(ex.Message + ex.StackTrace);
                _connected = false;
                return false;
            }
            debug(PROGRAM + " started.");
            _connected = true;
            return _connected;
        }
Ejemplo n.º 6
0
        public bool Start()
        {
            try
            {
                if (_connected) return true;
                ost = new OversellTracker(pt,_idt);
                ost.MinLotSize = MinLotSize;
                ost.Split = OversellSplit;
                ost.SendOrderEvent += new OrderDelegate(ost_SendOrderEvent);
                ost.SendDebugEvent += new DebugDelegate(ost_SendDebugEvent);
                ost.SendCancelEvent += new LongDelegate(reqcancel);
                ost.VerboseDebugging = VerboseDebugging;
                sho.SendDebugEvent+=new DebugDelegate(v);
                sho.DefaultAccount = Account;
                sho.VerboseDebugging = VerboseDebugging;
                
                debug(Util.TLSIdentity());
                debug("Attempting to start: " + PROGRAM);
                // basic structures needed for operation
                stiEvents = new STIEvents();
                stiOrder = new STIOrderMaint();
                stiPos = new STIPosition();
                stiQuote = new STIQuote();
                stiBook = new STIBook();
                stiApp = new STIApp();
                stiMaint = new STIAcctMaint();
                _bw = new Thread(new ParameterizedThreadStart(background));
                _runbg = true;
                _bw.Start();
                ptt.GotCancelEvent+=new LongDelegate(newcancel);
                ptt.GotFillEvent += new FillDelegate(tl.newFill);
                ptt.GotOrderEvent+=new OrderDelegate(tl.newOrder);
                ptt.SendDebugEvent += new DebugDelegate(ptt_SendDebugEvent);
                ptt.UseBidAskFills = isPaperTradeUsingBidAsk;

                stiEvents.OnSTIShutdown += new _ISTIEventsEvents_OnSTIShutdownEventHandler(stiEvents_OnSTIShutdown);
                stiEvents.SetOrderEventsAsStructs(true);
                stiApp.SetModeXML(UseXmlMode);

                stiEvents.OnSTIOrderUpdate += new _ISTIEventsEvents_OnSTIOrderUpdateEventHandler(stiEvents_OnSTIOrderUpdate);
                stiEvents.OnSTIOrderUpdateXML += new _ISTIEventsEvents_OnSTIOrderUpdateXMLEventHandler(stiEvents_OnSTIOrderUpdateXML);
                stiEvents.OnSTITradeUpdate += new _ISTIEventsEvents_OnSTITradeUpdateEventHandler(stiEvents_OnSTITradeUpdate);
                stiEvents.OnSTITradeUpdateXML += new _ISTIEventsEvents_OnSTITradeUpdateXMLEventHandler(stiEvents_OnSTITradeUpdateXML);
                stiPos.OnSTIPositionUpdate += new _ISTIPositionEvents_OnSTIPositionUpdateEventHandler(stiPos_OnSTIPositionUpdate);
                stiPos.OnSTIPositionUpdateXML += new _ISTIPositionEvents_OnSTIPositionUpdateXMLEventHandler(stiPos_OnSTIPositionUpdateXML);
                stiQuote.OnSTIQuoteUpdate += new _ISTIQuoteEvents_OnSTIQuoteUpdateEventHandler(stiQuote_OnSTIQuoteUpdate);
                stiQuote.OnSTIQuoteSnap += new _ISTIQuoteEvents_OnSTIQuoteSnapEventHandler(stiQuote_OnSTIQuoteSnap);
                stiEvents.OnSTIOrderRejectMsg += new _ISTIEventsEvents_OnSTIOrderRejectMsgEventHandler(stiEvents_OnSTIOrderRejectMsg);
                stiEvents.OnSTIOrderRejectXML += new _ISTIEventsEvents_OnSTIOrderRejectXMLEventHandler(stiEvents_OnSTIOrderRejectXML);
                stiEvents.OnSTIOrderReject += new _ISTIEventsEvents_OnSTIOrderRejectEventHandler(stiEvents_OnSTIOrderReject);
                stiQuote.OnSTIQuoteUpdateXML += new _ISTIQuoteEvents_OnSTIQuoteUpdateXMLEventHandler(stiQuote_OnSTIQuoteUpdateXML);
                stiQuote.OnSTIQuoteSnapXML += new _ISTIQuoteEvents_OnSTIQuoteSnapXMLEventHandler(stiQuote_OnSTIQuoteSnapXML);

                Array acctlist = new string[0];
                stiMaint.GetAccountList(ref acctlist);
                if (acctlist.Length > 0)
                {
                    foreach (string au in acctlist)
                        Accounts = new string[] { au};


                }
                stiPos.GetCurrentPositions();
                

                tl.newAcctRequest += new StringDelegate(tl_newAcctRequest);
                tl.newProviderName = Providers.Sterling;
                tl.newSendOrderRequest += new OrderDelegateStatus(tl_gotSrvFillRequest);
                tl.newPosList += new PositionArrayDelegate(tl_gotSrvPosList);
                tl.newRegisterSymbols += new SymbolRegisterDel(tl_newRegisterSymbols);
                tl.newOrderCancelRequest += new LongDelegate(tl_OrderCancelRequest);
                tl.newFeatureRequest += new MessageArrayDelegate(tl_newFeatureRequest);
                tl.newUnknownRequest += new UnknownMessageDelegate(tl_newUnknownRequest);
                tl.newImbalanceRequest += new VoidDelegate(tl_newImbalanceRequest);
                tl.SendDebugEvent += new DebugDelegate(tl_SendDebugEvent);
                
                string trader = stiApp.GetTraderName().ToUpper();
                debug("trader: " + trader);
                if (!accts.Contains(trader))
                {
                    accts.Add(trader);
                    debug("accounts: " + string.Join(",", Accounts));
                }

                debug("VerboseDebugging: " + (VerboseDebugging ? "ON" : "disabled."));
                debug("PaperTrade: " + (isPaperTradeEnabled ? "ON" : "disabled."));
                debug("OversellSplit: " + (OversellSplit ? "ON" : "disabled."));
                debug("CoverEnabled: " + (CoverEnabled? "ON" : "disabled."));
                debug("RegSHOShorts: " + (RegSHOShorts ? "ON" : "disabled."));
                debug("ServerStops: " + (UseServerStops ? "ON" : "disabled."));
                debug("SendCancelOnRejects: "+(SendCancelOnReject ? "ON" : "disabled."));
                debug("SendCancelOnError: " + (SendCancelOnError? "ON" : "disabled."));
                debug("UseSubscribedSymbolForNotify: " + (UseSubscribedSymbolForNotify? "ON" : "disabled."));
                
                
            }
            catch (Exception ex)
            {
                debug(ex.Message + ex.StackTrace);
                _connected = false;
                return false;
            }
            debug(PROGRAM + " started.");
            _connected = true;
            return _connected;
        }
Ejemplo n.º 7
0
        public ASP()
        {
            TrackEnabled = Util.TrackUsage();
            Program = PROGRAM;
            // read designer options for gui
            InitializeComponent();
            // show status
            status(Util.TLSIdentity());
            debug(Util.TLSIdentity());
            // count instances of program
            _ASPINSTANCE = getprocesscount(PROGRAM)-1;
            // ensure have not exceeded maximum
            if ((_ASPINSTANCE + 1) > MAXASPINSTANCE)
            {
                MessageBox.Show("You have exceeded maximum # of running ASPs (" + MAXASPINSTANCE + ")." + Environment.NewLine + "Please close some.", "too many ASPs");
                status("Too many ASPs.  Disabled.");
                debug("Too many ASPs.  Disabled.");
                return;
            }
            else
            {
                status("ASP " + (_ASPINSTANCE+1) + "/" + MAXASPINSTANCE);
                debug("ASP " + (_ASPINSTANCE+1) + "/" + MAXASPINSTANCE);
            }
            // set next response id
            _NEXTRESPONSEID = _ASPINSTANCE * MAXRESPONSEPERASP;
            _INITIALRESPONSEID = _NEXTRESPONSEID;
            _remskin.Click+=new EventHandler(_remskin_Click);
            _saveskins.Click+=new EventHandler(_saveskins_Click);
            _skins.SelectedIndexChanged+=new EventHandler(_skins_SelectedIndexChanged);
            _dw.NewCreateTicketEvent += new DebugDelegate(_dw_NewCreateTicketEvent);
            _ar.GotTick += new TickDelegate(tl_gotTick);
            _ar.GotBadTick += new VoidDelegate(_ar_GotBadTick);
            _ar.GotTickOverrun += new VoidDelegate(_ar_GotTickOverrun);
            string[] servers = Properties.Settings.Default.ServerIpAddresses.Split(',');
            _ost = new OversellTracker(_pt, _masteridt);
            _ost.SendDebugEvent += new DebugDelegate(debug);
            _ost.SendOrderEvent += new OrderDelegate(sendorder);
            _ost.Split = Properties.Settings.Default.OversellSplit;
            _bf = new BrokerFeed(Properties.Settings.Default.prefquote, Properties.Settings.Default.prefexecute,_ao._providerfallback.Checked,false,PROGRAM,servers,Properties.Settings.Default.ServerPort);
            _bf.VerboseDebugging = Properties.Settings.Default.VerboseDebugging;
            _bf.SendDebugEvent+=new DebugDelegate(debug);
            _rt.PushTracksCloseMax = Properties.Settings.Default.TicketsOnCloseMaxAttempts;
            _rt.PushTracksOnClose = Properties.Settings.Default.TicketsOnClose;
            _rt.TrackEnabled = Properties.Settings.Default.TicketTracking;
            _rt.SendDebug += new DebugDelegate(debug);
            debug(RunTracker.CountNewGetPrettyRuns(PROGRAM,Util.PROGRAM));
            // get providers
            initfeeds();
            // get asp option events
            _ao.MktTimestampChange += new VoidDelegate(_ao_MktTimestampChange);
            _ao.TimeoutChanged += new Int32Delegate(_ao_TimeoutChanged);
            _ao._datasel.SelectionChangeCommitted+= new EventHandler(_prefquot_SelectedIndexChanged);
            _ao._execsel.SelectionChangeCommitted+= new EventHandler(_prefexec_SelectedIndexChanged);
            // setup right click menu
            _resnames.ContextMenu= new ContextMenu();
            _resnames.ContextMenu.Popup += new EventHandler(ContextMenu_Popup);
            _resnames.ContextMenu.MenuItems.Add("remove response", new EventHandler(remresp));
            _resnames.ContextMenu.MenuItems.Add("enabled", new EventHandler(toggleresponse));
            _resnames.ContextMenu.MenuItems.Add("save to skin", new EventHandler(add2skin));
            _resnames.ContextMenu.MenuItems.Add("edit symbols", new EventHandler(editsyms));
            // make sure we exit properly
            this.FormClosing += new FormClosingEventHandler(ASP_FormClosing);
            bw.DoWork += new DoWorkEventHandler(bw_DoWork);
            bw.RunWorkerAsync();
            // handle capital connections on seperate thread
            cc.DoWork += new DoWorkEventHandler(cc_DoWork);
            // write indicator output
            si.DoWork += new DoWorkEventHandler(si_DoWork);
            si.RunWorkerAsync();
            // get last loaded response library
            LoadResponseDLL(Properties.Settings.Default.boxdll);
            // load any skins we can find
            findskins();
            // process command line
            processcommands();

        }