SDK for developing trading strategies in Python for FraQ NetTrade
Project description
FraQ NetTrade Python Abstractions
SDK for developing trading strategies in Python for the FraQ NetTrade platform.
Installation
pip install fraq-nettrade-abstractions
Quick Start
from fraq_nettrade_abstractions import Strategy
class MyStrategy(Strategy):
def on_start(self, context):
"""Initialize your strategy"""
self.sma_fast = context['indicators'].sma(period=10)
self.sma_slow = context['indicators'].sma(period=20)
def on_bar(self, symbol, index):
"""Trading logic - called on each bar"""
if self.sma_fast[index] > self.sma_slow[index]:
return {'action': 'buy', 'volume': 1.0}
elif self.sma_fast[index] < self.sma_slow[index]:
return {'action': 'sell', 'volume': 1.0}
return None
Backtesting Your Strategy
- Put the full path of the strategy in a FraQ backtest json configuration file
- Run backtest using 'fraq backtest .
Debugging (local only)
from fraq_nettrade_abstractions import Strategy, enable_debugger
class MyStrategy(Strategy):
def on_start(self, context):
debug = context["debug"]
if debug:
print("🔴 ATTACH DEBUGGER NOW")
enable_debugger()
# Your strategy code with breakpoints
Debug workflow:
- Start backtest normally
- Wait until message "ATTACH.." appears in the console window
- Set breakpoints in your strategy
- Attach VS Code to port 5678
here a template for VS Code launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to FraQ",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 5678
},
"justMyCode": false,
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}
]
}
]
}
API Reference
Strategy Class
Base class for all trading strategies.
Methods to implement:
on_start(context)- Called once when backtest startson_bar(symbol, index)- Called on each bar (required)on_tick(symbol)- Called on each tick (optional)on_stop()- Called when backtest ends (optional)
Context Dictionary
Passed to on_start():
{
'account': {
'balance': float,
'equity': float,
'margin_used': float,
'margin_available': float
},
'symbols': [
{
'name': str,
'bid': float,
'ask': float,
}
],
'indicators': IndicatorFactory
'debug': bool
}
Symbol Object
Passed to on_bar() and on_tick():
{
'name': 'EURUSD',
'bid': 1.0850,
'ask': 1.0852,
'spread': 0.0002,
'close': 1.0851,
'bars': [
{
'open': 1.0840,
'high': 1.0855,
'low': 1.0835,
'close': 1.0850,
'volume': 1000.0,
'time': '2024-01-01T00:00:00'
}
]
}
Trade Signals
Return from on_bar() or on_tick():
# Buy signal
{'action': 'buy', 'volume': 1.0}
# Sell signal
{'action': 'sell', 'volume': 1.0}
# Close all positions
{'action': 'close', 'volume': 0}
# No action
None
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fraq_nettrade_abstractions-0.1.5.tar.gz.
File metadata
- Download URL: fraq_nettrade_abstractions-0.1.5.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70037d364fefc0b30502f2d061258d8608df21fbb3e83171eddfb259a754c76e
|
|
| MD5 |
162010ffc163c990ff8709ca45609b5a
|
|
| BLAKE2b-256 |
05a1c30e1ed4a90005016e43a79a94e76c39b00ba56e525012ed594c022027b3
|
File details
Details for the file fraq_nettrade_abstractions-0.1.5-py3-none-any.whl.
File metadata
- Download URL: fraq_nettrade_abstractions-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d81f03c48fb20747cc4846a9261a7a2d11bcf180d10e054141521ee56c4d849
|
|
| MD5 |
f2339a8948ced61d35ee9d91b569a87a
|
|
| BLAKE2b-256 |
6a60aacfacc5942e44a9cd28afb130c25e0aee23c8a33e187028d5526c90b02e
|