Exemple #1
0
        public IHttpActionResult PostMasterInstrument(MasterInstrument masterInstrument)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.MasterInstruments.Add(masterInstrument);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (MasterInstrumentExists(masterInstrument.DividendID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = masterInstrument.DividendID }, masterInstrument));
        }
Exemple #2
0
        public double GetTickValue()
        {
            MasterInstrument maIns = Bars.Instrument.MasterInstrument;

            //Print("TickSize, name, pointvalue=" + maIns.TickSize + "," + maIns.Name + "," + maIns.PointValue);
            return(maIns.TickSize * maIns.PointValue);
        }
Exemple #3
0
        public IHttpActionResult PutMasterInstrument(int id, MasterInstrument masterInstrument)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != masterInstrument.DividendID)
            {
                return(BadRequest());
            }

            db.Entry(masterInstrument).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MasterInstrumentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #4
0
        protected override sealed void OnBarUpdate()
        {
            GomOnBarUpdate();

            if (BarsInProgress == 0)
            {
                if (Historical)
                {
                    MasterInstrument MI = Bars.Instrument.MasterInstrument;
                    if ((Bars.FirstBarOfSession || (BarsPeriod.Id == PeriodType.Day)) && (MI.InstrumentType == InstrumentType.Future) && (MI.MergePolicy != MergePolicy.DoNotMerge) && !writeData && !Bars.Instrument.FullName.Contains("##-##"))
                    {
                        RolloverContract();
                    }

                    OnBarUpdateHistorical();
                }

                else
                {
                    if (dataManagerNotDisposedOf)
                    {
                        if (!writeData)
                        {
                            fm.Dispose();
                            fm = null;
                            dataManagerNotDisposedOf = false;
                        }
                    }

                    OnBarUpdateRealTime();
                }

                GomOnBarUpdateDone();
            }
        }
Exemple #5
0
        private void RolloverContract()
        {
            string instrname;

            bool rollover = false;

            DateTime zonedate = TimeZoneInfo.ConvertTime(Time[0], Bars.Session.TimeZoneInfo);

            MasterInstrument MI = Bars.Instrument.MasterInstrument;

            IEnumerable <RollOver> ROCollection = MI.RollOverCollection.Cast <RollOver>();

            DateTime cm = ROCollection.Where(x => x.Date <= zonedate.Date).OrderByDescending(x => x.Date).First().ContractMonth;

            if (cm != curcm)
            {
                rollover = true;
                curcm    = cm;
            }

            if (rollover)
            {
                priceoffset = 0.0f;
                if (MI.MergePolicy == MergePolicy.MergeBackAdjusted)
                {
                    priceoffset = ROCollection.Where(x => (x.ContractMonth > cm) && (x.ContractMonth <= Instrument.Expiry) && !(double.IsNaN(x.Offset))).Sum(x => x.Offset);
                }

                foundbarinfile = false;
                EOFfound       = false;

                instrname = MI.Name + " " + cm.Month.ToString("D2") + "-" + (cm.Year % 100).ToString("D2");
                fm.Initialize(instrname, writeData, this);
            }
        }
        protected override sealed void OnBarUpdate()
        {
            GomOnBarUpdate();

            if (BarsInProgress == 0)
            {
                if (Historical)
                {
                    MasterInstrument MI = Bars.Instrument.MasterInstrument;
                    if ((Bars.FirstBarOfSession || (BarsPeriod.Id == PeriodType.Day)) && (MI.InstrumentType == InstrumentType.Future) && (MI.MergePolicy != MergePolicy.DoNotMerge) && !writeData)
                    {
                        RolloverContract();
                    }

                    OnBarUpdateHistorical();
                }

                else
                {
                    OnBarUpdateRealTime();
                }

                GomOnBarUpdateDone();
            }
        }
Exemple #7
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (tv1.SelectedNode == null)
            {
                return;
            }
            try
            {
                if (tv1.SelectedNode.Level == 1)
                {
                    string md = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\NinjaTrader 8\\db\\replay\\";
                    string fn = md + tv1.SelectedNode.Parent.Text + "\\" + tv1.SelectedNode.Text + ".nrd";
                    if (File.Exists(fn))
                    {
                        button3.Enabled = false;
                        string[]         s      = tv1.SelectedNode.Parent.Text.Split(' ');
                        string           MIname = s[0];
                        MI               tmp    = lstMaster.First(i => i.Name == MIname);
                        MasterInstrument mi     = new MasterInstrument();
                        mi.Name           = tmp.Name;
                        mi.InstrumentType = tmp.Type;
                        mi.TickSize       = tmp.TickSize;
                        DateTime exp   = new DateTime(2099, 12, 12);
                        int      month = 12;
                        int      year  = 0;
                        if (s.Length == 2)
                        {
                            month = Convert.ToInt16(s[1].Split('-')[0]);
                            year  = 2000 + Convert.ToInt16(s[1].Split('-')[1]);
                            exp   = new DateTime(year, month, 15);
                        }

                        Instrument instrument = new Instrument
                        {
                            Exchange         = Exchange.Default,
                            Expiry           = exp,
                            MasterInstrument = mi,
                        };
                        DateTime dt = new DateTime(Convert.ToInt16(tv1.SelectedNode.Text.Substring(0, 4)),
                                                   Convert.ToInt16(tv1.SelectedNode.Text.Substring(4, 2)),
                                                   Convert.ToInt16(tv1.SelectedNode.Text.Substring(6, 2)));
                        if (!Directory.Exists("CONVERTED\\" + tv1.SelectedNode.Parent.Text + "\\"))
                        {
                            Directory.CreateDirectory("CONVERTED\\" + tv1.SelectedNode.Parent.Text + "\\");
                        }
                        MarketReplay.DumpMarketDepth(instrument,
                                                     dt.AddDays(1), dt.AddDays(1),
                                                     "CONVERTED\\" + tv1.SelectedNode.Parent.Text + "\\" + tv1.SelectedNode.Text + ".txt");
                        button3.Enabled = true;
                        MessageBox.Show("Сonversion completed");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error" + Environment.NewLine + ex.Message);
                button3.Enabled = true;
            }
        }
Exemple #8
0
        public IHttpActionResult GetMasterInstrument(int id)
        {
            MasterInstrument masterInstrument = db.MasterInstruments.Find(id);

            if (masterInstrument == null)
            {
                return(NotFound());
            }

            return(Ok(masterInstrument));
        }
Exemple #9
0
        public double GetAvgPrice()
        {
            MasterInstrument maIns = Bars.Instrument.MasterInstrument;

            if (IsLiveTrading())
            {
                return(maIns.RoundToTickSize(PositionAccount.AveragePrice));
            }
            else
            {
                return(maIns.RoundToTickSize(Position.AveragePrice));
            }
        }
Exemple #10
0
        public IHttpActionResult DeleteMasterInstrument(int id)
        {
            MasterInstrument masterInstrument = db.MasterInstruments.Find(id);

            if (masterInstrument == null)
            {
                return(NotFound());
            }

            db.MasterInstruments.Remove(masterInstrument);
            db.SaveChanges();

            return(Ok(masterInstrument));
        }
        private void RolloverContract()
        {
            string instrname;

            bool rollover = false;

            DateTime zonedate = TimeZoneInfo.ConvertTime(Time[0], Bars.Session.TimeZoneInfo);

            DateTime cm = new DateTime(0L);

            MasterInstrument MI = Bars.Instrument.MasterInstrument;

            DateTime dt = new DateTime(0L);

            foreach (RollOver RO in MI.RollOverCollection)
            {
                if ((zonedate.Date >= RO.Date) && (RO.Date > dt))
                {
                    dt = RO.Date;
                    cm = RO.ContractMonth;
                }
            }

            if (cm != curcm)
            {
                rollover = true;
                curcm    = cm;
            }

            if (rollover)
            {
                priceoffset = 0.0f;
                if (MI.MergePolicy == MergePolicy.MergeBackAdjusted)
                {
                    foreach (RollOver RO in MI.RollOverCollection)
                    {
                        if ((RO.ContractMonth > cm) && (RO.ContractMonth <= Instrument.Expiry) && !(double.IsNaN(RO.Offset)))
                        {
                            priceoffset += RO.Offset;
                        }
                    }
                }

                foundbarinfile = false;
                EOFfound       = false;

                instrname = MI.Name + " " + cm.Month.ToString("D2") + "-" + cm.Year % 100;
                fm.Initialize(instrname, writeData, this);
            }
        }
Exemple #12
0
    // Use this for initialization
    void Start()
    {
        //If you are not the graph receiver, then you
        //are an instrument (AAJ)
        if(GetComponent<GraphReceiver>() == null){

            //Sets this instance of ApplyEdit as an instrument (AAJ)
            isInstrument = true;
        }//if

        //Finds the tracing manager (AAJ)
        tracingManager = GameObject.FindGameObjectWithTag("Trace");

        //Gets the components of the tracing screen (AAJ)
        tracingScript = tracingManager.GetComponent<TracingScript>();
        tracingScreen = tracingScript.tracingScreen;
        tracingGraph = tracingScript.tracingGraph;

        //Finds the master instrument (AAJ)
        masterInstrument = GameObject.FindGameObjectWithTag("Master").GetComponent<MasterInstrument>();
    }
Exemple #13
0
        /* Steps:
         *	1. Project start/end points for rays and extended lines
         *	2. Find collitions with ChartPanel for TextBox coordinates
         *	3. Determine price to be appended
         *	4. Create message
         *	5. Draw TextBox
         */

        public override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            base.OnRender(chartControl, chartScale);

            Stroke.RenderTarget        = RenderTarget;
            OutlineStroke.RenderTarget = RenderTarget;

            bool             snap           = true;
            bool             startsOnScreen = true;
            bool             priceOffScreen = false;
            double           priceToUse     = 0;
            string           pricetime      = String.Empty;
            string           TextToDisplay  = DisplayText;
            MasterInstrument masterInst     = GetAttachedToChartBars().Bars.Instrument.MasterInstrument;

            Point startPoint = StartAnchor.GetPoint(chartControl, ChartPanel, chartScale);
            Point endPoint   = EndAnchor.GetPoint(chartControl, ChartPanel, chartScale);

            double strokePixAdj   = ((double)(Stroke.Width % 2)).ApproxCompare(0) == 0 ? 0.5d : 0d;
            Vector pixelAdjustVec = new Vector(strokePixAdj, strokePixAdj);

            Point startAdj = (LineType == ChartLineType.HorizontalLine ? new Point(ChartPanel.X, startPoint.Y) : new Point(startPoint.X, ChartPanel.Y)) + pixelAdjustVec;
            Point endAdj   = (LineType == ChartLineType.HorizontalLine ? new Point(ChartPanel.X + ChartPanel.W, startPoint.Y) : new Point(startPoint.X, ChartPanel.Y + ChartPanel.H)) + pixelAdjustVec;

            Vector distVec  = Vector.Divide(Point.Subtract(endPoint, startPoint), 100);
            Vector scalVec  = (LineType == ChartLineType.ExtendedLine || LineType == ChartLineType.Ray || LineType == ChartLineType.HorizontalLine) ? Vector.Multiply(distVec, 10000) : Vector.Multiply(distVec, 100);
            Point  extPoint = Vector.Add(scalVec, startPoint);

            // Project extended line start point if it is off screen
            if (LineType == ChartLineType.ExtendedLine && TextDisplayMode != TextMode.EndPoint)
            {
                startPoint = Point.Subtract(startPoint, scalVec);
            }

            // Project TextBox coordinate for extended lines and rays to get ChartPanel bounds
            if (LineType == ChartLineType.ExtendedLine || LineType == ChartLineType.Ray)
            {
                extPoint = Vector.Add(scalVec, extPoint);
            }

            // Find collisions with ChartPanel bounds for PriceScale bound TextBox coordinates
            if (LineType == ChartLineType.HorizontalLine || LineType == ChartLineType.VerticalLine)
            {
                extPoint   = endAdj;
                startPoint = startAdj;
            }
            else if (TextDisplayMode == TextMode.EndPoint)
            {
                extPoint = endPoint;
                snap     = false;
            }
            else
            {
                if (extPoint.X <= ChartPanel.X || extPoint.Y < ChartPanel.Y || extPoint.X > ChartPanel.W || extPoint.Y > ChartPanel.H)
                {
                    switch (LineIntersectsRect(startPoint, extPoint, new SharpDX.RectangleF(ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H)))
                    {
                    case RectSide.Top:
                        extPoint = FindIntersection(startPoint, extPoint, new Point(ChartPanel.X, ChartPanel.Y), new Point(ChartPanel.W, ChartPanel.Y));
                        break;

                    case RectSide.Bottom:
                        extPoint = FindIntersection(startPoint, extPoint, new Point(ChartPanel.W, ChartPanel.H), new Point(ChartPanel.X, ChartPanel.H));
                        break;

                    case RectSide.Left:
                        extPoint = FindIntersection(startPoint, extPoint, new Point(ChartPanel.X, ChartPanel.H), new Point(ChartPanel.X, ChartPanel.Y));
                        break;

                    case RectSide.Right:
                        extPoint = FindIntersection(startPoint, extPoint, new Point(ChartPanel.W, ChartPanel.Y), new Point(ChartPanel.W, ChartPanel.H));
                        break;

                    default:
                        return;
                    }
                }

                if (startPoint.X <= ChartPanel.X || startPoint.Y < ChartPanel.Y || startPoint.X > ChartPanel.W || startPoint.Y > ChartPanel.H)
                {
                    switch (LineIntersectsRect(extPoint, startPoint, new SharpDX.RectangleF(ChartPanel.X, ChartPanel.Y, ChartPanel.W, ChartPanel.H)))
                    {
                    case RectSide.Top:
                        startPoint = FindIntersection(extPoint, startPoint, new Point(ChartPanel.X, ChartPanel.Y), new Point(ChartPanel.W, ChartPanel.Y));
                        break;

                    case RectSide.Bottom:
                        startPoint = FindIntersection(extPoint, startPoint, new Point(ChartPanel.W, ChartPanel.H), new Point(ChartPanel.X, ChartPanel.H));
                        break;

                    case RectSide.Left:
                        startPoint = FindIntersection(extPoint, startPoint, new Point(ChartPanel.X, ChartPanel.H), new Point(ChartPanel.X, ChartPanel.Y));
                        break;

                    case RectSide.Right:
                        startPoint = FindIntersection(extPoint, startPoint, new Point(ChartPanel.W, ChartPanel.Y), new Point(ChartPanel.W, ChartPanel.H));
                        break;

                    default:
                        return;
                    }
                }

                if (endPoint.X <= ChartPanel.X || endPoint.Y < ChartPanel.Y || endPoint.X > ChartPanel.W || endPoint.Y > ChartPanel.H)
                {
                    priceOffScreen = true;
                }
            }

            // Scale coordinates by HorizontalOffset/VerticalOffset
            distVec     = Point.Subtract(extPoint, startPoint);
            scalVec     = Vector.Multiply(Vector.Divide(distVec, 100), HorizontalOffset);
            extPoint    = Point.Subtract(extPoint, scalVec);
            extPoint.Y -= VerticalOffset;

            // Get a Price or a Timestamp to append to the label
            switch (LineType)
            {
            case ChartLineType.VerticalLine:
                pricetime = StartAnchor.Time.ToString();
                break;

            case ChartLineType.HorizontalLine:
                priceToUse = StartAnchor.Price;
                break;

            case ChartLineType.ExtendedLine:
            case ChartLineType.Ray:
                priceToUse = TextDisplayMode == TextMode.PriceScale
                                                           ? chartScale.GetValueByY(endPoint.X >= startPoint.X
                                                                                                                ? (float)FindIntersection(startPoint, endPoint, new Point(ChartPanel.W, ChartPanel.Y), new Point(ChartPanel.W, ChartPanel.H)).Y
                                                                                                                : (float)FindIntersection(startPoint, endPoint, new Point(ChartPanel.X, ChartPanel.Y), new Point(ChartPanel.X, ChartPanel.H)).Y)
                                                           : EndAnchor.Price;
                break;

            default:
                priceToUse = priceOffScreen && TextDisplayMode == TextMode.PriceScale
                                                           ? chartScale.GetValueByY(endPoint.X >= startPoint.X
                                                                                                                ? (float)FindIntersection(startPoint, endPoint, new Point(ChartPanel.W, ChartPanel.Y), new Point(ChartPanel.W, ChartPanel.H)).Y
                                                                                                                : (float)FindIntersection(startPoint, endPoint, new Point(ChartPanel.X, ChartPanel.Y), new Point(ChartPanel.X, ChartPanel.H)).Y)
                                                           : EndAnchor.Price;
                break;
            }

            // Round the price
            if (LineType != ChartLineType.VerticalLine)
            {
                pricetime = priceToUse <= masterInst.RoundDownToTickSize(priceToUse) + masterInst.TickSize * 0.5
                                                        ? pricetime = masterInst.RoundDownToTickSize(priceToUse).ToString("0.00")
                                                        : pricetime = masterInst.RoundToTickSize(priceToUse).ToString("0.00");
            }

            // Check if we need to append price or time
            if (AppendPriceTime && DisplayText.Length > 0)
            {
                TextToDisplay = String.Format("{0} {1}", DisplayText, pricetime);
            }
            else if (AppendPriceTime)
            {
                TextToDisplay = pricetime;
            }

            // Use Label Font if one is not specified by template
            if (Font == null)
            {
                Font = new NinjaTrader.Gui.Tools.SimpleFont(chartControl.Properties.LabelFont.Family.ToString(), 16);
            }

            // Update DX Brushes
            if (offScreenDXBrushNeedsUpdate)
            {
                offScreenDXBrush.Dispose();
                offScreenDXBrush            = offScreenMediaBrush.ToDxBrush(RenderTarget);
                offScreenDXBrushNeedsUpdate = false;
            }

            if (backgroundDXBrushNeedsUpdate)
            {
                backgroundDXBrush.Dispose();
                backgroundDXBrush            = backgroundMediaBrush.ToDxBrush(RenderTarget);
                backgroundDXBrush.Opacity    = (float)AreaOpacity / 100f;
                backgroundDXBrushNeedsUpdate = false;
            }

            // Draw TextBoxes
            switch (LineType)
            {
            case ChartLineType.VerticalLine:
                DrawTextBox(snap, TextToDisplay, extPoint.X, extPoint.Y, Stroke.BrushDX, backgroundDXBrush, OutlineStroke, 1.5708f);
                break;

            case ChartLineType.HorizontalLine:
                DrawTextBox(snap, TextToDisplay, extPoint.X, extPoint.Y, Stroke.BrushDX, backgroundDXBrush, OutlineStroke, 0);
                break;

            default:
                DrawTextBox(snap, TextToDisplay, extPoint.X, extPoint.Y, priceOffScreen && TextDisplayMode == TextMode.EndPointAtPriceScale ? offScreenDXBrush : Stroke.BrushDX, backgroundDXBrush, OutlineStroke, 0);
                break;
            }
        }
Exemple #14
0
        public double GetTypicalPrice(int barsAgo)
        {
            MasterInstrument maIns = Bars.Instrument.MasterInstrument;

            return(maIns.RoundToTickSize(Typical[barsAgo]));
        }
        private static UpdateDefinition <Market> createMarketUpdateDefinition(Market market, MasterInstrument instrument)
        {
            UpdateDefinition <Market> definition = null;

            if (market.Currency == null || !market.Currency.Equals(instrument.Currency.ToString()))
            {
                definition = Definitions <Market> .setUpdateDefinition(definition, Market.Field.CURRENCY.ToString(), instrument.Currency.ToString());
            }

            if (market.Description == null || !market.Description.Equals(instrument.Description))
            {
                definition = Definitions <Market> .setUpdateDefinition(definition, Market.Field.DESCRIPTION.ToString(), instrument.Description);
            }

            if (market.Type == null || !market.Type.Equals(instrument.InstrumentType.ToString()))
            {
                definition = Definitions <Market> .setUpdateDefinition(definition, Market.Field.TYPE.ToString(), instrument.InstrumentType.ToString());
            }

            if (market.TickSize != instrument.TickSize)
            {
                definition = Definitions <Market> .setUpdateDefinition(definition, Market.Field.TICK_SIZE.ToString(), instrument.TickSize);
            }

            if (market.PointValue != instrument.PointValue)
            {
                definition = Definitions <Market> .setUpdateDefinition(definition, Market.Field.POINT_VALUE.ToString(), instrument.PointValue);
            }

            if (market.Url == null || !market.Url.Equals(instrument.Url.ToString()))
            {
                definition = Definitions <Market> .setUpdateDefinition(definition, Market.Field.URL.ToString(), instrument.Url.ToString());
            }
            return(definition);
        }