public void Load_Listed_Instrument_Transaction() { var effectiveDate = new DateTimeOffset(2018, 1, 1, 0, 0, 0, TimeSpan.Zero); // create the portfolio var portfolioCode = _testDataUtilities.CreateTransactionPortfolio(TestDataUtilities.TutorialScope); // create the transaction request var transaction = new TransactionRequest( // unique transaction id transactionId: Guid.NewGuid().ToString(), // instruments must already exist in LUSID and have a valid LUSID instrument id instrumentIdentifiers: new Dictionary <string, string> { [TestDataUtilities.LusidInstrumentIdentifier] = _instrumentIds[0] }, type: "Buy", totalConsideration: new CurrencyAndAmount(1230, "GBP"), transactionDate: effectiveDate, settlementDate: effectiveDate, units: 100, transactionPrice: new TransactionPrice(12.3), source: "Custodian"); // add the transaction _transactionPortfoliosApi.UpsertTransactions(TestDataUtilities.TutorialScope, portfolioCode, new List <TransactionRequest> { transaction }); // get the transaction var transactions = _transactionPortfoliosApi.GetTransactions(TestDataUtilities.TutorialScope, portfolioCode); Assert.That(transactions.Values, Has.Count.EqualTo(1)); Assert.That(transactions.Values[0].TransactionId, Is.EqualTo(transaction.TransactionId)); }
/// <summary> /// This method add instruments to a portfolio (specified by its scope and code), /// by creating a transaction request with the instrument's LUID. /// </summary> private void AddInstrumentsTransactionToPortfolio( List <string> luids, string portfolioScope, string portfolioCode, DateTimeOffset effectiveAt) { // CREATE instrument transaction request var transactionRequests = luids.Select(luid => BuildTransactionRequest(luid, 1, null, "USD", effectiveAt, "StockIn")) .ToList(); // UPSERT instruments to portfolio _transactionPortfoliosApi.UpsertTransactions(portfolioScope, portfolioCode, transactionRequests); }
public void Get_Holdings() { // The currency of the cash and transactions const string currency = "GBP"; // The dates for which transactions are added to the portfolio. All dates/times // must be supplied in UTC var dayT1 = new DateTimeOffset(2018, 1, 1, 0, 0, 0, TimeSpan.Zero); var dayTPlus5 = new DateTimeOffset(2018, 1, 5, 0, 0, 0, TimeSpan.Zero); var dayTPlus10 = new DateTimeOffset(2018, 1, 10, 0, 0, 0, TimeSpan.Zero); // Create a portfolio var portfolioId = _testDataUtilities.CreateTransactionPortfolio(TestDataUtilities.TutorialScope); // The list of transactions to add to LUSID var transactions = new List <TransactionRequest>(); // Add the starting cash position transactions.Add(_testDataUtilities.BuildCashFundsInTransactionRequest(100000, currency, dayT1)); // Add initial transactions on dayT1 transactions.Add(_testDataUtilities.BuildTransactionRequest(_instrumentIds[0], 100.0M, 101.0M, currency, dayT1, "Buy")); transactions.Add(_testDataUtilities.BuildTransactionRequest(_instrumentIds[1], 100.0M, 102.0M, currency, dayT1, "Buy")); transactions.Add(_testDataUtilities.BuildTransactionRequest(_instrumentIds[2], 100.0M, 103.0M, currency, dayT1, "Buy")); // On T+5, add a transaction in another instrument and another to increase the amount of instrument 1 transactions.Add(_testDataUtilities.BuildTransactionRequest(_instrumentIds[1], 100.0M, 104.0M, currency, dayTPlus5, "Buy")); transactions.Add(_testDataUtilities.BuildTransactionRequest(_instrumentIds[3], 100.0M, 105.0M, currency, dayTPlus5, "Buy")); // Upload the transactions to LUSID _transactionPortfoliosApi.UpsertTransactions(TestDataUtilities.TutorialScope, portfolioId, transactions); // Get the portfolio holdings on T+10 var holdings = _transactionPortfoliosApi.GetHoldings(TestDataUtilities.TutorialScope, portfolioId, effectiveAt: dayTPlus10); // Ensure we have 5 holdings: 1 cash position and a position in 4 instruments that aggregates the 5 transactions Assert.That(holdings.Values.Count(), Is.EqualTo(5)); holdings.Values.Sort((h1, h2) => String.Compare(h1.InstrumentUid, h2.InstrumentUid, StringComparison.Ordinal)); // Check the cash balance Assert.That(holdings.Values[0].InstrumentUid, Is.EqualTo($"CCY_{currency}")); // Validate we have the correct instruments Assert.That(holdings.Values[1].InstrumentUid, Is.EqualTo(_instrumentIds[0])); Assert.That(holdings.Values[2].InstrumentUid, Is.EqualTo(_instrumentIds[1])); Assert.That(holdings.Values[3].InstrumentUid, Is.EqualTo(_instrumentIds[2])); Assert.That(holdings.Values[4].InstrumentUid, Is.EqualTo(_instrumentIds[3])); // Validate the holdings Assert.That(holdings.Values[0].HoldingType, Is.EqualTo("B")); // B = Balance Assert.That(holdings.Values[1].HoldingType, Is.EqualTo("P")); Assert.That(holdings.Values[1].Units, Is.EqualTo(100.0)); Assert.That(holdings.Values[1].Cost.Amount, Is.EqualTo(10100.0)); Assert.That(holdings.Values[2].HoldingType, Is.EqualTo("P")); Assert.That(holdings.Values[2].Units, Is.EqualTo(200.0)); Assert.That(holdings.Values[2].Cost.Amount, Is.EqualTo(20600.0)); Assert.That(holdings.Values[3].HoldingType, Is.EqualTo("P")); Assert.That(holdings.Values[3].Units, Is.EqualTo(100.0)); Assert.That(holdings.Values[3].Cost.Amount, Is.EqualTo(10300.0)); Assert.That(holdings.Values[4].HoldingType, Is.EqualTo("P")); Assert.That(holdings.Values[4].Units, Is.EqualTo(100.0)); Assert.That(holdings.Values[4].Cost.Amount, Is.EqualTo(10500.0)); }