Exemplo n.º 1
0
 public void Add(Fill fill)
 {
     Fills.Add(fill);
     Qty        += fill.Qty;
     Commission += fill.Commission;
     Price       = Fills.Sum(f => f.Qty * f.Price) / Qty;
 }
Exemplo n.º 2
0
 private void AddDefaultStyles()
 {
     Fonts.Add(new Font("Calibri", size: 11));
     Fills.Add(new Fill(new PatternFill(FillPattern.None, null, null), null));
     Fills.Add(new Fill(new PatternFill(FillPattern.Gray125, null, null), null));
     Borders.Add(new Border());
     CellFormats.Add(new CellFormat(null, 0, 0, 0, 0));
 }
Exemplo n.º 3
0
        public override void Initialize(LinkedNavigationEvent linkedNavigationEvent)
        {
            var fills = IoC.Get <IBacktestRepository>().GetBacktestFills(linkedNavigationEvent.Key);

            Fills.Clear();
            foreach (var fill in fills)
            {
                Fills.Add(fill);
            }

            FillView = CollectionViewSource.GetDefaultView(Fills);
            base.Initialize(linkedNavigationEvent);
        }
Exemplo n.º 4
0
        public uint Add(Fill fill)
        {
            if (fill == null)
            {
                throw new ArgumentNullException(nameof(fill));
            }

            var i = Fills.IndexOf(fill);

            if (i < 0)
            {
                i = Fills.Count;
                Fills.Add(fill);
            }

            return((uint)i);
        }
Exemplo n.º 5
0
        // TODO: rewrite it
        internal void OnFill(Fill fill, bool queued = true)
        {
            Fills.Add(fill);
            this.framework.EventServer.OnFill(this, fill, queued);
            var  instrument = fill.Instrument;
            bool flag       = false;
            var  position   = PositionsByInstrumentId[instrument.Id] ?? GetOrCreatePosition(instrument);

            if (position.Amount == 0)
            {
                flag = true;
            }

            position.Add(fill);
            Account.Add(fill, false);
            if (flag)
            {
                Statistics.OnPositionChanged(position);
                this.framework.EventServer.OnPositionChanged(this, position, queued);
                Statistics.OnPositionOpened(position);
                this.framework.EventServer.OnPositionOpened(this, position, queued);
            }
            else
            {
                if (fill.Qty > position.Qty && position.Amount != 0.0 && ((fill.Side == OrderSide.Buy && position.Side == PositionSide.Long) || (fill.Side == OrderSide.Sell && position.Side == PositionSide.Short)))
                {
                    Statistics.OnPositionSideChanged(position);
                }
                if (position.Amount != 0.0)
                {
                    Statistics.OnPositionChanged(position);
                }
                this.framework.EventServer.OnPositionChanged(this, position, queued);
                if (position.Amount == 0.0)
                {
                    Statistics.OnPositionClosed(position);
                    this.framework.EventServer.OnPositionClosed(this, position, queued);
                }
            }
            if (UpdateParent)
            {
                Parent?.OnFill(fill, queued);
            }
            Statistics.OnFill(fill);
        }
Exemplo n.º 6
0
        public void Add(Fill fill)
        {
            Fills.Add(fill);
            if (Amount == 0)
            {
                this.fill = fill;
            }

            if (fill.Side == OrderSide.Buy)
            {
                QtyBought += fill.Qty;
            }
            else
            {
                QtySold += fill.Qty;
            }

            this.method_0(fill);
            Amount = QtyBought - QtySold;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Сохраняет свою сделку.
        /// </summary>
        /// <param name="fill">Данные своей сделки.</param>
        protected void AddFill(FillMessage fill)
        {
            if (!storeFillsInMemory)
            {
                return;
            }

            if (!IsPermittedAccount(fill.Account))
            {
                return;
            }

            using (SyncRoot.Lock())
            {
                Dictionary <Instrument, List <FillMessage> > accountFills;

                if (!AvailableAccounts.Contains(fill.Account))
                {
                    AvailableAccounts.Add(fill.Account);
                    accountFills = new Dictionary <Instrument, List <FillMessage> >();
                    Fills.Add(fill.Account, accountFills);
                }
                else
                {
                    accountFills = Fills[fill.Account];
                }

                List <FillMessage> instrumentFills;

                if (!accountFills.TryGetValue(fill.Instrument, out instrumentFills))
                {
                    instrumentFills = new List <FillMessage>();
                    accountFills.Add(fill.Instrument, instrumentFills);
                }

                instrumentFills.Add(fill);
            }
        }
Exemplo n.º 8
0
        protected bool AddAccount(string account)
        {
            if (string.IsNullOrWhiteSpace(account))
            {
                return(false);
            }

            if (!IsPermittedAccount(account))
            {
                return(false);
            }

            using (SyncRoot.Lock())
            {
                if (AvailableAccounts.Contains(account))
                {
                    return(false);
                }

                AvailableAccounts.Add(account);
                Fills.Add(account, new Dictionary <Instrument, List <FillMessage> >());
                return(true);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Loads the style XML to memory
        /// </summary>
        private void LoadFromDocument()
        {
            //NumberFormats
            ExcelNumberFormatXml.AddBuildIn(NameSpaceManager, NumberFormats);
            XmlNode numNode = _styleXml.SelectSingleNode(NumberFormatsPath, _nameSpaceManager);

            if (numNode != null)
            {
                foreach (XmlNode n in numNode)
                {
                    ExcelNumberFormatXml nf = new ExcelNumberFormatXml(_nameSpaceManager, n);
                    NumberFormats.Add(nf.Id, nf);
                    if (nf.NumFmtId >= NumberFormats.NextId)
                    {
                        NumberFormats.NextId = nf.NumFmtId + 1;
                    }
                }
            }

            //Fonts
            XmlNode fontNode = _styleXml.SelectSingleNode(FontsPath, _nameSpaceManager);

            foreach (XmlNode n in fontNode)
            {
                ExcelFontXml f = new ExcelFontXml(_nameSpaceManager, n);
                Fonts.Add(f.Id, f);
            }

            //Fills
            XmlNode fillNode = _styleXml.SelectSingleNode(FillsPath, _nameSpaceManager);

            foreach (XmlNode n in fillNode)
            {
                ExcelFillXml f;
                if (n.FirstChild != null && n.FirstChild.LocalName == "gradientFill")
                {
                    f = new ExcelGradientFillXml(_nameSpaceManager, n);
                }
                else
                {
                    f = new ExcelFillXml(_nameSpaceManager, n);
                }
                Fills.Add(f.Id, f);
            }

            //Borders
            XmlNode borderNode = _styleXml.SelectSingleNode(BordersPath, _nameSpaceManager);

            foreach (XmlNode n in borderNode)
            {
                ExcelBorderXml b = new ExcelBorderXml(_nameSpaceManager, n);
                Borders.Add(b.Id, b);
            }

            //cellStyleXfs
            XmlNode styleXfsNode = _styleXml.SelectSingleNode(CellStyleXfsPath, _nameSpaceManager);

            if (styleXfsNode != null)
            {
                foreach (XmlNode n in styleXfsNode)
                {
                    ExcelXfs item = new ExcelXfs(_nameSpaceManager, n, this);
                    CellStyleXfs.Add(item.Id, item);
                }
            }

            XmlNode styleNode = _styleXml.SelectSingleNode(CellXfsPath, _nameSpaceManager);

            for (int i = 0; i < styleNode.ChildNodes.Count; i++)
            {
                XmlNode  n    = styleNode.ChildNodes[i];
                ExcelXfs item = new ExcelXfs(_nameSpaceManager, n, this);
                CellXfs.Add(item.Id, item);
            }

            //cellStyle
            XmlNode namedStyleNode = _styleXml.SelectSingleNode(CellStylesPath, _nameSpaceManager);

            if (namedStyleNode != null)
            {
                foreach (XmlNode n in namedStyleNode)
                {
                    ExcelNamedStyleXml item = new ExcelNamedStyleXml(_nameSpaceManager, n, this);
                    NamedStyles.Add(item.Name, item);
                }
            }

            //dxfsPath
            XmlNode dxfsNode = _styleXml.SelectSingleNode(dxfsPath, _nameSpaceManager);

            if (dxfsNode != null)
            {
                foreach (XmlNode x in dxfsNode)
                {
                    ExcelDxfStyleConditionalFormatting item = new ExcelDxfStyleConditionalFormatting(_nameSpaceManager, x, this);
                    Dxfs.Add(item.Id, item);
                }
            }
        }
Exemplo n.º 10
0
 protected override void AddTrade(TradeEvent tradeEvent)
 {
     Fills.Add(tradeEvent.Fill);
 }
Exemplo n.º 11
0
 public void AddFill(DarkLightFill fill)
 {
     Fills.Add(MockUtilities.GenerateFills("backtestidToImplement", 1)[0]);
 }