예제 #1
0
		internal Portfolio(SmartQuant.Instruments.Portfolio portfolio)
		{
			this.portfolio = portfolio;
			this.positions = new PositionList(portfolio.Positions);
			this.transactions = new TransactionList(portfolio.Transactions);
			this.account = new PortfolioAccount(portfolio.Account);
		}
예제 #2
0
 private void AddAccountData(SmartQuant.AccountData data)
 {
     int key = (int)data.ProviderId * 256 + (int)data.Route;
     AccountDataViewer accountDataViewer;
     if (!this.viewers.TryGetValue(key, out accountDataViewer))
     {
         accountDataViewer = new AccountDataViewer();
         accountDataViewer.Dock = DockStyle.Fill;
         this.viewers.Add(key, accountDataViewer);
         TabPage tabPage = new TabPage();
         try
         {
             if ((int)data.ProviderId == (int)data.Route)
                 tabPage.Text = string.Format("{0}", (object)this.framework.ProviderManager.GetProvider((int)data.ProviderId).Name);
             else
                 tabPage.Text = string.Format("{0} ({1})", (object)this.framework.ProviderManager.GetProvider((int)data.ProviderId).Name, (object)this.framework.ProviderManager.GetProvider((int)data.Route).Name);
         }
         catch (Exception ex)
         {
             tabPage.Text = ex.Message;
         }
         tabPage.Controls.Add((Control)accountDataViewer);
         this.tabViewers.TabPages.Add(tabPage);
     }
     accountDataViewer.OnData(data);
 }
예제 #3
0
        public ExecutionReport CreateReport(
            OrderRecord record,
            SQ.ExecType? execType,
            SQ.OrderStatus? orderStatus)
        {
            ExecutionReport report = new ExecutionReport();

            report.DateTime = framework.Clock.DateTime;

            report.Order = record.Order;
            report.Instrument = record.Order.Instrument;
            
            report.Side = record.Order.Side;
            report.OrdType = record.Order.Type;
            report.TimeInForce = record.Order.TimeInForce;

            report.OrdQty = record.Order.Qty;
            report.Price = record.Order.Price;
            report.StopPx = record.Order.StopPx;

            report.AvgPx = record.AvgPx;
            report.CumQty = record.CumQty;
            report.LeavesQty = record.LeavesQty;

            if (execType != null)
                report.ExecType = execType.Value;

            if (orderStatus != null)
                report.OrdStatus = orderStatus.Value;

            return report;
        }
예제 #4
0
 public ChildrenStatisticsViewItem(SmartQuant.Portfolio portfolio)
   : base(new string[8])
 {
     this.Portfolio = portfolio;
     this.SubItems[0].Text = this.Portfolio.Name;
     this.UseItemStyleForSubItems = false;
     this.Update();
 }
		public SmartQuant.Data.Bar FilterBarOpen(SmartQuant.Data.Bar bar, string symbol)
		{
			Bar bar2 = this.oqFilter.FilterBarOpen(new Bar(bar), symbol);
			if (bar2 != null)
			{
				return bar2.bar;
			}
			return null;
		}
		public SmartQuant.Data.Trade FilterTrade(SmartQuant.Data.Trade trade, string symbol)
		{
			Trade trade2 = this.oqFilter.FilterTrade(new Trade(trade), symbol);
			if (trade2 == null)
			{
				return null;
			}
			return trade2.trade;
		}
		public SmartQuant.Data.Quote FilterQuote(SmartQuant.Data.Quote quote, string symbol)
		{
			Quote quote2 = this.oqFilter.FilterQuote(new Quote(quote), symbol);
			if (quote2 == null)
			{
				return null;
			}
			return quote2.quote;
		}
예제 #8
0
 public DataSeriesViewItem(DataSeries dataSeries, byte dataType, SmartQuant.BarType? barType = null, long? barSize = null)
   : base(new string[4], 0)
 {
   this.dataSeries = dataSeries;
   this.DataType = dataType;
   this.BarType = barType;
   this.BarSize = barSize;
   this.Update();
 }
		internal BrokerPositionFieldList(SmartQuant.Providers.BrokerPositionField[] fields)
		{
			this.fields = fields;
			this.table = new Dictionary<string, SmartQuant.Providers.BrokerPositionField>();
			for (int i = 0; i < fields.Length; i++)
			{
				SmartQuant.Providers.BrokerPositionField brokerPositionField = fields[i];
				this.table.Add(brokerPositionField.Name, brokerPositionField);
			}
		}
예제 #10
0
 private void AddPortfolio(SmartQuant.Portfolio portfolio)
 {
   if (this.nodes.ContainsKey(portfolio.Name))
     return;
   PortfolioNode portfolioNode = new PortfolioNode(portfolio.Name);
   this.nodes[portfolio.Name] = portfolioNode;
   if (portfolio.Parent == null)
     this.trvPortfolios.Nodes.Add((TreeNode) portfolioNode);
   else
     this.nodes[portfolio.Parent.Name].Nodes.Add((TreeNode) portfolioNode);
 }
예제 #11
0
 protected override void OnInit(SmartQuant.DataObject dataObject, int decimalPlaces)
 {
   if (dataObject != null)
   {
     Quote quote = (Quote) dataObject;
     this.nudBid.Value = (Decimal) quote.Bid.Price;
     this.nudBidSize.Value = (Decimal) quote.Bid.Size;
     this.nudAsk.Value = (Decimal) quote.Ask.Price;
     this.nudAskSize.Value = (Decimal) quote.Ask.Size;
   }
   this.nudBid.DecimalPlaces = decimalPlaces;
   this.nudAsk.DecimalPlaces = decimalPlaces;
 }
		internal BrokerAccountFieldList(SmartQuant.Providers.BrokerAccountField[] fields)
		{
			this.fields = fields;
			this.table = new Dictionary<string, Dictionary<string, SmartQuant.Providers.BrokerAccountField>>();
			for (int i = 0; i < fields.Length; i++)
			{
				SmartQuant.Providers.BrokerAccountField brokerAccountField = fields[i];
				Dictionary<string, SmartQuant.Providers.BrokerAccountField> dictionary;
				if (!this.table.TryGetValue(brokerAccountField.Name, out dictionary))
				{
					dictionary = new Dictionary<string, SmartQuant.Providers.BrokerAccountField>();
					this.table.Add(brokerAccountField.Name, dictionary);
				}
				dictionary.Add(brokerAccountField.Currency, brokerAccountField);
			}
		}
        //public double FixPrice(double price, SmartQuant.OrderSide Side, double tickSize, double LowerLimitPrice, double UpperLimitPrice)
        //{
        //    //没有设置就直接用
        //    if (tickSize > 0)
        //    {
        //        decimal remainder = ((decimal)price % (decimal)tickSize);
        //        if (remainder != 0)
        //        {
        //            if (Side == SmartQuant.OrderSide.Buy)
        //            {
        //                price = Math.Round(Math.Ceiling(price / tickSize) * tickSize, 6);
        //            }
        //            else
        //            {
        //                price = Math.Round(Math.Floor(price / tickSize) * tickSize, 6);
        //            }
        //        }
        //        else
        //        {
        //            //正好能整除,不操作
        //        }
        //    }

        //    if (0 == UpperLimitPrice
        //        && 0 == LowerLimitPrice)
        //    {
        //        //涨跌停无效
                
        //    }
        //    else
        //    {
        //        //防止价格超过涨跌停
        //        if (price >= UpperLimitPrice)
        //            price = UpperLimitPrice;
        //        else if (price <= LowerLimitPrice)
        //            price = LowerLimitPrice;
        //    }
        //    return price;
        //}

        public double FixPrice(MarketDataRecord record,double price, SmartQuant.OrderSide Side, double tickSize)
        {
            double LowerLimitPrice = record.DepthMarket.LowerLimitPrice;
            double UpperLimitPrice = record.DepthMarket.UpperLimitPrice;

            //没有设置就直接用
            if (tickSize > 0)
            {
                decimal remainder = ((decimal)price % (decimal)tickSize);
                if (remainder != 0)
                {
                    if (Side == SmartQuant.OrderSide.Buy)
                    {
                        price = Math.Round(Math.Ceiling(price / tickSize) * tickSize, 6);
                    }
                    else
                    {
                        price = Math.Round(Math.Floor(price / tickSize) * tickSize, 6);
                    }
                }
                else
                {
                    //正好能整除,不操作
                }
            }

            if (0 == UpperLimitPrice
                && 0 == LowerLimitPrice)
            {
                //涨跌停无效
                _TdApi.Log.Warn("Symbol:{0},Symbol_Dot_Exchange:{1},LowerLimitPrice && UpperLimitPrice 为0,没有进行价格修正",
                    record.Symbol,record.Symbol_Dot_Exchange);
            }
            else
            {
                //防止价格超过涨跌停
                if (price >= UpperLimitPrice)
                    price = UpperLimitPrice;
                else if (price <= LowerLimitPrice)
                    price = LowerLimitPrice;
            }
            return price;
        }
예제 #14
0
 protected override void OnInit(SmartQuant.DataObject dataObject, int decimalPlaces)
 {
   if (dataObject != null)
   {
     Bar bar = (Bar) dataObject;
     this.dtpDateTime.Value = bar.OpenDateTime;
     this.dtpEnd.Value = bar.CloseDateTime;
     this.nudOpen.Value = (Decimal) bar.Open;
     this.nudHigh.Value = (Decimal) bar.High;
     this.nudLow.Value = (Decimal) bar.Low;
     this.nudClose.Value = (Decimal) bar.Close;
     this.nudVolume.Value = (Decimal) bar.Volume;
     this.nudOpenInt.Value = (Decimal) bar.OpenInt;
     this.dtpDateTime.Enabled = false;
     this.dtpEnd.Enabled = false;
   }
   else
   {
     DateTime now = DateTime.Now;
     this.dtpDateTime.Value = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
     this.dtpDateTime.Enabled = true;
     if (this.barType == BarType.Time)
     {
       this.dtpEnd.Value = this.dtpDateTime.Value.AddSeconds((double) this.barSize);
       this.dtpEnd.Enabled = false;
     }
     else
     {
       this.dtpEnd.Value = this.dtpDateTime.Value;
       this.dtpEnd.Enabled = true;
     }
   }
   this.tbxBarType.Text = string.Format("{0} {1}", (object) this.barType, (object) this.barSize);
   this.nudOpen.DecimalPlaces = decimalPlaces;
   this.nudHigh.DecimalPlaces = decimalPlaces;
   this.nudLow.DecimalPlaces = decimalPlaces;
   this.nudClose.DecimalPlaces = decimalPlaces;
 }
예제 #15
0
 public void OnData(SmartQuant.AccountData data)
 {
     if (!this.cbxAccount.Items.Contains((object)data.Account))
     {
         this.cbxAccount.Items.Add((object)data.Account);
         this.accounts.Add(data.Account, new Dictionary<string, ListViewItem>());
         this.positions.Add(data.Account, new Dictionary<string, ListViewItem>());
         this.orders.Add(data.Account, new Dictionary<string, ListViewItem>());
         if (this.cbxAccount.SelectedIndex < 0)
             this.cbxAccount.SelectedIndex = 0;
     }
     switch (data.Type)
     {
         case AccountDataType.AccountValue:
             this.AddValue(data);
             break;
         case AccountDataType.Position:
             this.AddPosition(data);
             break;
         case AccountDataType.Order:
             this.AddOrder(data);
             break;
     }
 }
예제 #16
0
		internal Statistics(SmartQuant.Instruments.Portfolio portfolio)
		{
			this.portfolio = portfolio;
		}
예제 #17
0
		internal BrokerAccountField(SmartQuant.Providers.BrokerAccountField field)
		{
			this.field = field;
		}
예제 #18
0
		internal Transaction(SmartQuant.Instruments.Transaction transaction)
		{
			this.transaction = transaction;
		}
예제 #19
0
 public DataTypeItem(byte dataType, SmartQuant.BarType? barType = null, long? barSize = null)
 {
   this.DataType = dataType;
   this.BarType = barType;
   this.BarSize = barSize;
 }
예제 #20
0
 private void UpdateSubItem(ListViewItem item, int index, SmartQuant.AccountData data, string name)
 {
     object obj = data.Fields[name];
     if (obj == null)
         return;
     item.SubItems[index].Text = obj.ToString();
 }
예제 #21
0
 public OrderKey(SmartQuant.AccountData data) : base(data)
 {
     this.key = GetFieldAsString("OrderID");
 }
예제 #22
0
 private void AddPosition(SmartQuant.AccountData data)
 {
     Dictionary<string, ListViewItem> dictionary = this.positions[data.Account];
     string key = new PositionKey(data).ToString();
     ListViewItem listViewItem = (ListViewItem)null;
     if (!dictionary.TryGetValue(key, out listViewItem))
     {
         listViewItem = new ListViewItem(new string[4]);
         listViewItem.Name = key;
         listViewItem.SubItems[0].Text = key;
         dictionary.Add(key, listViewItem);
     }
     this.UpdateSubItem(listViewItem, 1, data, "Qty");
     this.UpdateSubItem(listViewItem, 2, data, "LongQty");
     this.UpdateSubItem(listViewItem, 3, data, "ShortQty");
     if (!(data.Account == this.cbxAccount.SelectedItem as string))
         return;
     this.UpdateListView(data.Account, AccountDataViewer.ListType.Positions);
 }
예제 #23
0
 private void AddOrder(SmartQuant.AccountData data)
 {
     Dictionary<string, ListViewItem> dictionary = this.orders[data.Account];
     string key = new OrderKey(data).ToString();
     ListViewItem listViewItem = (ListViewItem)null;
     if (!dictionary.TryGetValue(key, out listViewItem))
     {
         listViewItem = new ListViewItem(new string[8]);
         listViewItem.Name = key;
         listViewItem.SubItems[0].Text = key;
         dictionary.Add(key, listViewItem);
     }
     this.UpdateSubItem(listViewItem, 1, data, "Symbol");
     this.UpdateSubItem(listViewItem, 2, data, "OrderSide");
     this.UpdateSubItem(listViewItem, 3, data, "OrderType");
     this.UpdateSubItem(listViewItem, 4, data, "Qty");
     this.UpdateSubItem(listViewItem, 5, data, "Price");
     this.UpdateSubItem(listViewItem, 6, data, "StopPx");
     this.UpdateSubItem(listViewItem, 7, data, "OrderStatus");
     if (!(data.Account == this.cbxAccount.SelectedItem as string))
         return;
     this.UpdateListView(data.Account, AccountDataViewer.ListType.Orders);
 }
예제 #24
0
 private void AddValue(SmartQuant.AccountData data)
 {
     Dictionary<string, ListViewItem> dictionary = this.accounts[data.Account];
     foreach (AccountDataField accountDataField in data.Fields)
     {
         string key = string.Format("{0}:{1}", (object)accountDataField.Name, (object)accountDataField.Currency);
         ListViewItem listViewItem = (ListViewItem)null;
         if (!dictionary.TryGetValue(key, out listViewItem))
         {
             listViewItem = new ListViewItem(new string[3]);
             listViewItem.Name = key;
             listViewItem.SubItems[0].Text = accountDataField.Name;
             listViewItem.SubItems[1].Text = accountDataField.Currency;
             dictionary.Add(key, listViewItem);
         }
         listViewItem.SubItems[2].Text = this.ValueToString(accountDataField.Value);
     }
     if (!(data.Account == this.cbxAccount.SelectedItem as string))
         return;
     this.UpdateListView(data.Account, AccountDataViewer.ListType.Accounts);
 }
예제 #25
0
 public PositionKey(SmartQuant.AccountData data) : base(data)
 {
     this.key = $"{GetFieldAsString("Symbol")} {GetFieldAsString("Maturity")} {GetFieldAsString("PutOrCall")} {GetFieldAsString("Strike")}";
 }
예제 #26
0
 private void RemovePortfolio(SmartQuant.Portfolio portfolio)
 {
   this.nodes[portfolio.Name].Remove();
   this.nodes.Remove(portfolio.Name);
 }
예제 #27
0
		internal static StopType Convert(SmartQuant.Trading.StopType stopType)
		{
			switch (stopType)
			{
			case SmartQuant.Trading.StopType.Fixed:
				return StopType.Fixed;
			case SmartQuant.Trading.StopType.Trailing:
				return StopType.Trailing;
			case SmartQuant.Trading.StopType.Time:
				return StopType.Time;
			default:
				throw new NotImplementedException("Stop type is not supported : " + stopType);
			}
		}
예제 #28
0
 private void ChangeParent(SmartQuant.Portfolio portfolio)
 {
   if (!this.nodes.ContainsKey(portfolio.Name))
     return;
   PortfolioNode portfolioNode = this.nodes[portfolio.Name];
   portfolioNode.Remove();
   this.nodes[portfolio.Parent.Name].Nodes.Add((TreeNode) portfolioNode);
 }
예제 #29
0
		internal static StopMode Convert(SmartQuant.Trading.StopMode stopMode)
		{
			switch (stopMode)
			{
			case SmartQuant.Trading.StopMode.Absolute:
				return StopMode.Absolute;
			case SmartQuant.Trading.StopMode.Percent:
				return StopMode.Percent;
			default:
				throw new NotImplementedException("Stop mode is not supported : " + stopMode);
			}
		}
예제 #30
0
		internal static StopStatus Convert(SmartQuant.Trading.StopStatus stopStatus)
		{
			switch (stopStatus)
			{
			case SmartQuant.Trading.StopStatus.Active:
				return StopStatus.Active;
			case SmartQuant.Trading.StopStatus.Executed:
				return StopStatus.Executed;
			case SmartQuant.Trading.StopStatus.Canceled:
				return StopStatus.Canceled;
			default:
				throw new NotImplementedException("Stop status is not supported : " + stopStatus);
			}
		}