|
| 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.bybit.common.enums import BybitProductType |
| 20 | +from nautilus_trader.adapters.bybit.config import BybitDataClientConfig |
| 21 | +from nautilus_trader.adapters.bybit.config import BybitExecClientConfig |
| 22 | +from nautilus_trader.adapters.bybit.factories import BybitLiveDataClientFactory |
| 23 | +from nautilus_trader.adapters.bybit.factories import BybitLiveExecClientFactory |
| 24 | +from nautilus_trader.config import InstrumentProviderConfig |
| 25 | +from nautilus_trader.config import LiveExecEngineConfig |
| 26 | +from nautilus_trader.config import LoggingConfig |
| 27 | +from nautilus_trader.config import TradingNodeConfig |
| 28 | +from nautilus_trader.examples.strategies.ema_cross_stop_entry import EMACrossStopEntry |
| 29 | +from nautilus_trader.examples.strategies.ema_cross_stop_entry import EMACrossStopEntryConfig |
| 30 | +from nautilus_trader.live.node import TradingNode |
| 31 | +from nautilus_trader.model.data import BarType |
| 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 | +# SPOT/LINEAR |
| 40 | +product_type = BybitProductType.LINEAR |
| 41 | +symbol = f"ETHUSDT-{product_type.value.upper()}" |
| 42 | +trade_size = Decimal("0.010") |
| 43 | + |
| 44 | +# Configure the trading node |
| 45 | +config_node = TradingNodeConfig( |
| 46 | + trader_id=TraderId("TESTER-001"), |
| 47 | + logging=LoggingConfig(log_level="INFO", use_pyo3=True), |
| 48 | + exec_engine=LiveExecEngineConfig( |
| 49 | + reconciliation=True, |
| 50 | + reconciliation_lookback_mins=1440, |
| 51 | + ), |
| 52 | + data_clients={ |
| 53 | + "BYBIT": BybitDataClientConfig( |
| 54 | + api_key=None, # 'BYBIT_API_KEY' env var |
| 55 | + api_secret=None, # 'BYBIT_API_SECRET' env var |
| 56 | + base_url_http=None, # Override with custom endpoint |
| 57 | + instrument_provider=InstrumentProviderConfig(load_all=True), |
| 58 | + product_types=[product_type], |
| 59 | + testnet=False, # If client uses the testnet |
| 60 | + ), |
| 61 | + }, |
| 62 | + exec_clients={ |
| 63 | + "BYBIT": BybitExecClientConfig( |
| 64 | + api_key=None, # 'BYBIT_API_KEY' env var |
| 65 | + api_secret=None, # 'BYBIT_API_SECRET' env var |
| 66 | + base_url_http=None, # Override with custom endpoint |
| 67 | + base_url_ws=None, # Override with custom endpoint |
| 68 | + instrument_provider=InstrumentProviderConfig(load_all=True), |
| 69 | + product_types=[product_type], |
| 70 | + testnet=False, # If client uses the testnet |
| 71 | + ), |
| 72 | + }, |
| 73 | + timeout_connection=30.0, |
| 74 | + timeout_reconciliation=10.0, |
| 75 | + timeout_portfolio=10.0, |
| 76 | + timeout_disconnection=10.0, |
| 77 | + timeout_post_stop=5.0, |
| 78 | +) |
| 79 | + |
| 80 | +# Instantiate the node with a configuration |
| 81 | +node = TradingNode(config=config_node) |
| 82 | + |
| 83 | +# Configure your strategy |
| 84 | +strat_config = EMACrossStopEntryConfig( |
| 85 | + instrument_id=InstrumentId.from_str(f"{symbol}.BYBIT"), |
| 86 | + external_order_claims=[InstrumentId.from_str(f"{symbol}.BYBIT")], |
| 87 | + bar_type=BarType.from_str(f"{symbol}.BYBIT-1-MINUTE-LAST-EXTERNAL"), |
| 88 | + fast_ema_period=10, |
| 89 | + slow_ema_period=20, |
| 90 | + atr_period=20, |
| 91 | + trailing_atr_multiple=3.0, |
| 92 | + trailing_offset=Decimal("0.010"), |
| 93 | + trailing_offset_type="BASIS_POINTS", |
| 94 | + trigger_type="LAST_TRADE", |
| 95 | + trade_size=Decimal("0.010"), |
| 96 | +) |
| 97 | +# Instantiate your strategy |
| 98 | +strategy = EMACrossStopEntry(config=strat_config) |
| 99 | + |
| 100 | +# Add your strategies and modules |
| 101 | +node.trader.add_strategy(strategy) |
| 102 | + |
| 103 | +# Register your client factories with the node (can take user defined factories) |
| 104 | +node.add_data_client_factory("BYBIT", BybitLiveDataClientFactory) |
| 105 | +node.add_exec_client_factory("BYBIT", BybitLiveExecClientFactory) |
| 106 | +node.build() |
| 107 | + |
| 108 | + |
| 109 | +# Stop and dispose of the node with SIGINT/CTRL+C |
| 110 | +if __name__ == "__main__": |
| 111 | + try: |
| 112 | + node.run() |
| 113 | + finally: |
| 114 | + node.dispose() |
0 commit comments