private void EnsurePropertyDefinition(string code) { var propertyApi = _apiFactory.Api <IPropertyDefinitionsApi>(); try { propertyApi.GetPropertyDefinition("Instrument", TestDataUtilities.TutorialScope, code); } catch (ApiException) { // Property definition doesn't exist (returns 404), so create one // Details of the property to be created var propertyDefinition = new CreatePropertyDefinitionRequest( domain: CreatePropertyDefinitionRequest.DomainEnum.Instrument, scope: TestDataUtilities.TutorialScope, lifeTime: CreatePropertyDefinitionRequest.LifeTimeEnum.Perpetual, code: code, valueRequired: false, displayName: code, dataTypeId: new ResourceId("system", "string") ); // Create the property propertyApi.CreatePropertyDefinition(propertyDefinition); } }
public void Create_Transaction_Portfolio_With_Properties() { var uuid = Guid.NewGuid().ToString(); var propertyName = $"fund-style-{uuid}"; var dataTypeId = new ResourceId("system", "string"); // Property definition var propertyDefinition = new CreatePropertyDefinitionRequest( domain: CreatePropertyDefinitionRequest.DomainEnum.Portfolio, scope: TestDataUtilities.TutorialScope, code: propertyName, valueRequired: false, displayName: "Fund Style", dataTypeId: dataTypeId, lifeTime: CreatePropertyDefinitionRequest.LifeTimeEnum.Perpetual); // Create the property definition var propertyDefinitionResult = _apiFactory.Api <IPropertyDefinitionsApi>().CreatePropertyDefinition(propertyDefinition); // Property value var propertyValue = "Active"; var portfolioProperty = new Property( key: propertyDefinitionResult.Key, value: new PropertyValue(labelValue: propertyValue)); // Properties to add to portfolio on creation var properties = new Dictionary <String, Property> { [propertyDefinitionResult.Key] = portfolioProperty }; // Details of the portfolio to be created var request = new CreateTransactionPortfolioRequest( displayName: $"portfolio-{uuid}", code: $"id-{uuid}", baseCurrency: "GBP", // Set the property value when creating the portfolio properties: properties ); var portfolio = _apiFactory.Api <ITransactionPortfoliosApi>().CreatePortfolio( scope: TestDataUtilities.TutorialScope, createTransactionPortfolioRequest: request); var portfolioCode = portfolio.Id.Code; Assert.That(portfolioCode, Is.EqualTo(request.Code)); var portfolioProperties = _apiFactory.Api <IPortfoliosApi>().GetPortfolioProperties( scope: TestDataUtilities.TutorialScope, code: portfolioCode); Assert.That(portfolioProperties.Properties.Count, Is.EqualTo(1)); Assert.That(portfolioProperties.Properties[propertyDefinitionResult.Key].Value.LabelValue, Is.EqualTo(propertyValue)); }
public void Create_Transaction_Portfolio_With_Property() { var uuid = Guid.NewGuid().ToString(); var propertyName = $"fund-style-{uuid}"; var effectiveDate = new DateTimeOffset(2018, 1, 1, 0, 0, 0, TimeSpan.Zero); // Details of the property to be created var propertyDefinition = new CreatePropertyDefinitionRequest( // The domain the property is to be applied to domain: CreatePropertyDefinitionRequest.DomainEnum.Portfolio, // The scope the property will be created in scope: TestDataUtilities.TutorialScope, // When the property value is set it will be valid forever and cannot be changed. // Properties whose values can change over time should be created with LifeTimeEnum.TIMEVARIANT lifeTime: CreatePropertyDefinitionRequest.LifeTimeEnum.Perpetual, code: propertyName, valueRequired: false, displayName: "Fund Style", dataTypeId: new ResourceId("system", "string") ); // Create the property definition var propertyDefinitionResult = _apiFactory.Api <IPropertyDefinitionsApi>().CreatePropertyDefinition(propertyDefinition); // Create the property value var propertyValue = new PropertyValue(labelValue: "Active"); // Details of the new portfolio to be created, created here with the minimum set of mandatory fields var createPortfolioRequest = new CreateTransactionPortfolioRequest( code: $"id-{uuid}", displayName: $"Portfolio-{uuid}", baseCurrency: "GBP", created: effectiveDate, // Set the property value when creating the portfolio properties: new Dictionary <string, Property> { [propertyDefinitionResult.Key] = new Property( propertyDefinitionResult.Key, propertyValue) } ); // Create the portfolio var portfolioResult = _apiFactory.Api <ITransactionPortfoliosApi>().CreatePortfolio(TestDataUtilities.TutorialScope, createPortfolioRequest); Assert.That(portfolioResult.Id.Code, Is.EqualTo(createPortfolioRequest.Code)); var portfolioProperties = _apiFactory.Api <IPortfoliosApi>().GetPortfolioProperties(TestDataUtilities.TutorialScope, portfolioResult.Id.Code); Assert.That(portfolioProperties.Properties, Has.Count.EqualTo(1)); Assert.That(portfolioProperties.Properties[propertyDefinitionResult.Key].Value.LabelValue, Is.EqualTo("Active")); }
public void Create_Portfolio_With_Properties() { var uuid = Guid.NewGuid().ToString(); const string scope = "finbourne"; var propertyName = $"fund-style-{uuid}"; var propertyDefinition = new CreatePropertyDefinitionRequest { Domain = "Portfolio", Scope = scope, Code = propertyName, ValueRequired = false, DisplayName = "Fund Style", LifeTime = "Perpetual", DataTypeId = new ResourceId("default", "string") }; // create property definition var propertyDefinitionDto = _client.CreatePropertyDefinition(propertyDefinition); // create portfolio var request = new CreateTransactionPortfolioRequest($"Portfolio-{uuid}", $"id-{uuid}", baseCurrency: "GBP"); var portfolio = _client.CreatePortfolio(scope, request); Assert.That(portfolio?.DisplayName, Is.EqualTo(request.DisplayName)); // get portfolioId var portfolioId = portfolio?.Id.Code; Assert.That(portfolioId, Is.Not.Null, "portfolioId null"); const string propertyValue = "Active"; // add the portfolio property var properties = new Dictionary <string, PropertyValue> { [propertyDefinitionDto.Key] = new PropertyValue(propertyValue) }; var propertiesResult = _client.UpsertPortfolioProperties(scope, portfolioId, properties, portfolio?.Created); Assert.That(propertiesResult.OriginPortfolioId.Code, Is.EqualTo(request.Code), "unable to add properties"); Assert.That(propertiesResult.Properties[0].Value, Is.EqualTo(propertyValue)); }
public void Add_Transactions_To_Portfolio_With_Property() { var uuid = Guid.NewGuid().ToString(); var propertyName = $"fund-style-{uuid}"; var labelValue = "A Trader"; // Effective date of the trades. All dates/times must be supplied in UTC var effectiveDate = new DateTimeOffset(2018, 1, 1, 0, 0, 0, TimeSpan.Zero); // Details of the property to be created var propertyDefinition = new CreatePropertyDefinitionRequest( // The domain the property is to be applied to domain: CreatePropertyDefinitionRequest.DomainEnum.Transaction, // The scope the property will be created in scope: TestDataUtilities.TutorialScope, // When the property value is set it will be valid forever and cannot be changed. // Properties whose values can change over time should be created with LifeTimeEnum.TIMEVARIANT lifeTime: CreatePropertyDefinitionRequest.LifeTimeEnum.Perpetual, code: propertyName, valueRequired: false, displayName: "Trader Id", dataTypeId: new ResourceId("system", "string") ); // Create the property definition var propertyDefinitionResult = _apiFactory.Api <IPropertyDefinitionsApi>().CreatePropertyDefinition(propertyDefinition); // Create the property value var propertyValue = new PerpetualProperty(propertyDefinitionResult.Key, new PropertyValue(labelValue)); // Create a portfolio var portfolioId = _testDataUtilities.CreateTransactionPortfolio(TutorialScope); // Details of the transaction to be added var transaction = new TransactionRequest( // Unique transaction id transactionId: Guid.NewGuid().ToString(), // Transaction type, configured during system setup type: "Buy", // Instrument identifier for the trnasaction instrumentIdentifiers: new Dictionary <string, string> { ["Instrument/default/LusidInstrumentId"] = _instrumentIds.First() }, // The properties to be added to the transaction properties: new Dictionary <string, PerpetualProperty> { [propertyDefinitionResult.Key] = propertyValue }, transactionDate: effectiveDate, settlementDate: effectiveDate, units: 100, transactionPrice: new TransactionPrice(12.3M, TransactionPrice.TypeEnum.Price), totalConsideration: new CurrencyAndAmount(1230, "GBP"), source: "Custodian" ); // Add the transaction to the portfolio _apiFactory.Api <ITransactionPortfoliosApi>().UpsertTransactions(TutorialScope, portfolioId, new List <TransactionRequest> { transaction }); // Retrieve the transaction var transactions = _apiFactory.Api <ITransactionPortfoliosApi>().GetTransactions(TutorialScope, portfolioId); Assert.That(transactions.Values.Count, Is.EqualTo(1)); Assert.That(transactions.Values[0].InstrumentUid, Is.EqualTo(transaction.InstrumentIdentifiers.First().Value)); Assert.That(transactions.Values[0].Properties[propertyDefinitionResult.Key].Value.LabelValue, Is.EqualTo(labelValue)); }
public void Create_Portfolio_With_Metric_Property() { var uuid = Guid.NewGuid().ToString(); var metricPropertyName = $"fund-nav-{uuid}"; var effectiveDate = new DateTimeOffset(2018, 1, 1, 0, 0, 0, TimeSpan.Zero); // Details of the property to be created var metricPropertyDefinition = new CreatePropertyDefinitionRequest( // The domain the property is to be applied to domain: CreatePropertyDefinitionRequest.DomainEnum.Portfolio, // The scope the property will be created in scope: TestDataUtilities.TutorialScope, // When the property value is set it will be valid forever and cannot be changed. // Properties whose values can change over time should be created with LifeTimeEnum.TIMEVARIANT lifeTime: CreatePropertyDefinitionRequest.LifeTimeEnum.Perpetual, code: metricPropertyName, valueRequired: false, displayName: "Fund NAV", dataTypeId: new ResourceId("system", "currencyAndAmount") ); // Create the property definitions var metricPropertyDefinitionResult = _apiFactory.Api <IPropertyDefinitionsApi>().CreatePropertyDefinition(metricPropertyDefinition); // Create the property values var metricPropertyValueRequest = new PropertyValue(metricValue: new MetricValue(1100000, "GBP")); // Details of the new portfolio to be created, created here with the minimum set of mandatory fields var createPortfolioRequest = new CreateTransactionPortfolioRequest( code: $"id-{uuid}", displayName: $"Portfolio-{uuid}", baseCurrency: "GBP", created: effectiveDate, // Set the property value when creating the portfolio properties: new Dictionary <string, Property> { [metricPropertyDefinitionResult.Key] = new Property( metricPropertyDefinitionResult.Key, metricPropertyValueRequest) } ); // Create the portfolio var portfolioResult = _apiFactory.Api <ITransactionPortfoliosApi>().CreatePortfolio(TestDataUtilities.TutorialScope, createPortfolioRequest); Assert.That(portfolioResult.Id.Code, Is.EqualTo(createPortfolioRequest.Code)); var portfolioProperties = _apiFactory.Api <IPortfoliosApi>().GetPortfolioProperties(TestDataUtilities.TutorialScope, portfolioResult.Id.Code).Properties; Assert.That(portfolioProperties.Keys, Is.EquivalentTo(new [] { metricPropertyDefinitionResult.Key })); // metricProperty.Value is just the value from the metric property, metricProperty.Unit is the units var metricProperty = portfolioProperties[metricPropertyDefinitionResult.Key]; Assert.That(metricProperty.Value.MetricValue.Value, Is.EqualTo(metricPropertyValueRequest.MetricValue.Value)); Assert.That(metricProperty.Value.MetricValue.Unit, Is.EqualTo(metricPropertyValueRequest.MetricValue.Unit)); }
public void Create_Portfolio_With_MultiValue_Property() { var uuid = Guid.NewGuid().ToString(); var propertyName = $"managers-{uuid}"; var effectiveDate = new DateTimeOffset(2018, 1, 1, 0, 0, 0, TimeSpan.Zero); // Details of the property to be created var multiValuePropertyDefinition = new CreatePropertyDefinitionRequest( // The domain the property is to be applied to domain: CreatePropertyDefinitionRequest.DomainEnum.Portfolio, // The scope the property will be created in scope: TestDataUtilities.TutorialScope, // When the property value is set it will be valid forever and cannot be changed. // Properties whose values can change over time should be created with LifeTimeEnum.TIMEVARIANT lifeTime: CreatePropertyDefinitionRequest.LifeTimeEnum.Perpetual, // Multi-value properties have constraint style "Collection" constraintStyle: "Collection", code: propertyName, valueRequired: false, displayName: "Managers", dataTypeId: new ResourceId("system", "string") ); // Create the property definitions var propertyDefinitionResult = _apiFactory.Api <IPropertyDefinitionsApi>().CreatePropertyDefinition(multiValuePropertyDefinition); // Create the property values var propertyValue = CreateLabelSet("PortfolioManager1", "PortfolioManager2"); // Details of the new portfolio to be created, created here with the minimum set of mandatory fields var createPortfolioRequest = new CreateTransactionPortfolioRequest( code: $"id-{uuid}", displayName: $"Portfolio-{uuid}", baseCurrency: "GBP", created: effectiveDate ); // Create the portfolio var portfolioResult = _apiFactory.Api <ITransactionPortfoliosApi>().CreatePortfolio(TestDataUtilities.TutorialScope, createPortfolioRequest); Assert.That(portfolioResult.Id.Code, Is.EqualTo(createPortfolioRequest.Code)); var propertiesUpsertResult = _apiFactory.Api <IPortfoliosApi>().UpsertPortfolioProperties( TestDataUtilities.TutorialScope, portfolioResult.Id.Code, new Dictionary <string, Property> { [propertyDefinitionResult.Key] = new Property( propertyDefinitionResult.Key, propertyValue) } ); Assert.That(propertiesUpsertResult.Properties.Values.Single().Value.LabelValueSet, Is.EqualTo(propertyValue.LabelValueSet).Using(LabelValueSetEquality)); var portfolioProperties = _apiFactory.Api <IPortfoliosApi>().GetPortfolioProperties(TestDataUtilities.TutorialScope, portfolioResult.Id.Code).Properties; Assert.That(portfolioProperties.Keys, Is.EquivalentTo(new [] { propertyDefinitionResult.Key })); var returnedProperty = portfolioProperties[propertyDefinitionResult.Key]; Assert.That(returnedProperty.Value, Is.EqualTo(propertyValue).Using(PropertyValueEquality)); }
public void Create_Trade_With_Property() { var uuid = Guid.NewGuid().ToString(); const string scope = "finbourne"; var propertyName = $"traderId-{uuid}"; var propertyDefinition = new CreatePropertyDefinitionRequest { Domain = "Trade", Scope = scope, Code = propertyName, ValueRequired = false, DisplayName = "Trader Id", LifeTime = "Perpetual", DataTypeId = new ResourceId("default", "string") }; // create property definition var propertyDefinitionDto = _client.CreatePropertyDefinition(propertyDefinition); var effectiveDate = new DateTimeOffset(2018, 1, 1, 0, 0, 0, TimeSpan.Zero); // create portfolio var request = new CreateTransactionPortfolioRequest( $"Portfolio-{uuid}", $"id-{uuid}", baseCurrency: "GBP", created: effectiveDate ); var portfolio = _client.CreatePortfolio(scope, request); Assert.That(portfolio?.DisplayName, Is.EqualTo(request.DisplayName)); // get portfolioId var portfolioId = portfolio?.Id.Code; Assert.That(portfolioId, Is.Not.Null, "portfolioId null"); const string propertyValue = "A Trader"; // create the transactions var transaction = new TransactionRequest() { TransactionId = Guid.NewGuid().ToString(), Type = "Buy", InstrumentUid = _instrumentIds.First(), TransactionDate = effectiveDate, SettlementDate = effectiveDate, Units = 100, TransactionPrice = new TransactionPrice(12.3, "Price"), TotalConsideration = new CurrencyAndAmount(1230, "GBP"), Source = "Client", Properties = new Dictionary <string, PerpetualPropertyValue>() { [propertyDefinitionDto.Key] = new PerpetualPropertyValue(propertyValue) } }; // add the transaction _client.UpsertTransactions(scope, portfolioId, new List <TransactionRequest> { transaction }); // get the transactions var transactions = _client.GetTransactions(scope, portfolioId); Assert.That(transactions.Values.Count, Is.EqualTo(1)); Assert.That(transactions.Values[0].InstrumentUid, Is.EqualTo(transaction.InstrumentUid)); Assert.That(transactions.Values[0].Properties[0].Value, Is.EqualTo(propertyValue)); }