diff --git a/SDK quick start guides/LUSID SDK quick start.ipynb b/SDK quick start guides/LUSID SDK quick start.ipynb new file mode 100644 index 00000000..bbbeca7c --- /dev/null +++ b/SDK quick start guides/LUSID SDK quick start.ipynb @@ -0,0 +1,144 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "fd20963f-95b3-42f8-a6c6-495c7f3b3c7c", + "metadata": {}, + "source": [ + "# Quick start: Using the LUSID SDK\n", + "This quick start guide will show how to connect to LUSID, create and retrieve a portfolio.\n", + "You can use the LUSID SDK to make requests against LUSID on your local machine, or in our hosted Jupyter environment." + ] + }, + { + "cell_type": "markdown", + "id": "f0e90cf2-dd74-4e33-a1d6-970ed3384ee5", + "metadata": {}, + "source": [ + "## Running outside of the FINBOURNE hosted Jupyter environment\n", + "\n", + "You'll need to set the appropriate environment variables to connect to LUSID.\n", + "\n", + "In this quick start guide we use a long-lived [Personal Access Token](https://support.lusid.com/knowledgebase/article/KA-01774) and [API URL](https://support.lusid.com/knowledgebase/article/KA-01787/en-us)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "975c759f-6574-4708-8ec2-dff1df286528", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.environ[\"FBN_LUSID_API_URL\"] = \"https://example.lusid.com/api\"\n", + "os.environ[\"FBN_ACCESS_TOKEN\"] = \"VGhpcyBpcyBhbiBleGFtcGxlIHRva2VuLg==\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1af6cacb-7899-4202-8811-d4508fb8164a", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "import lusid\n", + "api_client_factory = lusid.ApiClientFactory()" + ] + }, + { + "cell_type": "markdown", + "id": "b61681fe-8d7c-4966-8560-c37686e82ecb", + "metadata": {}, + "source": [ + "## Running in the FINBOURNE hosted Jupyter environment\n", + "\n", + "Please ensure you are logged into LUSID in a separate tab in your browser session. We'll use the lusidjam library which is provided in our hosted Jupyter environment to provide an up-to-date short lived access token." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7bf54479-cfc4-41e2-b0ca-9438ca8ca020", + "metadata": {}, + "outputs": [], + "source": [ + "import lusidjam\n", + "config_loaders = (lusid.ArgsConfigurationLoader(access_token = lusidjam.RefreshingToken()), lusid.EnvironmentVariablesConfigurationLoader())\n", + "api_client_factory = lusid.ApiClientFactory(config_loaders=config_loaders)" + ] + }, + { + "cell_type": "markdown", + "id": "c1539bfe-b362-4b93-bdeb-0242ecbcb448", + "metadata": {}, + "source": [ + "## Making your first request to LUSID.\n", + "\n", + "We'll build some API objects using our configured `ApiClientFactory` object." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c824987f-d3dc-493a-9e54-cc7786669cca", + "metadata": {}, + "outputs": [], + "source": [ + "transaction_portfolios_api = api_client_factory.build(lusid.TransactionPortfoliosApi)\n", + "portfolios_api = api_client_factory.build(lusid.PortfoliosApi)" + ] + }, + { + "cell_type": "markdown", + "id": "ad451178-635d-4b75-8579-2eca359bf87a", + "metadata": {}, + "source": [ + "We can use the `TransactionPortfoliosApi` object to create a transaction portfolio, and the `PortfoliosApi` object to get that portfolio.\n", + "\n", + "Here we create a portfolio called \"example_portfolio\", and retrieve information about that portfolio" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "be94b058-7fc1-4be1-bcb2-aeecf8c808c9", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "from pprint import pprint\n", + "async with api_client_factory:\n", + " try:\n", + " create_transaction_portfolio_request = lusid.CreateTransactionPortfolioRequest(display_name=\"example_portfolio\", code=\"example_code\", base_currency=\"GBP\")\n", + " result = await transaction_portfolios_api.create_portfolio(scope=\"example\", create_transaction_portfolio_request=create_transaction_portfolio_request)\n", + " portfolio = await portfolios_api.get_portfolio(scope=\"example\", code=\"example_code\")\n", + " pprint(portfolio)\n", + " except Exception as e:\n", + " pprint(json.loads(e.body))" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python (SDK v2)", + "language": "python", + "name": "v2sdkenv" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}