|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# ------------------------------------------------------------------------------------------------- |
| 3 | +# Copyright (C) 2015-2024 Nautech Systems Pty Ltd. All rights reserved. |
| 4 | +# https://nautechsystems.io |
| 5 | +# |
| 6 | +# Licensed under the GNU Lesser General Public License Version 3.0 (the "License"); |
| 7 | +# You may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# ------------------------------------------------------------------------------------------------- |
| 16 | + |
| 17 | +from decimal import Decimal |
| 18 | + |
| 19 | +from nautilus_trader.adapters.binance.common.enums import BinanceAccountType |
| 20 | +from nautilus_trader.adapters.binance.config import BinanceDataClientConfig |
| 21 | +from nautilus_trader.adapters.binance.config import BinanceExecClientConfig |
| 22 | +from nautilus_trader.adapters.binance.factories import BinanceLiveDataClientFactory |
| 23 | +from nautilus_trader.adapters.binance.factories import BinanceLiveExecClientFactory |
| 24 | +from nautilus_trader.config import CacheConfig |
| 25 | +from nautilus_trader.config import InstrumentProviderConfig |
| 26 | +from nautilus_trader.config import LiveExecEngineConfig |
| 27 | +from nautilus_trader.config import LoggingConfig |
| 28 | +from nautilus_trader.config import TradingNodeConfig |
| 29 | +from nautilus_trader.examples.strategies.orderbook_imbalance_rust import OrderBookImbalance |
| 30 | +from nautilus_trader.examples.strategies.orderbook_imbalance_rust import OrderBookImbalanceConfig |
| 31 | +from nautilus_trader.live.node import TradingNode |
| 32 | +from nautilus_trader.model.identifiers import InstrumentId |
| 33 | +from nautilus_trader.model.identifiers import TraderId |
| 34 | + |
| 35 | + |
| 36 | +# *** THIS IS A TEST STRATEGY WITH NO ALPHA ADVANTAGE WHATSOEVER. *** |
| 37 | +# *** IT IS NOT INTENDED TO BE USED TO TRADE LIVE WITH REAL MONEY. *** |
| 38 | + |
| 39 | + |
| 40 | +# Configure the trading node |
| 41 | +config_node = TradingNodeConfig( |
| 42 | + trader_id=TraderId("TESTER-001"), |
| 43 | + logging=LoggingConfig( |
| 44 | + log_level="INFO", |
| 45 | + # log_level_file="DEBUG", |
| 46 | + # log_file_format="json", |
| 47 | + ), |
| 48 | + exec_engine=LiveExecEngineConfig( |
| 49 | + reconciliation=True, |
| 50 | + reconciliation_lookback_mins=1440, |
| 51 | + filter_position_reports=True, |
| 52 | + ), |
| 53 | + cache=CacheConfig( |
| 54 | + database=None, |
| 55 | + timestamps_as_iso8601=True, |
| 56 | + flush_on_start=False, |
| 57 | + ), |
| 58 | + # snapshot_orders=True, |
| 59 | + # snapshot_positions=True, |
| 60 | + # snapshot_positions_interval=5.0, |
| 61 | + data_clients={ |
| 62 | + "BINANCE": BinanceDataClientConfig( |
| 63 | + api_key=None, # 'BINANCE_API_KEY' env var |
| 64 | + api_secret=None, # 'BINANCE_API_SECRET' env var |
| 65 | + account_type=BinanceAccountType.SPOT, |
| 66 | + base_url_http=None, # Override with custom endpoint |
| 67 | + base_url_ws=None, # Override with custom endpoint |
| 68 | + us=False, # If client is for Binance US |
| 69 | + testnet=False, # If client uses the testnet |
| 70 | + instrument_provider=InstrumentProviderConfig(load_all=True), |
| 71 | + ), |
| 72 | + }, |
| 73 | + exec_clients={ |
| 74 | + "BINANCE": BinanceExecClientConfig( |
| 75 | + api_key=None, # 'BINANCE_API_KEY' env var |
| 76 | + api_secret=None, # 'BINANCE_API_SECRET' env var |
| 77 | + account_type=BinanceAccountType.SPOT, |
| 78 | + base_url_http=None, # Override with custom endpoint |
| 79 | + base_url_ws=None, # Override with custom endpoint |
| 80 | + us=False, # If client is for Binance US |
| 81 | + testnet=False, # If client uses the testnet |
| 82 | + instrument_provider=InstrumentProviderConfig(load_all=True), |
| 83 | + ), |
| 84 | + }, |
| 85 | + timeout_connection=20.0, |
| 86 | + timeout_reconciliation=10.0, |
| 87 | + timeout_portfolio=10.0, |
| 88 | + timeout_disconnection=10.0, |
| 89 | + timeout_post_stop=5.0, |
| 90 | +) |
| 91 | + |
| 92 | +# Instantiate the node with a configuration |
| 93 | +node = TradingNode(config=config_node) |
| 94 | + |
| 95 | +# Configure your strategy |
| 96 | +strat_config = OrderBookImbalanceConfig( |
| 97 | + instrument_id=InstrumentId.from_str("ETHUSDT.BINANCE"), |
| 98 | + external_order_claims=[InstrumentId.from_str("ETHUSDT.BINANCE")], |
| 99 | + max_trade_size=Decimal("0.010"), |
| 100 | +) |
| 101 | + |
| 102 | +# Instantiate your strategy |
| 103 | +strategy = OrderBookImbalance(config=strat_config) |
| 104 | + |
| 105 | +# Add your strategies and modules |
| 106 | +node.trader.add_strategy(strategy) |
| 107 | + |
| 108 | +# Register your client factories with the node (can take user defined factories) |
| 109 | +node.add_data_client_factory("BINANCE", BinanceLiveDataClientFactory) |
| 110 | +node.add_exec_client_factory("BINANCE", BinanceLiveExecClientFactory) |
| 111 | +node.build() |
| 112 | + |
| 113 | + |
| 114 | +# Stop and dispose of the node with SIGINT/CTRL+C |
| 115 | +if __name__ == "__main__": |
| 116 | + try: |
| 117 | + node.run() |
| 118 | + finally: |
| 119 | + node.dispose() |
0 commit comments