|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "tags": [] |
| 7 | + }, |
| 8 | + "source": [ |
| 9 | + "# Refinitiv API Library Credentials" |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": 1, |
| 15 | + "metadata": {}, |
| 16 | + "outputs": [], |
| 17 | + "source": [ |
| 18 | + "%config Completer.use_jedi = False" |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "## Set your app key and credentials" |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "code", |
| 30 | + "execution_count": 1, |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [], |
| 33 | + "source": [ |
| 34 | + "import configparser as cp\n", |
| 35 | + "config = cp.ConfigParser()\n", |
| 36 | + "config.read(\"c:/Refinitiv/config.cfg\")\n", |
| 37 | + "\n", |
| 38 | + "APP_KEY = config['platform']['app_key']\n", |
| 39 | + "RDP_LOGIN = config['platform']['user']\n", |
| 40 | + "RDP_LOGIN2 = config['platform2']['user']\n", |
| 41 | + "RDP_PASSWORD = config['platform']['password']\n", |
| 42 | + "DEPLOYED_PLATFORM_HOST = config['deployed']['host']\n", |
| 43 | + "DEPLOYED_PLATFORM_USER_NAME = config['deployed']['user']\n", |
| 44 | + "#APP_KEY = 'YOUR_APP_KEY'\n", |
| 45 | + "#RDP_LOGIN = 'YOUR_REFINITIV_DATA_PLATFORM_LOGIN'\n", |
| 46 | + "#RDP_PASSWORD = 'YOUR_REFINITIV_DATA_PLATFORM_PASSWORD'\n", |
| 47 | + "#DEPLOYED_PLATFORM_HOST = 'THE_HOST:PORT_OF_YOUR_DEPLOYED_PLATFORM' # ADS hostname:PORT or IP:PORT e.g. 'myADS:15000'\n", |
| 48 | + "#DEPLOYED_PLATFORM_USER_NAME = 'YOUR_USER_NAME_ON_YOUR_DEPLOYED_PLATFORM' # DACS user name " |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "cell_type": "markdown", |
| 53 | + "metadata": {}, |
| 54 | + "source": [ |
| 55 | + " " |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + "cell_type": "markdown", |
| 60 | + "metadata": {}, |
| 61 | + "source": [ |
| 62 | + "## Helper functions to define and open and close a session\n", |
| 63 | + "\n", |
| 64 | + "These function will be used by most of the other tutorials to reduce session related code replication.\n", |
| 65 | + "\n", |
| 66 | + "Set your default session_type below with **SESSION_TYPE** variable below - valid values are:\n", |
| 67 | + "- \"desktop\"\n", |
| 68 | + "- \"platform\"\n", |
| 69 | + "- \"deployed\" \n", |
| 70 | + "\n", |
| 71 | + "This will avoid the need to specif it in all the tutorials.\n", |
| 72 | + "\n", |
| 73 | + "If you want to override the default you can do so, by calling with the session type e.g. **open_session('desktop')**\n", |
| 74 | + "\n", |
| 75 | + "When you want to release the session, call **close_session()**.\n", |
| 76 | + "\n", |
| 77 | + "For further information on session types, refer to **1. Quick Start/1.0 - Sessions.ipynb**" |
| 78 | + ] |
| 79 | + }, |
| 80 | + { |
| 81 | + "cell_type": "code", |
| 82 | + "execution_count": null, |
| 83 | + "metadata": { |
| 84 | + "tags": [] |
| 85 | + }, |
| 86 | + "outputs": [], |
| 87 | + "source": [ |
| 88 | + "# Set your Default session type here\n", |
| 89 | + "SESSION_TYPE = 'platform'\n", |
| 90 | + "\n", |
| 91 | + "import refinitiv.data as rd\n", |
| 92 | + "from refinitiv.data._data.legacy import get_default_session, set_default_session\n", |
| 93 | + "session=None\n", |
| 94 | + "def open_session(session_type=None):\n", |
| 95 | + " if session_type is None:\n", |
| 96 | + " session_type = SESSION_TYPE\n", |
| 97 | + " session = get_default_session()\n", |
| 98 | + " if session is None:\n", |
| 99 | + " if session_type == \"desktop\":\n", |
| 100 | + " session = rd.session.desktop.Definition(APP_KEY).get_session()\n", |
| 101 | + " elif session_type == \"platform\":\n", |
| 102 | + " session = rd.session.platform.Definition(\n", |
| 103 | + " app_key=APP_KEY,\n", |
| 104 | + " grant=rd.session.platform.GrantPassword(\n", |
| 105 | + " username=RDP_LOGIN,\n", |
| 106 | + " password=RDP_PASSWORD\n", |
| 107 | + " )\n", |
| 108 | + " ).get_session()\n", |
| 109 | + " elif session_type == \"deployed\":\n", |
| 110 | + " session = rd.session.platform.Definition(\n", |
| 111 | + " app_key=APP_KEY,\n", |
| 112 | + " deployed_platform_host = DEPLOYED_PLATFORM_HOST,\n", |
| 113 | + " deployed_platform_username = DEPLOYED_PLATFORM_USER_NAME\n", |
| 114 | + " ).get_session()\n", |
| 115 | + "\n", |
| 116 | + " if session is None:\n", |
| 117 | + " raise Exception(f\"Wrong session_type: {session_type}. It must be ['desktop', 'platform', 'deployed']\")\n", |
| 118 | + " else:\n", |
| 119 | + " set_default_session(session)\n", |
| 120 | + " #session.set_log_level(logging.DEBUG)\n", |
| 121 | + " session.set_log_level(logging.CRITICAL)\n", |
| 122 | + " session.open()\n", |
| 123 | + " \n", |
| 124 | + "def close_session():\n", |
| 125 | + " session = get_default_session()\n", |
| 126 | + " if session:\n", |
| 127 | + " session.close()" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": null, |
| 133 | + "metadata": {}, |
| 134 | + "outputs": [], |
| 135 | + "source": [] |
| 136 | + } |
| 137 | + ], |
| 138 | + "metadata": { |
| 139 | + "kernelspec": { |
| 140 | + "display_name": "RevData39", |
| 141 | + "language": "python", |
| 142 | + "name": "rd39" |
| 143 | + }, |
| 144 | + "language_info": { |
| 145 | + "codemirror_mode": { |
| 146 | + "name": "ipython", |
| 147 | + "version": 3 |
| 148 | + }, |
| 149 | + "file_extension": ".py", |
| 150 | + "mimetype": "text/x-python", |
| 151 | + "name": "python", |
| 152 | + "nbconvert_exporter": "python", |
| 153 | + "pygments_lexer": "ipython3", |
| 154 | + "version": "3.9.4" |
| 155 | + } |
| 156 | + }, |
| 157 | + "nbformat": 4, |
| 158 | + "nbformat_minor": 4 |
| 159 | +} |
0 commit comments