Investfly Python SDK
investfly-sdk is the public Python contract for building custom trading strategies and
custom indicators on Investfly. It contains typed models,
abstract service contracts, API clients, and runnable authoring examples. Live and backtest
execution algorithms remain in the Investfly runtime.
Install
python3 -m venv venv
source venv/bin/activate
pip install investfly-sdk
Python 3.11 or later is required.
The base installation includes mypy and the NumPy, pandas, and requests type information needed to check custom code. Run a full check without installing an optional extra:
mypy --check-untyped-defs MyStrategy.py
NumPy carries its own official type information, so it is installed with the SDK. Pandas
execution remains on Investfly servers; local SDK installations use pandas-stubs and do not
install the pandas runtime package.
Custom strategies
Subclass TradingStrategy, choose a universe, and implement a market-data callback and/or
one or more @scheduled callbacks. The runtime injects:
self.dataServicefor market data and indicatorsself.contextfor the current portfolio, universe, time, and option groupsself.servicesfor runtime-owned selection, ranking, guard evaluation, allocation, instrument selection, order planning, rebalancing, and scaling
Use getStrategyPolicy() for continuous behavior the runtime should enforce around your
callbacks, including protective exits, position scaling, option-group exits and lifecycle,
futures lifecycle, and portfolio limits.
from typing import List, Optional
from investfly.models import *
class MyStrategy(TradingStrategy):
def getSecurityUniverseSelector(self) -> SecurityUniverseSelector:
return SecurityUniverseSelector.fromSymbols(SecurityType.STOCK, ["AAPL", "MSFT"])
def getStrategyPolicy(self) -> CustomStrategyPolicy:
return CustomStrategyPolicy(
assetType=SecurityType.STOCK,
positionManagement=PositionManagementRules(
positionExits=ExitRules(
protectiveExits=buildProtectiveExitPlan(
targetProfitPct=10.0,
stopLossPct=5.0,
trailingStopPct=2.0,
)
)
),
portfolioLimits=PortfolioLimits(maxOpenPositions=5),
)
@data_trigger(type=DataType.BARS, barInterval=BarInterval.FIFTEEN_MINUTE)
def onMarketData(self, updatedSecurities: List[Security]) -> Optional[List[TradeOrder]]:
execution = OpenExecutionSettings(
positionSize=PositionSizeSpec(PositionSizeMode.PERCENT_OF_EQUITY, 15.0),
orderSpec=OrderSpec(),
instrumentSelection=DirectInstrumentSelection(),
)
return self.services.planAllocationOrders(AllocationPlan(updatedSecurities, execution)) or None
The authoritative investfly.samples.strategies catalog contains 37 runnable examples:
8 stock, 5 forex, 5 crypto, 5 futures, and 14 option strategies. The option examples cover
all 24 OptionStrategyTemplate structures, including the Wheel lifecycle, calendars,
diagonals, condors, butterflies, volatility structures, protective hedges, and custom
multi-leg combinations. Catalog metadata describes each strategy's intervals, capabilities,
why Python is required, and real-data audit profile.
Custom indicators
Subclass Indicator, implement getIndicatorSpec(), computeSeries(), and
calculateRequiredBars(). Indicator authors receive an injected IndicatorDataService;
the SDK also ships NumPy/pandas helpers, TA-Lib type stubs, and indicator samples.
CLI and REST clients
Installing the package also installs investfly-cli. Run investfly-cli, then use
login, copysamples, strategy.*, and indicator.* commands.
For direct API access:
from investfly.api.InvestflyApiClient import InvestflyApiClient
api = InvestflyApiClient()
session = api.login("username", "password")
strategies = api.strategyApi.listStrategies()
api.logout()
TLS certificate verification is enabled by default. API calls use a finite timeout and raise
InvestflyApiError for non-2xx responses.
Version 3.1
Version 3.1 expands the typed service boundary and publishes the comprehensive sample catalog.
Version 3.0 was an intentional breaking boundary cleanup. Runtime algorithms and runtime-state
encoding are no longer published as SDK utilities. Custom strategies call self.services and
describe continuous behavior with getStrategyPolicy() instead. See CHANGELOG.md
for the removed 2.x surface and replacements.
API documentation is published at investfly.com/apidocs/investfly.html. For help, contact support@investfly.com.
Metadata
Release files for investfly-sdk 3.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| investfly_sdk-3.1.2.tar.gz | 189.2 kB | Without provenance | Details for investfly_sdk-3.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| investfly_sdk-3.1.2-py3-none-any.whl | Python 3 | none | any | Details for investfly_sdk-3.1.2-py3-none-any.whl |
Total release size: 451.7 kB
Release files / investfly_sdk-3.1.2.tar.gz
| Download URL | investfly_sdk-3.1.2.tar.gz |
|---|---|
| Size | 189.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b5e4f4f9c21b923095ad97e340fb6c131070858c564ed99ad054f6d53e664af
|
|
BLAKE2b-256 checksum How to use checksums |
78b23f0d6db43b03d97405fd52ec8822cfe06d9a769226ef2733c1100bd7f4e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / investfly_sdk-3.1.2-py3-none-any.whl
| Download URL | investfly_sdk-3.1.2-py3-none-any.whl |
|---|---|
| Size | 262.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48370928c083fa5ecee1eae1d4e3ce8915aab77ac510bda664eba980fe52146c
|
|
BLAKE2b-256 checksum How to use checksums |
c14b5ef5d6009ecb831095cc7b2e205265ccfe8b981f47b843aae1b1c3107b68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for investfly-sdk 3.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.