This section of the Pocket Gateway documentation contains tutorials. A tutorial shows how to accomplish a goal that is larger than a single task. Typically a tutorial has several sections, each of which has a sequence of steps.
1 - Getting Started
This guide will walk you through basic usage with the Pocket Gateway
In less than <15 minutes you’ll be able to deploy a fully personalized
investment manager investing and trading directly on your or your customer’s behalf!
Learning Outcomes
💪 Afterwards, you’ll be able to:
1.1 - Create a new user
Create a new user on the Pocket Gateway
Create a new user
First, you will need to create a new user and an accompanying account.
Only free and personal accounts are supported!
Only free and personal accounts are currently supported. professional and bespoke plans are not yet available.
Replace the environment variables with your given and family name, email, and temporary password.
You will be asked to change the password once the user identifies themselves.
"Bad Request - Received a bad request from the user"
Not the most secure option!
This method of generating an access token is not the most secure. We use it here for illustrative purposes; rather if you’re building an application or requesting an access token often, prefer the object/token/oauth access flow.
👍 Wonderful! You’ve created a new user on the Pocket Cloud and now have an access token to start deploying resources!
1.2 - Access the user account
Access the newly created user accounts.
Access user account
If you are creating professional or bespoke accounts, you will have to create the accounts manually.
First, let’s get all accounts associated to the user:
You should see two accounts; the first account is the production account as indicated with the is_sandbox=false flag–which you’ll be billed for, and the second account is the sandbox account, which you can use as an isolated, non-billable environment to test different resources (AIs).
"Unauthorized access - Unauthorized - you do not have access to this API"
Account is not yet verified!
You may notice that the account is_verified is still in the false state. Most Pocket endpoints will be unavailable until the user has completed verification. At which point, once the user’s identity is verified, the account will be marked true.
"Unauthorized access - Unauthorized - you do not have access to this API"
👍 Báječné! You’ve accessed your newly created account on the Pocket Cloud!
1.3 - Verify the user entity
Verify the user’s entity information
Verify user entity
Before you can deploy most resources, you will have to verify the calling user entity. In most circumstances, all you’ll need to do is provide a government issued ID and verify your proof of identity.
For some account types such as professional and bespoke , you will need to provide additional information.
To start the verification process, send a POST request to the object/entity endpoint.
@TODO
Check verification status
Once the verification has been completed, you can check the status of user accounts by querying the object/account endpoint. Now, you should see that the user account has been verified.
@TODO
👍 Wunderbar! You’ve verified your entity on the Pocket Cloud!
1.4 - Fund your account
Deposit funds into the user account
@TODO
1.5 - Create a portfolio
Create a financial portfolio
Create a portfolio
Before you can start deploying resources onto the Pocket Cloud, you must create a financial portfolio that is linked to your account.
@TODO
1.6 - Deploy a resource
Deploy a synthetic resource onto the Pocket Gateway
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.
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
"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.
You’ll need the USER_RESOURCE_ID environment variable from above.
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!
1.7 - Check on your resource
Check-in on what your resource has been up to
Resources may generate actions which are then stored on the Pocket Cloud. These actions may result in orders being sent to financial exchanges which in turn may become transactions, affecting the user’s running ledger (if not in sandbox mode).
For example, the below user resource may generate the below action, resulting in two orders with an accompanying transaction and a linked resource reward.
Use SSE to receive up-to-date information from your resources
All of the below endpoints alternatively support the SSE protocol. You may open a long-lived session to the Pocket Cloud by passing the Accept: text/event-stream header to your HTTPs request. All other parameters remain the same.
Inspect resource records
Dependent on the type of resource, resources may output records from one or more actions. Records contain a historical record of the information a resource used to take an action. These actions can be inspected by querying the /object/record endpoint.
When a resource takes an action, those actions are recorded under the record endpoint. For example, the above response yields actions for the SNAP ticker destined for the NYSE American exchange. These records may result in orders (below).
Inspect resource orders
Once a resource generates an action, that action may become one or more orders . Orders are submitted to either an explicitly defined exchange or an optimally chosen one. These actions may be inspected by querying the /object/order endpoint.
Resource actions will affect your portfolio and account state. Let’s inspect our linked account ledger to determine what all has occurred.
Inspect ledger state
Accounts and portfolios are linked to ledgers , a running financial statement of your resource’s actions. In free and personal mode, each account has one running ledger.
1
@TODO
1
@TODO
You should see one of the below:
1
@TODO
1
@TODO
1
"You do not have access to this API"
1
"Could not find account - `account_id` not found"
👍 Meravellós! You’ve checked-in on the state of your AI on the Pocket Cloud!