Alera API
This guide explains how the Alera API works and how you can use it.
Available with APM version 2.1.0+
The Alera API allows you to:
This feature is only available for fully automated licenses.
HTTP Endpoints
All end-points are prefixed with http://localhost:<port>/api where <port> is the API Port set up in the account setting page. Don't forget to actually enable the API. We've also gone ahead and prevented any traffic to the API from a non-local IP. This means you should only be accessing the API from the same computer that the APM runs on.
Port 7425 is the default port and will be used throughout this document. Please make sure that you select a different port for each account when enabling the API for multiple accounts and that you are connected to the proper account.
HTTP POST Requests
Account
These calls allow us to start/stop the account.
Endpoint: http://localhost:7425/api/account?cmd=start
Parameters: None
Endpoint: http://localhost:7425/api/account?cmd=stop
Parameters: None
Strategies
This call allows the http client to send signals directly to APM for immediate processing. It requires the account to be running.
Signals
Endpoint: http://localhost:7425/api/strategies/<id>
Parameters:
Example
Run Strategy
Endpoint: http://localhost:7425/api/strategies/<id>?cmd=run
Parameters: None
HTTP GET Requests
Account
This call returns the account settings that were setup in the APM user interface.
Endpoint: http://localhost:7425/api/account
Parameters: NONE
Endpoint: http://localhost:7425/api/account/stats
Parameters:
Strategies
This call returns information regarding the strategies setup in the APM user interface.
Any call to a specific strategy requires the account to be running.
Endpoint: http://localhost:7425/api/strategies
Parameters:
If no parameters are specified, the GET request returns settings information for all strategies.
GET Examples
Settings
The outputs for these are not specified here since there are a lot of settings.
If you want to use this information, we suggest you look at the output yourself and determine what information you might want to use.
Orders
The following two URLs also produce the above result:
ReEnter Orders
The responses to these requests are the same as regular order requests:
Portfolio
Trades
Symbols
Strategy Stats
This guide explains how the Alera API works and how you can use it.
Available with APM version 2.1.0+
The Alera API allows you to:
- Send signals directly to the APM signal queue for immediate processing
- Retrieve account and strategy settings programmatically
- Retrieve current portfolio, order and trade information on a strategy by strategy basis
This feature is only available for fully automated licenses.
HTTP Endpoints
All end-points are prefixed with http://localhost:<port>/api where <port> is the API Port set up in the account setting page. Don't forget to actually enable the API. We've also gone ahead and prevented any traffic to the API from a non-local IP. This means you should only be accessing the API from the same computer that the APM runs on.
Port 7425 is the default port and will be used throughout this document. Please make sure that you select a different port for each account when enabling the API for multiple accounts and that you are connected to the proper account.
Type | URL | Description |
---|---|---|
POST | api/account?cmd=start | Start the account (connect to broker) |
POST | api/account?cmd=stop | Stop the account |
POST | api/strategies/<id> | Add multiple signals to the queue |
POST | api/strategies/<id>?cmd=run | Run this strategy |
GET | api/account | Get the account settings |
GET | api/account/stats/<currency> | Get the account stats |
GET | api/strategies | Get the settings for all strategies |
GET | api/strategies/<id> | Get the settings a specific strategy |
GET | api/strategies/<id>/portfolio/<format> | Get the portfolio for a strategy as text or json |
GET | api/strategies/<id>/orders/<format> | Get the orders for a strategy as text or json |
GET | api/strategies/<id>/trades/<format> | Get the trades for a strategy as text or json |
GET | api/strategies/<id>/reenter/<format> | Get the ReEnter orders for a strategy as text or json |
GET | api/strategies/<id>/stats | Get statistics for a strategy |
GET | api/strategies/<id>/symbols | Get a list of symbols assigned to the strategy by the APM |
HTTP POST Requests
Account
These calls allow us to start/stop the account.
Endpoint: http://localhost:7425/api/account?cmd=start
Parameters: None
Endpoint: http://localhost:7425/api/account?cmd=stop
Parameters: None
Strategies
This call allows the http client to send signals directly to APM for immediate processing. It requires the account to be running.
Signals
Endpoint: http://localhost:7425/api/strategies/<id>
Parameters:
- Header:
- Content-Type: application/json
- Content-Type: application/json
- Body:
- Key: “signals”
- Value: A string containing multiple lines with the same format as the flat signal files (i.e. each line contains one signal. Comments are allowed). Invalid signals will be ignored. No csv formatting supported at this time.
- Key: “signals”
Example
URL: http://localhost:7425/api/strategies/1002
Header: Content-Type: application/json
Body:{"signals":"
# This is just a comment
BTO SPY
LONG IVV 20 %position
SHORT DELL 100 shares LMT 45
"}
Response:
BTO SPY
LONG IVV 20 %POSITION
SHORT DELL 100 SHARES LMT 45
Run Strategy
Endpoint: http://localhost:7425/api/strategies/<id>?cmd=run
Parameters: None
HTTP GET Requests
Account
This call returns the account settings that were setup in the APM user interface.
Endpoint: http://localhost:7425/api/account
Parameters: NONE
Endpoint: http://localhost:7425/api/account/stats
Parameters:
- Currency:
- This is the currency you wish to receive the account stats in. Note that only valid strategy base currencies can be used here.
- This field is optional. Not providing it retrieves the stats in your account's base currency.
- This is the currency you wish to receive the account stats in. Note that only valid strategy base currencies can be used here.
Strategies
This call returns information regarding the strategies setup in the APM user interface.
Any call to a specific strategy requires the account to be running.
Endpoint: http://localhost:7425/api/strategies
Parameters:
- Id:
- This is the strategyId of the strategy you wish to query. Usually a 4 digit number (e.g. 1002)
- If no strategy with this id exists, the call returns Bad Request and an error message
- This is the strategyId of the strategy you wish to query. Usually a 4 digit number (e.g. 1002)
- Info:
- This parameter is used to specify the type of information that is requested for a specific strategy
- The following values are valid:
- Portfolio - returns the current portfolio
- Orders - returns all active orders. This includes the Stop and Target orders. The ReEnter orders are not listed here as they are not active in the market.
- ReEnter - returns all ReEnter orders
- Trades - returns the trades executed in the last 24 hours
- Stats - returns the strategy statistics
- Symbols - return a list of symbols assigned to the strategy (you do not necessarily hold positions for assigned symbols)
- Portfolio - returns the current portfolio
- This parameter is used to specify the type of information that is requested for a specific strategy
- Format:
- The response for Portfolio, Orders, ReEnter, Trades can be requested in two different formats (optional: default Text)
- JSON - returns a list of JSON formatted objects
- Text - returns a nicely formatted string (use this for displaying info)
- JSON - returns a list of JSON formatted objects
- The response for Symbols, Stats come in JSON format (see examples below)
- The response for Portfolio, Orders, ReEnter, Trades can be requested in two different formats (optional: default Text)
If no parameters are specified, the GET request returns settings information for all strategies.
GET Examples
Settings
The outputs for these are not specified here since there are a lot of settings.
If you want to use this information, we suggest you look at the output yourself and determine what information you might want to use.
Orders
URL: http://localhost:7425/api/strategies/1002/orders
Response:
[
{
"Symbol": "QQQ",
"Currency": "USD",
"Country": "US",
"Action": "SELL",
"Type": "TGT",
"Quantity": 100.0,
"TimeInForce": "GTC",
"LimitPrice": null,
"StopPrice": null,
"TargetPrice": 215.5,
"TrailingPercent": null
},
{
"Symbol": "QQQ",
"Currency": "USD",
"Country": "US",
"Action": "SELL",
"Type": "STP",
"Quantity": 100.0,
"TimeInForce": "GTC",
"LimitPrice": null,
"StopPrice": 195.36,
"TargetPrice": null,
"TrailingPercent": null
},
]
Code:
URL: http://localhost:7425/api/strategies/1002/orders/text
Response:
ORDERS Action Quantity Type Limit % TIF ID
-------------------------------------------------------------------
1. QQQ SELL 100 TGT 215.50 GTC
2. QQQ SELL 100 STP 195.36 GTC
3. SVXY SELL 917 MKT DAY
4. TLT SELL 1,000 STP 160.47 GTC
5. TLT SELL 1,000 TGT 177.01 GTC
6. TLT SELL 1,018 LOC 100.00 DAY
7. TSLA BUY 80 TGT 551.95 GTC
8. TSLA BUY 80 STP 611.31 GTC
9. TSLA BUY 49 MKT DAY
10. USD BUY 370 MKT DAY
-------------------------------------------------------------------
ReEnter Orders
The responses to these requests are the same as regular order requests:
Portfolio
URL: http://localhost:7425/api/strategies/1002/portfolio
Response:
[
{
"Symbol": "QQQ",
"Currency": "USD",
"Country": "US",
"Quantity": 100.0,
"Exposure": "LONG",
"MarketPrice": 201.3999939,
"MarketValue": 20140.0,
"AverageCost": 216.555,
"UnrealizedPNL": -1515.5,
"RealizedPNL": null,
"Hold": null
},
{
"Symbol": "SVXY",
"Currency": "USD",
"Country": "US",
"Quantity": 917.0,
"Exposure": "LONG",
"MarketPrice": 32.54999925,
"MarketValue": 29848.35,
"AverageCost": 53.88827155,
"UnrealizedPNL": -19567.2,
"RealizedPNL": null,
"Hold": null
},
]
Trades
URL: http://localhost:7425/api/strategies/1002/symbols
Response:
[
{
"Symbol": "GS",
"Currency": "USD",
"Country": "US",
"Side": "BOT",
"Quantity": 181.0,
"AveragePrice": 183.21,
"Value": 33161.01,
"Time": "20200413 10:30:32"
},
{
"Symbol": "GS",
"Currency": "USD",
"Country": "US",
"Side": "BOT",
"Quantity": 46.0,
"AveragePrice": 183.38,
"Value": 8435.48,
"Time": "20200413 10:33:14"
},
]
Symbols
URL: http://localhost:7425/api/strategies/1002/symbols
Response:
["QQQ","SVXY","TLT","TSLA"]
Strategy Stats
URL: http://localhost:7425/api/strategies/1002/stats
Response:
{
"Allocation": 550000,
"LongExposure": 383826.07999999996,
"ShortExposure": -76561.5,
"NumberOfLongPositions": 3,
"NumberOfShortPositions": 1,
"LongPNL": 20382.74,
"ShortPNL": 23753.41,
"NetExposure": 307264.57999999996,
"TotalExposure": 460387.57999999996,
"TotalNumberOfPositions": 4,
"TotalPNL": 44136.15
}