Deploy a resource

Deploy a synthetic resource onto the Pocket Gateway

4 minute read

We’re now going to deploy a resource–an artificial intelligence, on the Pocket Cloud.

A resource is a set of one or more trained policies which carry out a set of pre-defined tasks. In other words, a resource is an “AI” that performs actions on behalf of the calling user.

Resources are identified by a family and name . Resources within the same family are logically related. Once a resource is deployed on the Pocket Cloud It is assigned an id , a universally unique RFC 4122 complaint identifier.

Employ a resource

For this example, we’ll be using the simple-manager resource which constructs a random financial portfolio. This resource is always used in sandbox mode so you don’t need to worry about incurring billing charges.

We’re going to employ a resource with a few configurable parameters. Resource families have different configurable parameters.

1
2
3
4
5
6
7
export \
	USER_RESOURCE_SECTOR="us-stocks" \
	USER_RESOURCE_EXCHANGE=null \
	USER_RESOURCE_PRODUCT=null \
	USER_RESOURCE_ALLOCATION=70 \
	USER_RESOURCE_CONFIG_FREQUENCY=hourly \
 	USER_RESOURCE_CONFIG_MAX_SIZE=100
Variable Description
USER_RESOURCE_SECTOR One or more financial sectors to which the resource is being deployed to
USER_RESOURCE_EXCHANGE A specific financial exchange the resource will read data from and submit orders to
USER_RESOURCE_PRODUCT An array of products(tickers/symbols) to be used
USER_RESOURCE_ALLOCATION A percentage of the user’s account size to be allocated to the resource; i.e., “allocate 20% of my account size to this portfolio manager.”
USER_RESOURCE_CONFIG_FREQUENCY How frequently the resource can take actions; e.g., rebalance, adjust positions, place and cancel orders.
USER_RESOURCE_CONFIG_MAX_SIZE The largest possible order size that the resource may submit.
  • Note: the resource’s balance may increase or decrease in percentage terms as it relates to the original account balance. As a result, you may experience significant “drift” from the original percentage allocation to the current time’s present allocation.

  • Note: the more frequent the data, the more potential actions, and the more potential trading costs.

  • Note: observe that a resource may place multiple orders over sequential time-steps resulting in a “total lot size” greater than max_size

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
curl -X \
  --request POST \
  --url "https://sandbox.alpha.api.pocket-portfolio.com/resource/employ/manager/simple-manager" \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer ${ACCESS_TOKEN}" \
  --data '{
  	"sector": "${USER_RESOURCE_SECTOR}",
    "exchange": "${USER_RESOURCE_EXCHANGE}",
    "product": "${USER_RESOURCE_PRODUCT}",
    "allocation": "${USER_RESOURCE_ALLOCATION}",
    "config": {
    	"frequency": "${USER_RESOURCE_CONFIG_FREQUENCY}",
    	"max_size": "${USER_RESOURCE_CONFIG_MAX_SIZE}"
    }
  }'

After employing the resource, you should receive a status message:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[
  {
    "timestamp": "2020-11-21T20:27:11.826252+00:00",
    "family": "manager",
    "name": "simple-manager",
    "id": "02348147-99b0-4a8c-b170-fa769f61dbb0",
    "status": 4,
    "session_id": "93fa3b6e-fd37-401c-b1c3-46be728e04ec",
    "portfolio_id" "7dc9f025-2c98-4cfc-9bcd-886864ad36f"
  }
]
1
"Unauthorized access - Unauthorized - you do not have access to this API"

Verify resource status

To check on the status of the resource, query the /resource/ping endpoint

1
2
3
4
5
curl -X \
  --request GET \
  --url "https://sandbox.alpha.api.pocket-portfolio.com/resource/ping" \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer ${ACCESS_TOKEN}"
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[
  {
    "timestamp": "2020-11-21T20:28:11.826252+00:00",
    "family": "manager",
    "name": "simple-manager",
    "id": "02348147-99b0-4a8c-b170-fa769f61dbb0",
    "status": 1,
    "session_id": "93fa3b6e-fd37-401c-b1c3-46be728e04ec",
    "portfolio_id" "7dc9f025-2c98-4cfc-9bcd-886864ad36f"
  }
]

export USER_RESOURCE_ID="02348147-99b0-4a8c-b170-fa769f61dbb0"
1
"Unauthorized access - Unauthorized - you do not have access to this API"

Retire a resource

You’ll probably want to shutdown your resource after awhile. Let’s send a POST request to the resource/retire endpoint and teardown our running resource.

1
2
3
4
5
curl -X \
  --request POST \
  --url "https://alpha.api.pocket-portfolio.com/resource/retire/${USER_RESOURCE_ID}" \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer ${ACCESS_TOKEN}"

You should then see something like the below. (it may take a moment for the resource to properly cleanup and shutdown)

1
"400: User {###} did not return any registered resources. Are you sure this user registered a resource on this server?"
1
"Unauthorized access - Unauthorized - you do not have access to this API"

👍 Zvinoshamisa! You’ve employed and retired your first AI onto the Pocket Cloud!

Last modified April 3, 2023: fix ubuntu issues (dc29291)