Example #1
0
        public void FixSentOnUnknown()
        {
            // reset everything
            id = 1;
            o  = new OrderImpl();
            ot = new OrderTracker();
            ot.SendDebugEvent      += new DebugDelegate(ot_SendDebugEvent);
            ot.VerboseDebugging     = true;
            ot.FixSentSizeOnUnknown = true;

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // prepare a buy order
            o = new BuyLimit(sym, 100, 100, id++);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // order will be invalid since it was sent previously (or unknown)
            Assert.False(ot.SentOrder(id - 1).isValid, "valid order was found, none was sent though");
            // verify size/pending/cancel
            Assert.AreEqual(100, ot.Sent(id - 1), "not sent buy");
            Assert.AreEqual(100, ot.Filled(id - 1), "incorrect fill size buy");
            Assert.IsTrue(ot.isCompleted(id - 1), "wrongly not filled");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Portfolio"/> class.
        /// </summary>
        /// <param name="clock">The clock.</param>
        /// <param name="actionscheduler">The actionscheduler.</param>
        /// <param name="brokerconnection">The brokerconnection.</param>
        /// <param name="brokermodel">The brokermodel.</param>
        /// <param name="currency">The currency.</param>
        /// <param name="eventrunner">The eventrunner.</param>
        /// <param name="exceptionhandler">The exceptionhandler.</param>
        /// <param name="orderTicketHandler">The order ticket handler.</param>
        /// <param name="brokeraccount">The brokeraccount.</param>
        /// <param name="cashmanager">The cashmanager.</param>
        /// <param name="runmode">The runmode.</param>
        /// <param name="datafeed">The datafeed.</param>
        /// <param name="benchmark">The benchmark.</param>
        /// <param name="id">The identifier.</param>
        public Portfolio(WorldClock clock, ActionsScheduler actionscheduler, BrokerConnection brokerconnection, BrokerModel brokermodel,
                         Currency currency, EventRunner eventrunner, ExceptionHandler exceptionhandler, OrderTicketHandler orderTicketHandler,
                         BrokerAccount brokeraccount, CashManager cashmanager, RunMode runmode, DataFeed datafeed, Benchmark benchmark, string id = "")
        {
            //Set references
            ActionsScheduler   = actionscheduler;
            BrokerAccount      = brokeraccount;
            BrokerConnection   = brokerconnection;
            BrokerModel        = brokermodel;
            Clock              = clock;
            Currency           = currency;
            EventRunner        = eventrunner;
            ExceptionHandler   = exceptionhandler;
            CashManager        = cashmanager;
            OrderTicketHandler = orderTicketHandler;
            _porfolioBenchmark = benchmark;

            //Set initial items
            Id            = id;
            IsBacktesting = runmode == RunMode.Backtester;
            OrderFactory  = new OrderFactory(this, BrokerModel);
            OrderTracker  = new OrderTracker(this);
            Subscription  = new DataSubscriptionManager(datafeed, CashManager);
            Results       = new Result(0, _porfolioBenchmark);

            //Portfolio benchmark is not used
            benchmark.OnCalc(x => 0);
        }
Example #3
0
        void OrderTrackerField(OrderTracker tracker)
        {
            if (!tracker)
            {
                return;
            }


            Rect r = EditorGUILayout.GetControlRect();

            if (tracker == target)
            {
                //GUI.enabled = true;
                Rect rBG = new Rect(r.x - 2, r.y - 2, r.width + 4, r.height + 4);
                GUI.Label(rBG, "", "SelectionRect");
                //GUI.enabled = false;
            }
            //Debug.Log(EditorStyles.foldout..background);


            Rect   rLable = new Rect(r.x, r.y, 100, r.height);
            string label  = string.Format(" {0}{1} [{2:+#;-#;+0}]", tracker == target ? "(Self) " : "", tracker.sortingOrder, tracker.addSortingOrder);

            EditorGUI.LabelField(rLable, new GUIContent(tracker == target ? "<b>" + label + "</b>" : label), "IN Foldout");

            Rect rField = new Rect(r.x + rLable.width, r.y, r.width - rLable.width, r.height);

            EditorGUI.ObjectField(
                rField,
                //string.Format("{0} : {1} [{2:+#;-#;+0}]", label, tracker.sortingOrder, tracker.addSortingOrder),
                tracker,
                typeof(OrderTracker),
                true);
        }
Example #4
0
        public void PartialFill()
        {
            // reset everything
            id = 1;
            o  = new OrderImpl();
            ot = new OrderTracker();
            ot.SendDebugEvent  += new DebugDelegate(ot_SendDebugEvent);
            ot.VerboseDebugging = true;

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // send a buy order
            o = new BuyLimit(sym, 200, 100, id++);
            ot.GotOrder(o);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // verify order is there
            Assert.IsTrue(ot.SentOrder(id - 1).isValid, "no valid order");
            // verify size/pending/cancel
            Assert.AreEqual(200, ot.Sent(id - 1), "not sent buy");
            Assert.AreEqual(100, ot.Filled(id - 1), "incorrect fill size buy");
            Assert.IsFalse(ot.isCompleted(id - 1), "wrongly completed");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsTrue(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");

            // do sell order

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // send sell order
            o = new SellLimit(sym, 200, 100, id++);
            ot.GotOrder(o);
            // fill it
            Assert.IsTrue(o.Fill(TickImpl.NewTrade(sym, 100, 100)), "order did not fill");
            ot.GotFill((Trade)o);
            // verify order is there
            Assert.IsTrue(ot.SentOrder(id - 1).isValid, "no valid order");
            // verify size/pending/cancel
            Assert.AreEqual(-100, ot.Filled(id - 1), "incorrect fill size sell");
            Assert.AreEqual(-200, ot.Sent(id - 1), "not sent sell");
            Assert.IsFalse(ot.isCompleted(id - 1), "wrongly completed");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsTrue(ot.isPending(id - 1), "wrongly pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");
        }
Example #5
0
 public int InsertOrder(OrderTracker OrderTracker)
 {
     using (var connection = _databaseConnectionProvider.GetDbConnection())
     {
         var insertQuery = @"INSERT INTO orderstatus(orderid,status) VALUES(@OrderId,@OrderStatus)";
         int id          = connection.Execute(insertQuery, OrderTracker);
         if (id <= 0)
         {
             throw new ArgumentException("An error has occured");
         }
         return(id);
     }
 }
Example #6
0
        static void Main(string[] args)
        {
            Manager manager = new Manager();

            ConditionA conditionA = new ConditionA(manager);
            ConditionB conditionB = new ConditionB(manager);

            OrderTracker tracker = new OrderTracker();

            tracker.TakeOrder(conditionA);
            tracker.TakeOrder(conditionB);

            tracker.RunOrders();
        }
        public void Sent()
        {
            // reset everything
            id = 1;
            o  = new OrderImpl();
            ot = new OrderTracker();
            ot.SendDebugEvent  += new DebugDelegate(ot_SendDebugEvent);
            ot.VerboseDebugging = true;

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // send a buy order
            ot.GotOrder(new BuyLimit(sym, 100, 100, id++));
            // verify order is there
            Assert.IsTrue(ot.SentOrder(id - 1).isValid, "no valid order");
            // verify size/pending/cancel
            Assert.AreEqual(100, ot.Sent(id - 1), "not sent");
            Assert.AreEqual(0, ot.Filled(id - 1), "incorrect fill size");
            Assert.IsFalse(ot.isCompleted(id - 1), "completed but not filled");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsTrue(ot.isPending(id - 1), "not pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");
            Assert.IsTrue(ot.GetOrderId(0) == 1, "no id at idx");

            // do sell order

            // verify no size/pending/cancel
            Assert.AreEqual(0, ot.Sent(id), "sent but not sent");
            Assert.IsFalse(ot.isCompleted(id), "completed but not sent");
            Assert.IsFalse(ot.isCanceled(id), "wrongly canceled");
            Assert.IsFalse(ot.isPending(id), "wrongly pending");
            Assert.IsFalse(ot.isTracked(id), "wrongly tracked");
            // send a sell order
            ot.GotOrder(new SellLimit(sym, 100, 100, id++));
            // verify order is there
            Assert.IsTrue(ot.SentOrder(id - 1).isValid, "no valid order");
            // verify size/pending/cancel
            Assert.AreEqual(-100, ot.Sent(id - 1), "not sent");
            Assert.AreEqual(0, ot.Filled(id - 1), "incorrect fill size");
            Assert.IsFalse(ot.isCompleted(id - 1), "completed but not filled");
            Assert.IsFalse(ot.isCanceled(id - 1), "wrongly canceled");
            Assert.IsTrue(ot.isPending(id - 1), "not pending");
            Assert.IsTrue(ot.isTracked(id - 1), "not tracked");
        }
Example #8
0
        public OrdersPanel()
        {
            var panel = new QDockPanel();

            Content = panel;
            Loaded += initialize;

            systemBox = new QComboBox(onSystemSelected);
            pvBox     = new QComboBox(onPvSelected);
            marketBox = new QComboBox(onMarketSelected);
            filterBox = new QComboBox("ALL", onFilterSelected, O.list("Not Ferret", "Ferret"));
            panel.add(comboBoxPanel(), Dock.Top);
            panel.add(new FerretPanel(), Dock.Bottom);
            orderGrid = new QDataTableGrid(loadOrderRow, unloadOrderRow);
            panel.add(orderGrid);

            LogC.info("starting order tracker");
            orderTracker = new OrderTracker(this);
        }
Example #9
0
        /// <summary>
        /// Sends the pending order information messages.
        /// </summary>
        /// <param name="quantfunds"></param>
        /// <param name="ordertracker"></param>
        /// <param name="portfolioid"></param>
        public void SendPendingOrderInfoMessages(IQuantFund[] quantfunds, OrderTracker ordertracker, string portfolioid)
        {
            if (!IsRunning || !HasSubscribers)
            {
                return;
            }

            ordertracker.PendingOrders.ForEach(p =>
            {
                var quantfund = quantfunds.FirstOrDefault(x => x.FundId == p.FundId);
                if (quantfund != null)
                {
                    Enqueue(PendingOrderInfoMessage.Generate(p, quantfund.Portfolio.Id, quantfund.Name));
                }
                else
                {
                    Enqueue(PendingOrderInfoMessage.Generate(p, portfolioid, string.Empty));
                }
            });
        }
Example #10
0
        public OrderAndPositionViewModel()
        {
            _eventaggregator = ServiceLocator.Current.GetInstance <EventAggregator>();
            _logger          = ServiceLocator.Current.GetInstance <ILoggerFacade>();
            _configmanager   = ServiceLocator.Current.GetInstance <IConfigManager>() as ConfigManager;

            _ordertracker = new OrderTracker(_configmanager.DailyOrderCapacity);
            _ordertracker.SendDebugEvent += OnDebug;
            _positiontracker              = new PositionTracker(_configmanager.DailyOrderCapacity);

            _eventaggregator.GetEvent <InitialPositionEvent>().Subscribe(ClientGotInitialPosition);
            //_eventaggregator.GetEvent<SendOrderEvent>().Subscribe(ClientGotOrder);
            _eventaggregator.GetEvent <OrderConfirmationEvent>().Subscribe(ClientGotOrder);
            _eventaggregator.GetEvent <OrderCancelConfirmationEvent>().Subscribe(ClientGotOrderCancelConfirmation);
            _eventaggregator.GetEvent <OrderFillEvent>().Subscribe(ClientGotOrderFilled);
            _eventaggregator.GetEvent <GenerateReportEvent>().Subscribe(GeneratePerformanceReport);

            _resultstable.Columns.Add("Statistics");
            _resultstable.Columns.Add("Result");
        }
Example #11
0
        public IActionResult SaveTracker(OrderTracker order)
        {
            try
            {
                int orders = _orderTrackerRepository.InsertOrder(order);
                if (orders <= 0)
                {
                    return(new NotFoundObjectResult(order));
                }

                return(new OkObjectResult(orders));
            }
            catch (ArgumentException ex)
            {
                return(Content(HttpStatusCode.BadRequest.ToString(), ex.Message));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex.Message));
            }
        }
        public override void Reset(bool popup = true)
        {
            _positiontracker           = new PositionTracker(_symbols.Count);
            _barlisttracker            = new BarListTracker(_symbols.ToArray(), new int[] { _higherbarinterval, _lowerbarinterval });
            _barlisttracker.GotNewBar += _barlisttracker_GotNewBar;
            _ordertracker              = new OrderTracker(10000);

            // in the none zone
            _isOBOSZone = Enumerable.Repeat <OBOSZone>(OBOSZone.None, _symbols.Count).ToArray();
            // neither bull or bear
            _isHigherTimeFrameBullBear = Enumerable.Repeat <BullBearTrend>(BullBearTrend.None, _symbols.Count).ToArray();
            // all are active
            _issymbolactive = Enumerable.Repeat <bool>(true, _symbols.Count).ToArray();
            // none are filled
            _waittobefilled = Enumerable.Repeat <bool>(false, _symbols.Count).ToArray();

            _currentorderids = Enumerable.Repeat <long>(0L, _symbols.Count).ToArray();
            _entrylevel      = Enumerable.Repeat <decimal>(0m, _symbols.Count).ToArray();
            _exitlevel       = Enumerable.Repeat <decimal>(0m, _symbols.Count).ToArray();

            _transactions = 0;
            _currenttime  = 0;
        }
Example #13
0
 public void Awake()
 {
     OrderTracker = GameObject.Find("OrderTracker").GetComponent <OrderTracker>();
 }
Example #14
0
        public override void OnInspectorGUI()
        {
            if (contentEnableMaskRect2D == null)
            {
                contentEnableMaskRect2D   = new GUIContent(" Clipped (MaskRect2D)", EditorGUIUtility.FindTexture("testpassed"), "The Renderer will be clipped by MaskRect2D.");
                contentDisableMaskRect2D  = new GUIContent(" Clipped (MaskRect2D)", EditorGUIUtility.FindTexture("console.warnicon.sml"), "Required '_ClipRect_n' properties in shader.\nRequired RectTransform component.");
                contentEnableCanvasGroup  = new GUIContent(" Modified Alpha (CanvasGroup)", EditorGUIUtility.FindTexture("testpassed"), "The Renderer will be modified alpha by CanvasGroup.");
                contentDisableCanvasGroup = new GUIContent(" Modified Alpha (CanvasGroup)", EditorGUIUtility.FindTexture("console.warnicon.sml"), "Required '_Alpha' property in shader.");
            }


            OrderTracker current = target as OrderTracker;
            bool         isAutoOrderedByParent = current.parent && current.parent.childOrderInterval != 0;

            serializedObject.Update();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_IgnoreParentTracker"));

            GUILayout.Space(EditorGUIUtility.singleLineHeight);
            EditorGUILayout.LabelField("Sorting Tracking", EditorStyles.boldLabel);
            using (new EditorGUI.DisabledGroupScope(isAutoOrderedByParent))
            {
                if (current.parent)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("m_AddSortingOrder"), new GUIContent("Sorting Order"));
                }
                else
                {
                    var spSortingLayer = serializedObject.FindProperty("m_SortingLayerID");
                    SortingLayerField(new GUIContent(spSortingLayer.displayName), spSortingLayer, EditorStyles.popup, EditorStyles.label);
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("m_AddSortingOrder"));
                }
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ChildOrderInterval"));
            //		DrawDefaultInspector();
            serializedObject.ApplyModifiedProperties();

            //using (new EditorGUI.DisabledGroupScope(true))
            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                int indentLevel = EditorGUI.indentLevel;
                if (current.parent)
                {
                    OrderTrackerField(current.parent);
                    EditorGUI.indentLevel++;
                }

                OrderTrackerField(current);
                EditorGUI.indentLevel++;

                foreach (var child in current.children.OrderBy(x => x.addSortingOrder))
                {
                    OrderTrackerField(child);
                }

                EditorGUI.indentLevel = indentLevel;
            }


            // Draw rendering options.
            if (current.cachedRenderer)
            {
                GUILayout.Space(EditorGUIUtility.singleLineHeight);
                EditorGUILayout.LabelField("Rendering Options", EditorStyles.boldLabel);
                using (new EditorGUILayout.VerticalScope("helpbox"))
                {
                    GUILayout.Label(current.isClippable ? contentEnableMaskRect2D : contentDisableMaskRect2D);
                    GUILayout.Label(current.isTransparent ? contentEnableCanvasGroup : contentDisableCanvasGroup);
                }
            }
        }
 private void Awake()
 {
     Store        = GetComponent <GameDataStore>();
     OrderTracker = GameObject.Find("OrderTracker").GetComponent <OrderTracker>();
     LevelLoader  = GameObject.Find("LevelChanger").GetComponent <LevelChanger>();
 }