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

references/examples/actor_signals/strategy.py

View on GitHub
# -------------------------------------------------------------------------------------------------
#  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
#  https://nautechsystems.io
#
#  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
#  You may not use this file except in compliance with the License.
#  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
# -------------------------------------------------------------------------------------------------

import types

from nautilus_trader.common.enums import LogColor
from nautilus_trader.config import StrategyConfig
from nautilus_trader.core.datetime import unix_nanos_to_dt
from nautilus_trader.model.data import Bar
from nautilus_trader.model.data import BarType
from nautilus_trader.model.instruments import Instrument
from nautilus_trader.trading.strategy import Strategy


class DemoStrategyConfig(StrategyConfig, frozen=True):
    instrument: Instrument
    bar_type: BarType


# Signal names for price extremes
signals = types.SimpleNamespace()
signals.NEW_HIGHEST_PRICE = "NewHighestPriceReached"
signals.NEW_LOWEST_PRICE = "NewLowestPriceReached"


class DemoStrategy(Strategy):
    """
    A demonstration strategy showing how to use Actor-Based Signal messaging.

    This example demonstrates the simplest messaging approach in NautilusTrader:
    - Using signals for lightweight notifications (price extremes in this case)
    - Publishing signals with single string values
    - Subscribing to signals and handling them in on_signal

    Two signals are used:
    - NewHighestPriceReached: Published when a new maximum price is detected
    - NewLowestPriceReached: Published when a new minimum price is detected

    """

    def __init__(self, config: DemoStrategyConfig):
        super().__init__(config)

        # Initialize price tracking
        self.highest_price = float("-inf")
        self.lowest_price = float("inf")

    def on_start(self):
        # Subscribe to market data
        self.subscribe_bars(self.config.bar_type)
        self.log.info(f"Subscribed to {self.config.bar_type}", color=LogColor.YELLOW)

        # Subscribe to signals - each signal subscription will trigger on_signal when that signal is published
        self.subscribe_signal(signals.NEW_HIGHEST_PRICE)
        self.subscribe_signal(signals.NEW_LOWEST_PRICE)
        self.log.info("Subscribed to price extreme signals", color=LogColor.YELLOW)

    def on_bar(self, bar: Bar):
        # Check for new highest price
        if bar.close > self.highest_price:
            self.highest_price = bar.close
            self.log.info(f"New highest price detected: {bar.close}")
            # Publish a lightweight signal (can only contain a single value of type str/int/float)
            self.publish_signal(
                name=signals.NEW_HIGHEST_PRICE,  # Signal name
                value=signals.NEW_HIGHEST_PRICE,  # Signal value
                ts_event=bar.ts_event,
            )

        # Check for new lowest price
        if bar.close < self.lowest_price:
            self.lowest_price = bar.close
            self.log.info(f"New lowest price detected: {bar.close}")
            # Publish a lightweight signal (can only contain a single value of type str/int/float)
            self.publish_signal(
                name=signals.NEW_LOWEST_PRICE,
                value=signals.NEW_LOWEST_PRICE,  # Using same string as name for simplicity
                ts_event=bar.ts_event,
            )

    def on_signal(self, signal):
        """
        Handle incoming signals.

        This method is automatically called when any signal we're subscribed to is published.
        Important: In the signal handler, we can only match against signal.value
        (signal.name is not accessible in the handler).

        """
        match signal.value:
            case signals.NEW_HIGHEST_PRICE:
                self.log.info(
                    f"New highest price was reached. | "
                    f"Signal value: {signal.value} | "
                    f"Signal time: {unix_nanos_to_dt(signal.ts_event)}",
                    color=LogColor.GREEN,
                )
            case signals.NEW_LOWEST_PRICE:
                self.log.info(
                    f"New lowest price was reached. | "
                    f"Signal value: {signal.value} | "
                    f"Signal time: {unix_nanos_to_dt(signal.ts_event)}",
                    color=LogColor.RED,
                )

    def on_stop(self):
        self.log.info("Strategy stopped.")
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