From 6d6369010c6b7392ce2cdb2bfec68080fc6ecdb1 Mon Sep 17 00:00:00 2001 From: Adam Massoud Date: Fri, 19 Jan 2024 11:33:46 +0000 Subject: [PATCH 1/2] CTECH-3419: Remove incorrect commentary on Endpoint support and installing packages concurrently. Remove note about examples (until we've got these tested with v2) Update code to use correct extensions and awaits Point to correct repo for generation --- README.md | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index b4c73c840dc..eb5b2b443a7 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,9 @@ The PyPi package for the LUSID SDK can installed using the following: pip install lusid-sdk ``` -We publish two versions of the Python SDK: - -* **lusid-sdk-python (this one) - supports `Production` and `Early Access` API endpoints** -* [lusid-sdk-python-preview](https://github.com/finbourne/lusid-sdk-python-preview) - supports `Production`, `Early Access`, `Beta` and `Experimental` API endpoints. - For more details on API endpoint categories, see [What is the LUSID feature release lifecycle?](https://support.lusid.com/knowledgebase/article/KA-01786/en-us). To find out which category an API endpoint falls into, see [LUSID API Documentation](https://www.lusid.com/api/swagger/index.html). -> If you install both `lusid-sdk-python` and `lusid-sdk-python-preview`, `import lusid` will refer to `lusid-sdk-python`. ## Usage @@ -31,18 +25,23 @@ First, import the following LUSID modules: ```python import lusid import lusid.models as models -from lusid.utilities import ApiConfigurationLoader +from lusid import ( + ApiClientFactory, + EnvironmentVariablesConfigurationLoader, + SecretsFileConfigurationLoader, + ArgsConfigurationLoader +) ``` And construct the API factory: ```python secrets_file_path = "/path/to/secrets.json" -config = ApiConfigurationLoader.load(secrets_file_path) -api_factory = lusid.utilities.ApiClientFactory( - token=lusid.utilities.RefreshingToken(config), - api_secrets_filename=secrets_file_path -) +config_loaders = [ + EnvironmentVariablesConfigurationLoader(), + SecretsFileConfigurationLoader(api_secrets_file=secrets_path) +] +api_client_factory = ApiClientFactory(config_loaders=config_loaders) ``` > You will need to create a secrets file containing your LUSID credentials. For instructions on how to construct this file, see [Getting started with the LUSID API and SDKs](https://support.lusid.com/knowledgebase/article/KA-01916/) @@ -68,7 +67,6 @@ import pytz The examples below should be run in order, as they assume that the preceding code has been executed. -> Sets of working examples for using this SDK are available in the [Python examples repo](https://github.com/finbourne/lusid-sdk-examples-python). #### Create portfolio @@ -82,10 +80,9 @@ portfolio_request = models.CreateTransactionPortfolioRequest( display_name=f"Portfolio-{guid}", code=f"Id-{guid}", base_currency="GBP", - created=datetime.datetime(2021, 3, 20, tzinfo=pytz.utc) + created=datetime.datetime(2021, 3, 20, tzinfo=pytz.utc).isoformat() ) - -portfolio = tx_portfolios_api.create_portfolio(scope, create_transaction_portfolio_request=portfolio_request) +portfolio = await tx_portfolios_api.create_portfolio(scope, create_transaction_portfolio_request=portfolio_request) portfolio_code = portfolio.id.code print("Porfolio Code:", portfolio_code) ``` @@ -102,13 +99,14 @@ figis_to_create = { ) } -instruments_api.upsert_instruments(request_body=figis_to_create) +await instruments_api.upsert_instruments(request_body=figis_to_create) + ``` #### Get instruments ```python -instruments_response = instruments_api.get_instruments( +instruments_response = await instruments_api.get_instruments( identifier_type="Figi", request_body=list(figis_to_create.keys())) name_to_luid = { value.name: value.lusid_instrument_id @@ -134,7 +132,7 @@ tx1 = models.TransactionRequest( source="Broker" ) -tx_portfolios_api.upsert_transactions(scope=scope, code=portfolio_code, transaction_request=[tx1]) +await tx_portfolios_api.upsert_transactions(scope=scope, code=portfolio_code, transaction_request=[tx1]) ``` #### Get holdings @@ -142,7 +140,7 @@ tx_portfolios_api.upsert_transactions(scope=scope, code=portfolio_code, transact ```python tx_portfolios_api = api_factory.build(lusid.api.TransactionPortfoliosApi) -holdings_response = tx_portfolios_api.get_holdings( +holdings_response = await tx_portfolios_api.get_holdings( scope=scope, code=portfolio_code, property_keys=["Instrument/default/Name"]).values print("Holdings:") @@ -150,14 +148,12 @@ for holding in holdings_response: print(luid_to_name[holding.instrument_uid], holding.units, holding.cost.amount) ``` -For more fully fledged examples showing how to use the SDK, see [sdk/tests/tutorials](sdk/tests/tutorials) - ## Manually building the SDK A pre-generated version of the latest SDK is included in the `sdk` folder. This is based on the [OpenAPI specification](https://github.com/OAI/OpenAPI-Specification) specification named `lusid.json` in the root folder. The most up to date version of the OpenAPI specification can be downloaded from [api.lusid.com/swagger/v0/swagger.json](https://api.lusid.com/swagger/v0/swagger.json). -If you want to generate the Python SDK locally from the FINBOURNE OpenAPI specification, see [github.com/finbourne/lusid-sdk-generators](https://github.com/finbourne/lusid-sdk-generators). +If you want to generate the Python SDK locally from the FINBOURNE OpenAPI specification, see [github.com/finbourne/lusid-sdk-generator-python](https://github.com/finbourne/lusid-sdk-generator-python). ## Build status From 77d9ac603250c7ca09f96e9065dc264bd3ece1c7 Mon Sep 17 00:00:00 2001 From: Adam Massoud <56272501+adamMQM@users.noreply.github.com> Date: Fri, 19 Jan 2024 11:49:22 +0000 Subject: [PATCH 2/2] remove secrets file specific config discussion Co-authored-by: Rizwan Saeed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb5b2b443a7..9d78ebc4bad 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ config_loaders = [ api_client_factory = ApiClientFactory(config_loaders=config_loaders) ``` -> You will need to create a secrets file containing your LUSID credentials. For instructions on how to construct this file, see [Getting started with the LUSID API and SDKs](https://support.lusid.com/knowledgebase/article/KA-01916/) +> Accessing the LUSID API endpoints requires an authenticated request. An authentication token can be obtained following the instructions [Getting started with the LUSID API and SDKs](https://support.lusid.com/knowledgebase/article/KA-01916/) Now that the API client is ready, you are ready to use the various API endpoints. You can list all the API endpoints by running the following: