Skip to content

Martingale42/nautilus-dev / skills/nt-trading

nt-trading

Verified

Use when working with strategy logic, order execution, risk management, position/portfolio tracking, or exec algorithms in NautilusTrader.

FileKindSize
SKILL.mdskill md18.0 KB
references/api/.gitkeepother0 B
references/api/accounting.mdmarkdown888 B
references/api/events.mdmarkdown543 B
references/api/execution.mdmarkdown1.3 KB
references/api/orders.mdmarkdown1.8 KB
references/api/portfolio.mdmarkdown380 B
references/api/position.mdmarkdown162 B
references/api/risk.mdmarkdown359 B
references/api/trading.mdmarkdown680 B
references/architecture_patterns.mdmarkdown16.2 KB
references/concepts/.gitkeepother0 B
references/concepts/actors.mdmarkdown14.9 KB
references/concepts/execution.mdmarkdown23.1 KB
references/concepts/orders.mdmarkdown42.6 KB
references/concepts/portfolio.mdmarkdown6.7 KB
references/concepts/positions.mdmarkdown17.2 KB
references/concepts/rust.mdmarkdown16.1 KB
references/concepts/strategies.mdmarkdown25.7 KB
references/examples/.gitkeepother0 B
references/examples/actor_data/README.mdmarkdown653 B
references/examples/actor_data/run_example.pyscript3.9 KB
references/examples/actor_data/strategy.pyscript5.6 KB
references/examples/actor_signals/README.mdmarkdown669 B
references/examples/actor_signals/run_example.pyscript3.9 KB
references/examples/actor_signals/strategy.pyscript4.8 KB
references/examples/crypto_ema_cross_ethusdt_trade_ticks.pyexecutablescript5.3 KB
references/examples/fx_ema_cross_audusd_bars_from_ticks.pyexecutablescript4.2 KB
references/examples/msgbus/README.mdmarkdown1.0 KB
references/examples/msgbus/run_example.pyscript3.9 KB
references/examples/msgbus/strategy.pyscript4.5 KB
references/examples/rust_trading/examples/actors/imbalance/actor.rsscript6.5 KB
references/examples/rust_trading/examples/actors/imbalance/config.rsscript2.8 KB
references/examples/rust_trading/examples/mod.rsscript963 B
references/examples/rust_trading/examples/strategies/ema_cross.rsscript4.9 KB
references/examples/rust_trading/examples/strategies/ema_cross/config.rsscript3.7 KB
references/examples/rust_trading/examples/strategies/ema_cross/strategy.rsscript4.6 KB
references/examples/rust_trading/examples/strategies/grid_mm.rsscript31.0 KB
references/examples/rust_trading/examples/strategies/grid_mm/config.rsscript6.9 KB
references/examples/rust_trading/examples/strategies/grid_mm/strategy.rsscript13.3 KB
references/examples/rust_trading/examples/strategies/mod.rsscript1.1 KB
references/guides/.gitkeepother0 B
references/guides/rust_patterns.mdmarkdown17.2 KB
references/guides/testing.mdmarkdown7.9 KB
references/guides/troubleshooting_rust.mdmarkdown12.3 KB
references/guides/write_rust_actor.mdmarkdown3.9 KB
references/guides/write_rust_strategy.mdmarkdown4.7 KB
templates/.gitkeepother0 B
templates/actor.pyscript2.1 KB
templates/exec_algorithm.pyscript2.4 KB
templates/strategy.pyscript3.8 KB

templates/strategy.py

View on GitHub
# -------------------------------------------------------------------------------------------------
#  NautilusTrader Strategy Template
#
#  Subclass Strategy for components that submit orders and manage positions.
#  For data-only components (no trading), use Actor instead.
# -------------------------------------------------------------------------------------------------

from nautilus_trader.model.data import Bar
from nautilus_trader.model.data import BarType
from nautilus_trader.model.data import QuoteTick
from nautilus_trader.model.data import TradeTick
from nautilus_trader.model.events.order import OrderFilled
from nautilus_trader.model.events.position import PositionChanged
from nautilus_trader.model.events.position import PositionClosed
from nautilus_trader.model.events.position import PositionOpened
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.trading.config import StrategyConfig
from nautilus_trader.trading.strategy import Strategy


class MyStrategyConfig(StrategyConfig, frozen=True):
    """Configuration for MyStrategy."""

    instrument_id: str = None  # e.g. "ETHUSDT-PERP.BINANCE"
    bar_type: str = None  # e.g. "ETHUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL"
    # TODO: Add strategy-specific config parameters


class MyStrategy(Strategy):
    """
    TODO: Describe strategy logic.
    """

    def __init__(self, config: MyStrategyConfig):
        super().__init__(config)
        self.instrument_id = InstrumentId.from_str(config.instrument_id)
        self.bar_type = BarType.from_str(config.bar_type)
        # TODO: Initialize indicators and state

    def on_start(self):
        """Called once when the strategy starts."""
        self.instrument = self.cache.instrument(self.instrument_id)
        if self.instrument is None:
            self.log.error(f"Instrument {self.instrument_id} not found")
            self.stop()
            return

        self.subscribe_bars(self.bar_type)
        # TODO: Subscribe to additional data, register indicators
        # self.register_indicator_for_bars(self.bar_type, self.ema)

    def on_bar(self, bar: Bar):
        """Called on each bar update."""
        # TODO: Implement core trading logic
        #
        # Example order submission:
        #   order = self.order_factory.market(
        #       instrument_id=self.instrument_id,
        #       order_side=OrderSide.BUY,
        #       quantity=self.instrument.make_qty(1.0),
        #   )
        #   self.submit_order(order)
        pass

    def on_quote_tick(self, tick: QuoteTick):
        """Called on each quote tick update."""
        pass

    def on_trade_tick(self, tick: TradeTick):
        """Called on each trade tick update."""
        pass

    def on_order_filled(self, event: OrderFilled):
        """Called when an order is filled."""
        pass

    def on_position_opened(self, event: PositionOpened):
        """Called when a new position is opened."""
        pass

    def on_position_changed(self, event: PositionChanged):
        """Called when a position's quantity or side changes."""
        pass

    def on_position_closed(self, event: PositionClosed):
        """Called when a position is fully closed."""
        pass

    def on_stop(self):
        """Called when the strategy stops. Clean up resources."""
        # TODO: Cancel open orders, optionally close positions
        # self.cancel_all_orders(self.instrument_id)
        # self.close_all_positions(self.instrument_id)
        pass

    def on_reset(self):
        """Called when the strategy is reset. Clear state."""
        # TODO: Reset indicators and state
        pass

    def on_save(self) -> dict[str, bytes]:
        """Return state to persist across restarts."""
        return {}

    def on_load(self, state: dict[str, bytes]) -> None:
        """Restore persisted state."""
        pass
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall