Trouble getting started with IB + Nautilus #1245
-
Hi all, I really really like nautilus and what it enables me to do compared to my current setup with backtrader, but I cannot find a way to a working example for using IB's integration :( I managed to get the Live demo from /examples working, but I cannot find anything else anywhere. Basically I want to be able to do thse 3 simple things:
I don't know where to even start so any help is appreciated ! All the best Example Code: from nautilus_trader.adapters.interactive_brokers.common import *
from nautilus_trader.adapters.interactive_brokers.config import *
from nautilus_trader.adapters.interactive_brokers.providers import InteractiveBrokersInstrumentProvider
from nautilus_trader.adapters.interactive_brokers.client.client import InteractiveBrokersClient
from nautilus_trader.msgbus.bus import MessageBus
from nautilus_trader.cache.cache import Cache
from nautilus_trader.common.logging import Logger
from nautilus_trader.common.clock import TestClock
from nautilus_trader.config import LoggingConfig
from nautilus_trader.config import RoutingConfig
from nautilus_trader.model.identifiers import TraderId
from nautilus_trader.config import InstrumentProviderConfig
from nautilus_trader.persistence.catalog import ParquetDataCatalog
from nautilus_trader.persistence.external.core import write_objects
from nautilus_trader.adapters.interactive_brokers.factories import (
get_cached_ib_client, get_cached_interactive_brokers_instrument_provider
)
import asyncio
clock = TestClock()
logger = Logger(clock)
trader_id = TraderId('bt-1')
msgbus = MessageBus(trader_id, clock, logger)
cache = Cache(logger)
contract = IBContract(
secIdType='CRYPTO',
symbol='BTC',
exchange='PAXOS',
#primaryExchange='NASDAQ'
currency='USD'
)
instrument_provider_config = InteractiveBrokersInstrumentProviderConfig(
load_ids=frozenset(["BTC/USD.PAXOS"]),
load_contracts=frozenset([contract]),
)
catalog = ParquetDataCatalog("./catalog/")
gateway_config = InteractiveBrokersGatewayConfig(
start=False,
username="user",
password="pass",
trading_mode="paper",
read_only_api=False,
)
client = get_cached_ib_client(
loop=asyncio.get_event_loop(),
msgbus=msgbus,
cache=cache,
clock=clock,
logger=logger,
host='127.0.0.1',
port=4002,
client_id=2,
gateway=gateway_config
)
instrument_provider = get_cached_interactive_brokers_instrument_provider(
client=client,
config=instrument_provider_config,
logger=logger
)
res = instrument_provider.load_all() Output
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Good point, will update docs/README for this. Was just setting this up recently, so I am pretty familiar with interactive brokers setup, for me it works pretty well and nautilus IB adapter looks really good |
Beta Was this translation helpful? Give feedback.
Best to explore all strategy examples, learn how to use
Strategy
class function and what are common function/patterns there. You can start playing with the nautilus adapters, how to request data, indicators, or print live WS updates. Crypto exchange adapters and their API documentation are , in my opinion, better and easier to use at the beginning to get a good feeling of how everything works. Start by implementing some simple strategies that you understand, and check frontend UI for live updates. For that, best are MM strategies or grids, to see in real-time how algorithm trades and executes orders.