Skip to content

Commit

Permalink
Add bar handlers for subscriber example strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Nov 16, 2024
1 parent f7b9c0e commit 495d07e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/live/databento/databento_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from nautilus_trader.config import TradingNodeConfig
from nautilus_trader.live.node import TradingNode
from nautilus_trader.model.book import OrderBook
from nautilus_trader.model.data import Bar
from nautilus_trader.model.data import OrderBookDeltas
from nautilus_trader.model.data import QuoteTick
from nautilus_trader.model.data import TradeTick
Expand Down Expand Up @@ -250,6 +251,18 @@ def on_trade_tick(self, tick: TradeTick) -> None:
"""
self.log.info(repr(tick), LogColor.CYAN)

def on_bar(self, bar: Bar) -> None:
"""
Actions to be performed when the strategy is running and receives a bar.
Parameters
----------
bar : Bar
The bar received.
"""
self.log.info(repr(bar), LogColor.CYAN)


# Configure and initialize your strategy
strat_config = DataSubscriberConfig(instrument_ids=instrument_ids)
Expand Down
13 changes: 13 additions & 0 deletions examples/live/polymarket/polymarket_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from nautilus_trader.config import TradingNodeConfig
from nautilus_trader.live.node import TradingNode
from nautilus_trader.model.book import OrderBook
from nautilus_trader.model.data import Bar
from nautilus_trader.model.data import OrderBookDeltas
from nautilus_trader.model.data import QuoteTick
from nautilus_trader.model.data import TradeTick
Expand Down Expand Up @@ -256,6 +257,18 @@ def on_trade_tick(self, tick: TradeTick) -> None:
"""
self.log.info(repr(tick), LogColor.CYAN)

def on_bar(self, bar: Bar) -> None:
"""
Actions to be performed when the strategy is running and receives a bar.
Parameters
----------
bar : Bar
The bar received.
"""
self.log.info(repr(bar), LogColor.CYAN)


# Configure and initialize your strategy
strat_config = DataSubscriberConfig(instrument_ids=instrument_ids)
Expand Down
14 changes: 14 additions & 0 deletions examples/live/tardis/tardis_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from nautilus_trader.config import TradingNodeConfig
from nautilus_trader.live.node import TradingNode
from nautilus_trader.model.book import OrderBook
from nautilus_trader.model.data import Bar
from nautilus_trader.model.data import OrderBookDeltas
from nautilus_trader.model.data import QuoteTick
from nautilus_trader.model.data import TradeTick
Expand Down Expand Up @@ -154,6 +155,7 @@ def on_start(self) -> None:
self.subscribe_quote_ticks(instrument_id, client_id=self.client_id)
self.subscribe_trade_ticks(instrument_id, client_id=self.client_id)

# from nautilus_trader.model.data import BarType
# bar_type = BarType.from_str(f"{instrument_id}-10-TICK-LAST-EXTERNAL")
# self.subscribe_bars(bar_type, client_id=self.client_id)

Expand Down Expand Up @@ -233,6 +235,18 @@ def on_trade_tick(self, tick: TradeTick) -> None:
"""
self.log.info(repr(tick), LogColor.CYAN)

def on_bar(self, bar: Bar) -> None:
"""
Actions to be performed when the strategy is running and receives a bar.
Parameters
----------
bar : Bar
The bar received.
"""
self.log.info(repr(bar), LogColor.CYAN)


# Configure and initialize your strategy
strat_config = DataSubscriberConfig(instrument_ids=instrument_ids)
Expand Down

0 comments on commit 495d07e

Please sign in to comment.