from gs_quant.api.gs.users import GsUsersApi
from gs_quant.api.gs.workspaces import GsWorkspacesMarketsApi as ws_api
from gs_quant.session import Environment, GsSession
from gs_quant.target.workspaces_markets import *
GsSession.use(Environment.PROD, client_id=None, client_secret=None)
Determine the basics of your Workspace (i.e name, description and entitlements over who can view and edit)
name = 'Example Workspace'
alias = 'example-workspace' # This needs to be unique across all users as to not have conflicting URLs
description = 'This workspace was created as an example.'
user_id = GsUsersApi.get_my_guid()
# Entitle everyone internal to view but only yourself to edit and change entitlements
entitlements = Entitlements(view=(user_id,), edit=(user_id,), admin=(user_id,))
components = [] # Empty list of components with some to be added below
Workspaces currently support many components such as Promo (text), Plots, DataGrids, and Commentary. See all available components here.
To create a component, create the parameters object for the component such as PromoComponentParameters, fill out the required and optional fields.
Then add the component using these parameters. Let's start with a simple Promo Component.
If you want to add simple text to a workspace, this can be done by adding a Promo Component, as seen below.
promo_params = PromoComponentParameters(height=52, body='Your text here!', transparent=False)
components.append(WorkspaceComponent(id_='promo-1', type_=ComponentType.promo, parameters=promo_params))
Now you are ready to create your workspace. Let us put everything together.
layout = 'r(c12($0))'
parameters = WorkspaceParameters(layout=layout, components=components)
workspace = Workspace(parameters=parameters, name=name, alias=alias, entitlements=entitlements, description=description)
workspace = ws_api.create_workspace(workspace)
The above snippet will create a workspace that is now viewable at the URL https://marquee.gs.com/s/markets/%7Balias%7D. Substitute {alias} with the alias you set. Remember to change the alias since the example one probably already exists.
The layout string controls the layout of your components. In this case, a simple layout with a single component that spans a single row. Learn more about layouts here.
Now let us create a Workspace with some plots and a commentary component.
Start by creating plots in PlotTool Pro here
After you have created your plot, grab the plot id from the browser.
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.
# 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.
plot_params = PlotComponentParameters(height=300, hideLegend=False)
plot_id = 'CHYYNR2YSD8W21GA' # example plot id
# Add the plot component to the list of components
components.append(WorkspaceComponent(id_=plot_id, type_=ComponentType.plot, parameters=plot_params))
channel_1 = 'EQUITIES MACRO'
channel_2 = 'EQUITIES GS BASKETS'
commentary_params = CommentaryComponentParameters(height=300, commentary_channels=(channel_1, channel_2))
components.append(WorkspaceComponent(id_='streaming-commentary-1', type_=ComponentType.commentary, parameters=commentary_params))
workspace.parameters.layout = 'r(c12($0))r(c6($1)c6($2))'
workspace.parameters.components = components
workspace = ws_api.update_workspace(workspace)
--------------------------------------------------------------------------- MqRequestError Traceback (most recent call last) <ipython-input-8-8b4e83496b74> in <module> 3 parameters = WorkspaceParameters(layout=layout, components=components, disclaimer=disclaimer) 4 new_workspace = Workspace(parameters,'cashboard', name=name, alias=alias, entitlements=entitle, description=description) ----> 5 created_workspace = wk.create_workspace(new_workspace) 6 H:\_repos\gs_quant\gs_quant\api\gs\workspaces.py in create_workspace(cls, workspace) 49 @classmethod 50 def create_workspace(cls, workspace: Workspace) -> Workspace: ---> 51 return GsSession.current._post(f'{API}', workspace, cls=Workspace, request_headers=WORKSPACES_MARKETS_HEADERS) 52 53 @classmethod H:\_repos\gs_quant\gs_quant\session.py in _post(self, path, payload, request_headers, cls, include_version, timeout) 230 include_version: bool = True, timeout: int = DEFAULT_TIMEOUT) -> Union[Base, tuple, dict]: 231 return self.__request('POST', path, payload=payload, request_headers=request_headers, --> 232 cls=cls, include_version=include_version, timeout=timeout) 233 234 def _delete(self, path: str, payload: Optional[Union[dict, Base]] = None, request_headers: Optional[dict] H:\_repos\gs_quant\gs_quant\session.py in __request(self, method, path, payload, request_headers, cls, try_auth, include_version, timeout) 195 return self.__request(method, path, payload=payload, cls=cls, try_auth=False) 196 elif not 199 < response.status_code < 300: --> 197 raise MqRequestError(response.status_code, response.text, context='{} {}'.format(method, url)) 198 elif 'Content-Type' in response.headers: 199 if 'application/x-msgpack' in response.headers['Content-Type']: MqRequestError: context: POST https://marquee.web.gs.com/v1/workspaces/markets status: 400, message: <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>Request Body Validation Error</title> <style>body { font-family: sans-serif; } footer { font-style: italic; }</style> </head> <body> <h1>400 Bad Request - Request Body Validation Error</h1> <h2>Problem Description</h2> <p> The request did not match any of the requests defined for this endpoint. </p> <h2>Details</h2> <h3>Request Definition 1</h3> <p>The JSON object in the body does not conform to the schema</p> <ul> <li>error: ECMA 262 regex "^(?:\w{1,256}:){0,10}[\w.]{1,256}$$" does not match input string "insert your user id" level: "error" schema: {"loadingURI":"definition:/Token#","pointer":""} instance: {"pointer":"/entitlements/admin/0"} domain: "validation" keyword: "pattern" regex: "^(?:\\w{1,256}:){0,10}[\\w.]{1,256}$$" string: "insert your user id" </li> </ul> <h2>Troubleshooting</h2> <ul> <li>Verify that the content type of the request matches the service definition.</li> <li>Check that the JSON document you are sending matches the schema.</li> <li>If the service does not define any requests, make sure you are not sending a request body.</li> </ul> <footer><p>Error ID: 7001873889772119441</p><p>Dash Services Framework 62.3 [SVN build 8011 at 2021-01-22 16:07]</p></footer> </body> </html> <!-- The request did not match any of the requests defined for this endpoint. Request definition 1: The JSON object in the body does not conform to the schema error: ECMA 262 regex "^(?:\w{1,256}:){0,10}[\w.]{1,256}$$" does not match input string "insert your user id" level: "error" schema: {"loadingURI":"definition:/Token#","pointer":""} instance: {"pointer":"/entitlements/admin/0"} domain: "validation" keyword: "pattern" regex: "^(?:\\w{1,256}:){0,10}[\\w.]{1,256}$$" string: "insert your user id" -->