Skip to main content

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

Running Your Strategy

  1. Save your strategy to a .py file
  2. Open FraQ application
  3. Load your Python strategy file
  4. Run backtest

Debugging

from fraq_nettrade_abstractions import Strategy, enable_debugger

class MyStrategy(Strategy):
    def on_start(self, context):
        enable_debugger()  # Wait for VS Code debugger
        # Your strategy code with breakpoints

Debug workflow:

  1. Start FraQ with --debug flag
  2. Attach VS Code to port 5678
  3. Set breakpoints in your strategy
  4. Press Enter in FraQ console

API Reference

Strategy Class

Base class for all trading strategies.

Methods to implement:

  • on_start(context) - Called once when backtest starts
  • on_bar(symbol, index) - Called on each bar (required)
  • on_tick(symbol) - Called on each tick (optional)
  • on_stop() - Called when backtest ends (optional)

Context Object

Passed to on_start():

{
    'account': {
        'balance': float,
        'equity': float,
        'margin_used': float,
        'margin_available': float
    },
    'symbols': [
        {
            'name': str,
            'bid': float,
            'ask': float,
        }
    ],
    'indicators': IndicatorFactory
}

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

Built-in Indicators

Access via context['indicators'] in on_start():

  • sma(period) - Simple Moving Average
  • ema(period) - Exponential Moving Average
  • rsi(period) - Relative Strength Index
  • macd(fast, slow, signal) - MACD
  • bollinger(period, stddev) - Bollinger Bands

Examples

See the examples directory for complete strategy examples.

License

MIT License - see LICENSE file for details

Support

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

fraq_nettrade_abstractions-0.1.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fraq_nettrade_abstractions-0.1.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file fraq_nettrade_abstractions-0.1.2.tar.gz.

File metadata

File hashes

Hashes for fraq_nettrade_abstractions-0.1.2.tar.gz
Algorithm Hash digest
SHA256 608b8b84aa9612cb8b139d3a2a4a150ad2cbeb8cde0935e79c22aef1a635b111
MD5 30986788d9ef2c7c7f615cc48350c36d
BLAKE2b-256 b88e3539b15856785e8ee0ed374d8d7715ec586516af8274a2021e208566d5d3

See more details on using hashes here.

File details

Details for the file fraq_nettrade_abstractions-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fraq_nettrade_abstractions-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c2b3f43bc9ed69942fc939e2a603c9cb2f324d89f43b6a6c979b27bd50492805
MD5 393b2f61d5418ec5d1f53044a2d7e99a
BLAKE2b-256 da4b58c0591b660c87ee3a014f55b2a5bfac10e80c2abaff68a1fcd4a3aba6cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page