Start with sample code
Use a strategy starter template or an asset-specific example to understand the supported interface before adding custom behavior.
Develop custom strategy logic with the Investfly Python SDK while platform services handle supported market data, indicators, order planning, backtesting, virtual portfolios, and eligible account deployment.
class MyStrategy(TradingStrategy): def getSecurityUniverseSelector(self): return SecurityUniverseSelector.fromSymbols( SecurityType.STOCK, ["AAPL", "MSFT"] ) @data_trigger( type=DataType.BARS, barInterval=BarInterval.FIFTEEN_MINUTE ) def onMarketData(self, updatedSecurities): # Your signal and order-planning logic return orders or None
The SDK gives your code explicit interfaces for the universe, market-data callbacks, portfolio access, order requests, and shared position controls.
Use a strategy starter template or an asset-specific example to understand the supported interface before adding custom behavior.
Define security selection, data callbacks, custom indicators, signal evaluation, and order-planning requests in Python.
Run historical backtests, deploy to a virtual portfolio, inspect activity, and revise code before considering eligible live use.
Asset-native selection and execution models remain visible even when your signal logic is custom.
Python strategies run inside the supported Investfly environment rather than an unrestricted general-purpose server.
Access platform-provided bars, quotes, indicator series, and strategy services through supported interfaces.
Use supported runtime imports including NumPy, pandas, TA-Lib, statistics, typing, and Investfly SDK modules.
Express position management and portfolio limits through typed strategy-policy models where applicable.
Use the same user-authored strategy concept across backtesting, virtual portfolios, and eligible deployments.
It supplies supported market data, strategy interfaces, testing, virtual portfolios, order planning, monitoring, and eligible broker connectivity so your code can focus on the logic you author.
The current bounded runtime supports Investfly SDK modules and selected packages including NumPy, pandas, TA-Lib, statistics, typing, and math. Check the API documentation for the current interface and restrictions.
Supported Python strategies follow the shared strategy path through historical backtesting and virtual portfolio simulation, helping you inspect behavior before considering eligible live use.
Use Python when your strategy needs supported custom selection, indicators, callbacks, or signal logic. Use the visual builder when the available configuration fields can express the strategy more simply.
The public SDK version 3.1.2 supports Python 3.11+. This minimal authoring example declares a stock universe, runtime-managed protection and an allocation callback. It is an educational starting point; it has no predictive signal and its example allocation must be reviewed before any use.
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
Download MyStrategy.py and follow installation, type-checking, upload and hosted testing. A local import/type check does not reproduce hosted data or fills. The bounded runtime supports Investfly modules and selected math, statistics, typing, NumPy, pandas and TA-Lib imports; it is not unrestricted package hosting.
Premium/Elite plans provide continued historical testing and automated deployment after the trial. Elite adds eligible broker connections. Use Python templates for worked market-specific logic. Standalone backtesting-library/framework searches can seek a different product; this is a hosted strategy platform.
Download the public volatility-adaptive BTC DCA source or inspect its strategy and report. This larger maintained example demonstrates scheduled contributions and volatility-based safety orders; it is separate from MyStrategy.py and is not an investment recommendation.
| Reported period | Matched closed records | Last completed run |
|---|---|---|
| 2026-09-09 to 2026-10-13 | 2 | 2026-10-14 |
Observed October 14, 2026. Historical modeled output is not a live or paper-deployment result. Downloaded examples are type-checked locally; the platform still validates uploaded code and returns the current run’s actual status, warnings, dates and trades.
After uploading, testing and choosing a compatible Investfly virtual portfolio, inspect the saved strategy’s Deployment status and Execution Logs. A deployed state establishes the running copy/account; it does not establish a filled order. Logs can show startup, evaluation, no-order decisions or errors. Reconcile orders and positions separately. See the labeled actual status/log screen and its interpretation. That fictional SMA demo is separate from MyStrategy.py; no hosted paper run of the minimal snippet is claimed here.
Review the supported interface, clone a sample, and test your own code in the platform.
Available packages, providers, instruments, and live capabilities depend on current platform support.