IApi
QuantConnect.Interfaces.IApi
Bases: IDisposable
API for QuantConnect.com
abort_optimization
abort_optimization(optimization_id: str) -> RestResponse
Abort an optimization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimization_id
|
str
|
Optimization id for the optimization we want to abort |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse. |
add_project_file
add_project_file(
project_id: int, name: str, content: str
) -> RestResponse
Add a file to a project
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
The project to which the file should be added |
required |
name
|
str
|
The name of the new file |
required |
content
|
str
|
The content of the new file |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
ProjectFilesResponse that includes information about the newly created file. |
broadcast_live_command
broadcast_live_command(
organization_id: str,
exclude_project_id: Optional[int],
command: Any,
) -> RestResponse
Broadcast a live command
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
organization_id
|
str
|
Organization ID of the projects we would like to broadcast the command to |
required |
exclude_project_id
|
Optional[int]
|
Project for the live instance we want to exclude from the broadcast list |
required |
command
|
Any
|
The command to run |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse. |
create_backtest
create_backtest(
project_id: int, compile_id: str, backtest_name: str
) -> Backtest
Create a new backtest from a specified project_id and compile_id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
|
required |
compile_id
|
str
|
|
required |
backtest_name
|
str
|
|
required |
create_compile
create_compile(project_id: int) -> Compile
Create a new compile job request for this project id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id we wish to compile. |
required |
Returns:
| Type | Description |
|---|---|
Compile
|
Compile object result. |
create_live_algorithm
create_live_algorithm(
project_id: int,
compile_id: str,
node_id: str,
brokerage_settings: Dictionary[str, Object],
version_id: str = "-1",
data_providers: Dictionary[str, Object] = None,
) -> CreateLiveAlgorithmResponse
Create a new live algorithm for a logged in user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Id of the project on QuantConnect |
required |
compile_id
|
str
|
Id of the compilation on QuantConnect |
required |
node_id
|
str
|
Id of the node that will run the algorithm |
required |
brokerage_settings
|
Dictionary[str, Object]
|
Dictionary with Brokerage specific settings |
required |
version_id
|
str
|
The version identifier |
'-1'
|
data_providers
|
Dictionary[str, Object]
|
Dictionary with data providers and their corresponding credentials |
None
|
Returns:
| Type | Description |
|---|---|
CreateLiveAlgorithmResponse
|
Information regarding the new algorithm CreateLiveAlgorithmResponse. |
create_optimization
create_optimization(
project_id: int,
name: str,
target: str,
target_to: str,
target_value: Optional[float],
strategy: str,
compile_id: str,
parameters: HashSet[OptimizationParameter],
constraints: Sequence[Constraint],
estimated_cost: float,
node_type: str,
parallel_nodes: int,
) -> OptimizationSummary
create_project
create_project(
name: str,
language: Language,
organization_id: str = None,
) -> ProjectResponse
Create a project with the specified name and language via QuantConnect.com API
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Project name |
required |
language
|
Language
|
Programming language to use |
required |
organization_id
|
str
|
Organization to create this project under |
None
|
Returns:
| Type | Description |
|---|---|
ProjectResponse
|
ProjectResponse that includes information about the newly created project. |
delete_backtest
delete_backtest(
project_id: int, backtest_id: str
) -> RestResponse
Delete a backtest from the specified project and backtest_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project for the backtest we want to delete |
required |
backtest_id
|
str
|
Backtest id we want to delete |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse on success. |
delete_object_store
delete_object_store(
organization_id: str, key: str
) -> RestResponse
Request to delete Object Store metadata of a specific organization and key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
organization_id
|
str
|
Organization ID we would like to delete the Object Store file from |
required |
key
|
str
|
Key to the Object Store file |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse. |
delete_optimization
delete_optimization(optimization_id: str) -> RestResponse
Delete an optimization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimization_id
|
str
|
Optimization id for the optimization we want to delete |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse. |
delete_project
delete_project(project_id: int) -> RestResponse
Delete a specific project owned by the user from QuantConnect.com
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id we own and wish to delete |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse indicating success. |
delete_project_file
delete_project_file(
project_id: int, name: str
) -> RestResponse
Delete a file in a project
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to which the file belongs |
required |
name
|
str
|
The name of the file that should be deleted |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
ProjectFilesResponse that includes the information about all files in the project. |
download
download(
address: str,
headers: List[KeyValuePair[str, str]],
user_name: str,
password: str,
) -> str
Local implementation for downloading data to algorithms
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
URL to download |
required |
headers
|
List[KeyValuePair[str, str]]
|
KVP headers |
required |
user_name
|
str
|
Username for basic authentication |
required |
password
|
str
|
Password for basic authentication |
required |
download_bytes
download_bytes(
address: str,
headers: List[KeyValuePair[str, str]],
user_name: str,
password: str,
) -> List[int]
Local implementation for downloading data to algorithms
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
URL to download |
required |
headers
|
List[KeyValuePair[str, str]]
|
KVP headers |
required |
user_name
|
str
|
Username for basic authentication |
required |
password
|
str
|
Password for basic authentication |
required |
download_data
download_data(file_path: str, organization_id: str) -> bool
Method to download and save the data purchased through QuantConnect
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
File path representing the data requested |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A bool indicating whether the data was successfully downloaded or not. |
estimate_optimization
estimate_optimization(
project_id: int,
name: str,
target: str,
target_to: str,
target_value: Optional[float],
strategy: str,
compile_id: str,
parameters: HashSet[OptimizationParameter],
constraints: Sequence[Constraint],
) -> Estimate
get_algorithm_status
get_algorithm_status(algorithm_id: str) -> AlgorithmControl
Get the algorithm current status, active or cancelled from the user
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm_id
|
str
|
|
required |
get_object_store
get_object_store(
organization_id: str,
keys: List[str],
destination_folder: str = None,
) -> bool
Download the object store associated with the given organization ID and key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
organization_id
|
str
|
Organization ID we would like to get the Object Store from |
required |
keys
|
List[str]
|
Keys for the Object Store files |
required |
destination_folder
|
str
|
Folder in which the object will be stored |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the object was retrieved correctly, false otherwise. |
get_object_store_properties
get_object_store_properties(
organization_id: str, key: str
) -> PropertiesObjectStoreResponse
Get Object Store properties given the organization ID and the Object Store key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
organization_id
|
str
|
Organization ID we would like to get the Object Store from |
required |
key
|
str
|
Key for the Object Store file |
required |
Returns:
| Type | Description |
|---|---|
PropertiesObjectStoreResponse
|
PropertiesObjectStoreResponse. |
initialize
initialize(
user_id: int, token: str, data_folder: str
) -> None
Initialize the control system
liquidate_live_algorithm
liquidate_live_algorithm(project_id: int) -> RestResponse
Liquidate a live algorithm from the specified project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project for the live instance we want to stop |
required |
list_backtests
list_backtests(
project_id: int, include_statistics: bool = False
) -> BacktestSummaryList
Get a list of backtest summaries for a specific project id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to search |
required |
include_statistics
|
bool
|
True for include statistics in the response, false otherwise |
False
|
Returns:
| Type | Description |
|---|---|
BacktestSummaryList
|
BacktestList container for list of backtests. |
list_live_algorithms
list_live_algorithms(
status: Optional[AlgorithmStatus] = None,
) -> LiveList
Get a list of live running algorithms for a logged in user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
Optional[AlgorithmStatus]
|
Filter the statuses of the algorithms returned from the api |
None
|
Returns:
| Type | Description |
|---|---|
LiveList
|
List of live algorithm instances. |
list_optimizations
list_optimizations(
project_id: int,
) -> List[OptimizationSummary]
List all the optimizations for a project
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id we'd like to get a list of optimizations for |
required |
Returns:
| Type | Description |
|---|---|
List[OptimizationSummary]
|
A list of BaseOptimization objects, BaseOptimization. |
list_projects
list_projects() -> ProjectResponse
Read back a list of all projects on the account for a user.
Returns:
| Type | Description |
|---|---|
ProjectResponse
|
Container for list of projects. |
read_account
read_account(organization_id: str = None) -> Account
Will read the organization account status
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
organization_id
|
str
|
The target organization id, if null will return default organization |
None
|
read_backtest
read_backtest(
project_id: int,
backtest_id: str,
get_charts: bool = True,
) -> Backtest
Read out the full result of a specific backtest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id for the backtest we'd like to read |
required |
backtest_id
|
str
|
Backtest id for the backtest we'd like to read |
required |
get_charts
|
bool
|
True will return backtest charts |
True
|
Returns:
| Type | Description |
|---|---|
Backtest
|
Backtest result object. |
read_backtest_chart
read_backtest_chart(
project_id: int,
name: str,
start: int,
end: int,
count: int,
backtest_id: str,
) -> ReadChartResponse
Returns a requested chart object from a backtest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project ID of the request |
required |
name
|
str
|
The requested chart name |
required |
start
|
int
|
The Utc start seconds timestamp of the request |
required |
end
|
int
|
The Utc end seconds timestamp of the request |
required |
count
|
int
|
The number of data points to request |
required |
backtest_id
|
str
|
Associated Backtest ID for this chart request |
required |
read_backtest_insights
read_backtest_insights(
project_id: int,
backtest_id: str,
start: int = 0,
end: int = 0,
) -> InsightResponse
Read out the insights of a backtest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Id of the project from which to read the backtest |
required |
backtest_id
|
str
|
Backtest id from which we want to get the insights |
required |
start
|
int
|
Starting index of the insights to be fetched |
0
|
end
|
int
|
Last index of the insights to be fetched. Note that end - start must be less than 100 |
0
|
Returns:
| Type | Description |
|---|---|
InsightResponse
|
InsightResponse. |
read_backtest_report
read_backtest_report(
project_id: int, backtest_id: str
) -> BacktestReport
Read out the report of a backtest in the project id specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to read |
required |
backtest_id
|
str
|
Specific backtest id to read |
required |
Returns:
| Type | Description |
|---|---|
BacktestReport
|
BacktestReport. |
read_compile
read_compile(project_id: int, compile_id: str) -> Compile
Read a compile packet job result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id we sent for compile |
required |
compile_id
|
str
|
Compile id return from the creation request |
required |
Returns:
| Type | Description |
|---|---|
Compile
|
Compile object result. |
read_data_directory
read_data_directory(file_path: str) -> DataList
Get valid data entries for a given filepath from data/list
read_data_link
read_data_link(
file_path: str, organization_id: str
) -> DataLink
Gets the link to the downloadable data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
File path representing the data requested |
required |
organization_id
|
str
|
Organization to purchase this data with |
required |
Returns:
| Type | Description |
|---|---|
DataLink
|
Link to the downloadable data. |
read_data_prices
read_data_prices(organization_id: str) -> DataPricesList
Gets data prices from data/prices
read_lean_versions
read_lean_versions() -> VersionsResponse
Gets a list of LEAN versions with their corresponding basic descriptions
read_live_algorithm
read_live_algorithm(
project_id: int, deploy_id: str
) -> LiveAlgorithmResults
Read out a live algorithm in the project id specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to read |
required |
deploy_id
|
str
|
Specific instance id to read |
required |
Returns:
| Type | Description |
|---|---|
LiveAlgorithmResults
|
Live object with the results. |
read_live_chart
read_live_chart(
project_id: int,
name: str,
start: int,
end: int,
count: int,
) -> ReadChartResponse
Returns a chart object from a live algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project ID of the request |
required |
name
|
str
|
The requested chart name |
required |
start
|
int
|
The Utc start seconds timestamp of the request |
required |
end
|
int
|
The Utc end seconds timestamp of the request |
required |
count
|
int
|
The number of data points to request |
required |
read_live_insights
read_live_insights(
project_id: int, start: int = 0, end: int = 0
) -> InsightResponse
Read out the insights of a live algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Id of the project from which to read the live algorithm |
required |
start
|
int
|
Starting index of the insights to be fetched |
0
|
end
|
int
|
Last index of the insights to be fetched. Note that end - start must be less than 100 |
0
|
Returns:
| Type | Description |
|---|---|
InsightResponse
|
InsightResponse. |
read_live_logs
read_live_logs(
project_id: int,
algorithm_id: str,
start_line: int,
end_line: int,
) -> LiveLog
Gets the logs of a specific live algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project Id of the live running algorithm |
required |
algorithm_id
|
str
|
Algorithm Id of the live running algorithm |
required |
start_line
|
int
|
Start line of logs to read |
required |
end_line
|
int
|
End line of logs to read |
required |
Returns:
| Type | Description |
|---|---|
LiveLog
|
List of strings that represent the logs of the algorithm. |
read_live_portfolio
read_live_portfolio(project_id: int) -> PortfolioResponse
Read out the portfolio state of a live algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Id of the project from which to read the live algorithm |
required |
Returns:
| Type | Description |
|---|---|
PortfolioResponse
|
PortfolioResponse. |
read_optimization
read_optimization(optimization_id: str) -> Optimization
Read an optimization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimization_id
|
str
|
Optimization id for the optimization we want to read |
required |
Returns:
| Type | Description |
|---|---|
Optimization
|
Optimization. |
read_organization
read_organization(
organization_id: str = None,
) -> Organization
Fetch organization data from web API
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
organization_id
|
str
|
|
None
|
read_project
read_project(project_id: int) -> ProjectResponse
Read in a project from the QuantConnect.com API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id you own |
required |
Returns:
| Type | Description |
|---|---|
ProjectResponse
|
ProjectResponse about a specific project. |
read_project_file
read_project_file(
project_id: int, file_name: str
) -> ProjectFilesResponse
Read a file in a project
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to which the file belongs |
required |
file_name
|
str
|
The name of the file |
required |
Returns:
| Type | Description |
|---|---|
ProjectFilesResponse
|
ProjectFilesResponse that includes the file information. |
read_project_files
read_project_files(project_id: int) -> ProjectFilesResponse
Read all files in a project
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to which the file belongs |
required |
Returns:
| Type | Description |
|---|---|
ProjectFilesResponse
|
ProjectFilesResponse that includes the information about all files in the project. |
read_project_nodes
read_project_nodes(project_id: int) -> ProjectNodesResponse
Read all nodes in a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to which the nodes refer |
required |
Returns:
| Type | Description |
|---|---|
ProjectNodesResponse
|
ProjectNodesResponse that includes the information about all nodes in the project. |
send_notification
send_notification(
notification: Notification, project_id: int
) -> RestResponse
Sends a notification
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notification
|
Notification
|
The notification to send |
required |
project_id
|
int
|
The project id |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse containing success response and errors. |
send_statistics
send_statistics(
algorithm_id: str,
unrealized: float,
fees: float,
net_profit: float,
holdings: float,
equity: float,
net_return: float,
volume: float,
trades: int,
sharpe: float,
) -> None
Send the statistics to storage for performance tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm_id
|
str
|
Identifier for algorithm |
required |
unrealized
|
float
|
Unrealized gainloss |
required |
fees
|
float
|
Total fees |
required |
net_profit
|
float
|
Net profi |
required |
holdings
|
float
|
Algorithm holdings |
required |
equity
|
float
|
Total equity |
required |
net_return
|
float
|
Algorithm return |
required |
volume
|
float
|
Volume traded |
required |
trades
|
int
|
Total trades since inception |
required |
sharpe
|
float
|
Sharpe ratio since inception |
required |
set_algorithm_status
set_algorithm_status(
algorithm_id: str,
status: AlgorithmStatus,
message: str = ...,
) -> None
Set the algorithm status from the worker to update the UX e.g. if there was an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm_id
|
str
|
Algorithm id we're setting. |
required |
status
|
AlgorithmStatus
|
Status enum of the current worker |
required |
message
|
str
|
Message for the algorithm status event |
...
|
set_object_store
set_object_store(
organization_id: str, key: str, object_data: List[int]
) -> RestResponse
Upload files to the Object Store
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
organization_id
|
str
|
Organization ID we would like to upload the file to |
required |
key
|
str
|
Key to the Object Store file |
required |
object_data
|
List[int]
|
File to be uploaded |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse. |
stop_live_algorithm
stop_live_algorithm(project_id: int) -> RestResponse
Stop a live algorithm from the specified project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project for the live algo we want to delete |
required |
update_backtest
update_backtest(
project_id: int,
backtest_id: str,
name: str = ...,
note: str = ...,
) -> RestResponse
Update the backtest name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to update |
required |
backtest_id
|
str
|
Backtest id to update |
required |
name
|
str
|
New backtest name to set |
...
|
note
|
str
|
Note attached to the backtest |
...
|
Returns:
| Type | Description |
|---|---|
RestResponse
|
Rest response on success. |
update_optimization
update_optimization(
optimization_id: str, name: str = None
) -> RestResponse
Update an optimization
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimization_id
|
str
|
Optimization id we want to update |
required |
name
|
str
|
Name we'd like to assign to the optimization |
None
|
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse. |
update_project_file_content
update_project_file_content(
project_id: int, file_name: str, new_file_contents: str
) -> RestResponse
Update the contents of a file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to which the file belongs |
required |
file_name
|
str
|
The name of the file that should be updated |
required |
new_file_contents
|
str
|
The new contents of the file |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse indicating success. |
update_project_file_name
update_project_file_name(
project_id: int, old_file_name: str, new_file_name: str
) -> RestResponse
Update the name of a file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to which the file belongs |
required |
old_file_name
|
str
|
The current name of the file |
required |
new_file_name
|
str
|
The new name for the file |
required |
Returns:
| Type | Description |
|---|---|
RestResponse
|
RestResponse indicating success. |
update_project_nodes
update_project_nodes(
project_id: int, nodes: List[str]
) -> ProjectNodesResponse
Update the active state of some nodes to true. If you don't provide any nodes, all the nodes become inactive and AutoSelectNode is true.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_id
|
int
|
Project id to which the nodes refer |
required |
nodes
|
List[str]
|
List of node ids to update |
required |
Returns:
| Type | Description |
|---|---|
ProjectNodesResponse
|
ProjectNodesResponse that includes the information about all nodes in the project. |