{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"pycharm": {
"is_executing": false
}
},
"outputs": [],
"source": [
"from gs_quant.api.gs.users import GsUsersApi\n",
"from gs_quant.api.gs.workspaces import GsWorkspacesMarketsApi as ws_api\n",
"from gs_quant.session import Environment, GsSession\n",
"from gs_quant.target.workspaces_markets import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"GsSession.use(Environment.PROD, client_id=None, client_secret=None)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"### Initializing your Workspace\n",
"\n",
"Determine the basics of your Workspace (i.e name, description and entitlements over who can view and edit)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"name = 'Example Workspace'\n",
"alias = 'example-workspace' # This needs to be unique across all users as to not have conflicting URLs\n",
"description = 'This workspace was created as an example.'\n",
"user_id = GsUsersApi.get_my_guid()\n",
"\n",
"# Entitle everyone internal to view but only yourself to edit and change entitlements\n",
"entitlements = Entitlements(view=(user_id,), edit=(user_id,), admin=(user_id,))\n",
"\n",
"components = [] # Empty list of components with some to be added below"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"### Add Components\n",
"\n",
"Workspaces currently support many components such as Promo (text), Plots, DataGrids, and Commentary. See all available components\n",
"[here](https://developer.gs.com/p/docs/services/data/workspaces-markets/#components).\n",
"\n",
"To create a component, create the parameters object for the component such as PromoComponentParameters, fill out the required and optional fields.\n",
"\n",
"Then add the component using these parameters. Let's start with a simple Promo Component."
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"#### Add a Promo Component \n",
"\n",
"If you want to add simple text to a workspace, this can be done by adding a Promo Component, as seen below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"promo_params = PromoComponentParameters(height=52, body='Your text here!', transparent=False)\n",
"components.append(WorkspaceComponent(id_='promo-1', type_=ComponentType.promo, parameters=promo_params))"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"### Create the Workspace\n",
"\n",
"Now you are ready to create your workspace. Let us put everything together."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"layout = 'r(c12($0))'\n",
"parameters = WorkspaceParameters(layout=layout, components=components)\n",
"workspace = Workspace(parameters=parameters, name=name, alias=alias, entitlements=entitlements, description=description)\n",
"workspace = ws_api.create_workspace(workspace)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"The above snippet will create a workspace that is now viewable at the URL https://marquee.gs.com/s/markets/{alias}. \n",
"Substitute {alias} with the alias you set. Remember to change the alias since the example one probably already exists.\n",
"\n",
"The layout string controls the layout of your components. In this case, a simple layout with a single component that spans a single row.\n",
"Learn more about layouts [here](https://developer.gs.com/p/docs/services/data/workspaces-markets/#layouts). \n"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"### Updating the Workspace with Additional Components\n",
"\n",
"Now let us create a Workspace with some plots and a commentary component."
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"#### Add a plot \n",
"\n",
"Start by creating plots in PlotTool Pro [here](https://marquee.gs.com/s/plottool/new) \n",
"\n",
"After you have created your plot, grab the plot id from the browser.\n",
"* For example, the id for [this plot](https://marquee.gs.com/s/plottool/CH5RJJ9APZMRQ7B7) is CHYYNR2YSD8W21GA\n",
" \n",
"You want all the underlying components that have entitlements to have the same entitlements as the Workspace, so all components are visible on the Workspace for the intended audience."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false,
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"# Create the plot component parameters, setting the height to the desired height in pixels. Also, other configurations can be set such as hiding the legend.\n",
"plot_params = PlotComponentParameters(height=300, hideLegend=False)\n",
"plot_id = 'CHYYNR2YSD8W21GA' # example plot id\n",
"\n",
"# Add the plot component to the list of components\n",
"components.append(WorkspaceComponent(id_=plot_id, type_=ComponentType.plot, parameters=plot_params))"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"#### Add a commentary stream"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"channel_1 = 'EQUITIES MACRO'\n",
"channel_2 = 'EQUITIES GS BASKETS'\n",
"commentary_params = CommentaryComponentParameters(height=300, commentary_channels=(channel_1, channel_2))\n",
"components.append(\n",
" WorkspaceComponent(id_='streaming-commentary-1', type_=ComponentType.commentary, parameters=commentary_params)\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"### Update the Workspace"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false,
"pycharm": {
"is_executing": false,
"name": "#%%\n"
}
},
"outputs": [
{
"ename": "MqRequestError",
"evalue": "context: POST https://marquee.web.gs.com/v1/workspaces/markets\nstatus: 400, message: \n\n\n\n400 Bad Request - Request Body Validation Error
\n\r\nProblem Description
\r\n
\r\n The request did not match any of the requests defined for this endpoint.\r\n
\r\nThe JSON object in the body does not conform to the schema
\r\n\r\n The request did not match any of the requests defined for this endpoint.\r\n
\r\nThe JSON object in the body does not conform to the schema
\r\n