├── .coveragerc ├── .github ├── dependabot.yml └── workflows │ └── main.yml ├── .gitignore ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── dev_requirements.txt ├── octobot_trading ├── __init__.py ├── api │ ├── __init__.py │ ├── channels.py │ ├── contracts.py │ ├── exchange.py │ ├── modes.py │ ├── orders.py │ ├── portfolio.py │ ├── positions.py │ ├── profitability.py │ ├── storage.py │ ├── symbol_data.py │ ├── trader.py │ └── trades.py ├── constants.py ├── enums.py ├── errors.py ├── exchange_channel.py ├── exchange_data │ ├── __init__.py │ ├── contracts │ │ ├── __init__.py │ │ ├── contract_factory.py │ │ ├── future_contract.py │ │ └── margin_contract.py │ ├── exchange_symbol_data.py │ ├── exchange_symbols_data.py │ ├── funding │ │ ├── __init__.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── funding.py │ │ │ ├── funding_updater.py │ │ │ └── funding_updater_simulator.py │ │ └── funding_manager.py │ ├── kline │ │ ├── __init__.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── kline.py │ │ │ ├── kline_updater.py │ │ │ └── kline_updater_simulator.py │ │ └── kline_manager.py │ ├── ohlcv │ │ ├── __init__.py │ │ ├── candles_adapter.py │ │ ├── candles_manager.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── ohlcv.py │ │ │ ├── ohlcv_updater.py │ │ │ └── ohlcv_updater_simulator.py │ │ └── preloaded_candles_manager.py │ ├── order_book │ │ ├── __init__.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── order_book.py │ │ │ ├── order_book_updater.py │ │ │ └── order_book_updater_simulator.py │ │ └── order_book_manager.py │ ├── prices │ │ ├── __init__.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── price.py │ │ │ ├── prices_updater.py │ │ │ └── prices_updater_simulator.py │ │ ├── price_events_manager.py │ │ └── prices_manager.py │ ├── recent_trades │ │ ├── __init__.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── recent_trade.py │ │ │ ├── recent_trade_updater.py │ │ │ └── recent_trade_updater_simulator.py │ │ └── recent_trades_manager.py │ └── ticker │ │ ├── __init__.py │ │ ├── channel │ │ ├── __init__.py │ │ ├── ticker.py │ │ ├── ticker_updater.py │ │ └── ticker_updater_simulator.py │ │ └── ticker_manager.py ├── exchanges │ ├── __init__.py │ ├── abstract_exchange.py │ ├── abstract_websocket_exchange.py │ ├── adapters │ │ ├── __init__.py │ │ └── abstract_adapter.py │ ├── config │ │ ├── __init__.py │ │ ├── backtesting_exchange_config.py │ │ ├── exchange_config_data.py │ │ ├── exchange_credentials_data.py │ │ └── proxy_config.py │ ├── connectors │ │ ├── __init__.py │ │ ├── ccxt │ │ │ ├── __init__.py │ │ │ ├── ccxt_adapter.py │ │ │ ├── ccxt_client_util.py │ │ │ ├── ccxt_clients_cache.py │ │ │ ├── ccxt_connector.py │ │ │ ├── ccxt_websocket_connector.py │ │ │ ├── constants.py │ │ │ └── enums.py │ │ └── simulator │ │ │ ├── __init__.py │ │ │ ├── ccxt_client_simulation.py │ │ │ ├── exchange_simulator_adapter.py │ │ │ └── exchange_simulator_connector.py │ ├── exchange_builder.py │ ├── exchange_channels.py │ ├── exchange_details.py │ ├── exchange_factory.py │ ├── exchange_manager.py │ ├── exchange_websocket_factory.py │ ├── exchanges.py │ ├── implementations │ │ ├── __init__.py │ │ ├── default_rest_exchange.py │ │ ├── default_websocket_exchange.py │ │ └── exchange_simulator.py │ ├── traders │ │ ├── __init__.py │ │ ├── trader.py │ │ └── trader_simulator.py │ ├── types │ │ ├── __init__.py │ │ ├── rest_exchange.py │ │ └── websocket_exchange.py │ └── util │ │ ├── __init__.py │ │ ├── exchange_market_status_fixer.py │ │ ├── exchange_util.py │ │ ├── symbol_details.py │ │ └── websockets_util.py ├── modes │ ├── __init__.py │ ├── abstract_trading_mode.py │ ├── channel │ │ ├── __init__.py │ │ ├── abstract_mode_consumer.py │ │ ├── abstract_mode_producer.py │ │ └── mode.py │ ├── mode_activity.py │ ├── mode_config.py │ ├── modes_factory.py │ ├── modes_util.py │ ├── script_keywords │ │ ├── __init__.py │ │ ├── basic_keywords │ │ │ ├── __init__.py │ │ │ ├── account_balance.py │ │ │ ├── amount.py │ │ │ ├── configuration.py │ │ │ ├── position.py │ │ │ ├── price.py │ │ │ ├── run_persistence.py │ │ │ ├── trading_signals.py │ │ │ └── user_inputs.py │ │ ├── context_management.py │ │ └── dsl │ │ │ ├── __init__.py │ │ │ ├── quantity.py │ │ │ └── values.py │ └── scripted_trading_mode │ │ ├── __init__.py │ │ └── abstract_scripted_trading_mode.py ├── octobot_channel_consumer.py ├── personal_data │ ├── __init__.py │ ├── exchange_personal_data.py │ ├── orders │ │ ├── __init__.py │ │ ├── active_order_swap_strategies │ │ │ ├── __init__.py │ │ │ ├── active_order_swap_strategy.py │ │ │ ├── stop_first_active_order_swap_strategy.py │ │ │ └── take_profit_first_active_order_swap_strategy.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── orders.py │ │ │ ├── orders_updater.py │ │ │ └── orders_updater_simulator.py │ │ ├── decimal_order_adapter.py │ │ ├── groups │ │ │ ├── __init__.py │ │ │ ├── balanced_take_profit_and_stop_order_group.py │ │ │ ├── group_util.py │ │ │ ├── one_cancels_the_other_order_group.py │ │ │ └── trailing_on_filled_tp_balanced_order_group.py │ │ ├── order.py │ │ ├── order_adapter.py │ │ ├── order_factory.py │ │ ├── order_group.py │ │ ├── order_state.py │ │ ├── order_util.py │ │ ├── orders_manager.py │ │ ├── orders_storage_operations.py │ │ ├── states │ │ │ ├── __init__.py │ │ │ ├── cancel_order_state.py │ │ │ ├── close_order_state.py │ │ │ ├── fill_order_state.py │ │ │ ├── open_order_state.py │ │ │ ├── order_state_factory.py │ │ │ ├── pending_creation_chained_order_state.py │ │ │ └── pending_creation_order_state.py │ │ ├── trailing_profiles │ │ │ ├── __init__.py │ │ │ ├── filled_take_profit_trailing_profile.py │ │ │ ├── trailing_price_step.py │ │ │ ├── trailing_profile.py │ │ │ ├── trailing_profile_factory.py │ │ │ └── trailing_profile_types.py │ │ ├── triggers │ │ │ ├── __init__.py │ │ │ ├── base_trigger.py │ │ │ └── price_trigger.py │ │ └── types │ │ │ ├── __init__.py │ │ │ ├── limit │ │ │ ├── __init__.py │ │ │ ├── buy_limit_order.py │ │ │ ├── limit_order.py │ │ │ ├── sell_limit_order.py │ │ │ ├── stop_loss_limit_order.py │ │ │ ├── stop_loss_order.py │ │ │ ├── take_profit_limit_order.py │ │ │ └── take_profit_order.py │ │ │ ├── market │ │ │ ├── __init__.py │ │ │ ├── buy_market_order.py │ │ │ ├── market_order.py │ │ │ └── sell_market_order.py │ │ │ ├── trailing │ │ │ ├── __init__.py │ │ │ ├── trailing_stop_limit_order.py │ │ │ └── trailing_stop_order.py │ │ │ ├── unknown_order.py │ │ │ └── unsupported_order.py │ ├── portfolios │ │ ├── __init__.py │ │ ├── asset.py │ │ ├── assets │ │ │ ├── __init__.py │ │ │ ├── future_asset.py │ │ │ ├── margin_asset.py │ │ │ └── spot_asset.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── balance.py │ │ │ ├── balance_updater.py │ │ │ └── balance_updater_simulator.py │ │ ├── history │ │ │ ├── __init__.py │ │ │ ├── historical_asset_value.py │ │ │ ├── historical_asset_value_factory.py │ │ │ └── historical_portfolio_value_manager.py │ │ ├── portfolio.py │ │ ├── portfolio_factory.py │ │ ├── portfolio_manager.py │ │ ├── portfolio_profitability.py │ │ ├── portfolio_util.py │ │ ├── portfolio_value_holder.py │ │ ├── sub_portfolio.py │ │ ├── sub_portfolio_data.py │ │ ├── types │ │ │ ├── __init__.py │ │ │ ├── future_portfolio.py │ │ │ ├── margin_portfolio.py │ │ │ └── spot_portfolio.py │ │ └── value_converter.py │ ├── positions │ │ ├── __init__.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── positions.py │ │ │ ├── positions_updater.py │ │ │ └── positions_updater_simulator.py │ │ ├── position.py │ │ ├── position_factory.py │ │ ├── position_state.py │ │ ├── position_util.py │ │ ├── positions_manager.py │ │ ├── states │ │ │ ├── __init__.py │ │ │ ├── active_position_state.py │ │ │ ├── idle_position_state.py │ │ │ ├── liquidate_position_state.py │ │ │ └── position_state_factory.py │ │ └── types │ │ │ ├── __init__.py │ │ │ ├── inverse_position.py │ │ │ └── linear_position.py │ ├── state.py │ ├── trades │ │ ├── __init__.py │ │ ├── channel │ │ │ ├── __init__.py │ │ │ ├── trades.py │ │ │ └── trades_updater.py │ │ ├── trade.py │ │ ├── trade_factory.py │ │ ├── trade_pnl.py │ │ ├── trades_manager.py │ │ └── trades_util.py │ └── transactions │ │ ├── __init__.py │ │ ├── transaction.py │ │ ├── transaction_factory.py │ │ ├── transactions_manager.py │ │ └── types │ │ ├── __init__.py │ │ ├── blockchain_transaction.py │ │ ├── fee_transaction.py │ │ ├── realised_pnl_transaction.py │ │ └── transfer_transaction.py ├── signals │ ├── __init__.py │ ├── channel │ │ ├── __init__.py │ │ ├── remote_trading_signal.py │ │ ├── remote_trading_signal_channel_factory.py │ │ └── signal_producer.py │ ├── signal_creation.py │ ├── trading_signal_bundle_builder.py │ └── util.py ├── storage │ ├── __init__.py │ ├── abstract_storage.py │ ├── candles_storage.py │ ├── orders_storage.py │ ├── portfolio_storage.py │ ├── storage_manager.py │ ├── trades_storage.py │ ├── transactions_storage.py │ └── util.py ├── supervisors │ ├── __init__.py │ ├── abstract_portfolio_supervisor.py │ └── abstract_supervisor.py └── util │ ├── __init__.py │ ├── config_util.py │ ├── initializable.py │ ├── initialization_util.py │ ├── simulator_updater_utils.py │ └── test_tools │ ├── __init__.py │ ├── exchange_data.py │ ├── exchanges_test_tools.py │ ├── spot_rest_exchange_test_tools.py │ └── websocket_test_tools.py ├── requirements.txt ├── setup.py ├── standard.rc ├── tests ├── __init__.py ├── api │ ├── __init__.py │ ├── test_channels.py │ ├── test_exchange.py │ ├── test_modes.py │ ├── test_orders.py │ ├── test_portfolio.py │ ├── test_profitability.py │ ├── test_symbol_data.py │ ├── test_trader.py │ └── test_trades.py ├── cli │ └── __init__.py ├── exchange_data │ ├── __init__.py │ ├── contracts │ │ ├── __init__.py │ │ ├── test_future_contract.py │ │ └── test_margin_contract.py │ ├── funding │ │ ├── __init__.py │ │ └── test_funding_manager.py │ ├── kline │ │ ├── __init__.py │ │ └── test_kline_manager.py │ ├── ohlcv │ │ ├── __init__.py │ │ ├── test_candles_adapter.py │ │ └── test_candles_manager.py │ ├── order_book │ │ ├── __init__.py │ │ └── test_order_book_manager.py │ ├── prices │ │ ├── __init__.py │ │ ├── test_price_events_manager.py │ │ └── test_prices_manager.py │ ├── recent_trades │ │ ├── __init__.py │ │ └── test_recent_trades_manager.py │ ├── test_exchange_symbols_data.py │ └── ticker │ │ ├── __init__.py │ │ └── test_ticker_manager.py ├── exchanges │ ├── __init__.py │ ├── connectors │ │ ├── __init__.py │ │ └── ccxt │ │ │ ├── __init__.py │ │ │ ├── mock_exchanges_data.py │ │ │ └── test_ccxt_connector.py │ ├── implementations │ │ ├── __init__.py │ │ ├── test_default_rest_exchange.py │ │ └── test_default_websocket_exchange.py │ ├── test_abstract_exchange.py │ ├── test_abstract_websocket_exchange.py │ ├── test_exchange_builder.py │ ├── test_exchange_config_data.py │ ├── test_exchange_factory.py │ ├── test_exchange_manager.py │ ├── test_exchange_simulator.py │ ├── test_exchanges.py │ ├── traders │ │ ├── __init__.py │ │ └── test_trader.py │ ├── types │ │ ├── __init__.py │ │ └── test_websocket_exchange.py │ └── util │ │ ├── __init__.py │ │ ├── test_exchange_market_status_fixer.py │ │ └── test_exchange_util.py ├── modes │ ├── __init__.py │ ├── script_keywords │ │ ├── __init__.py │ │ ├── basic_keywords │ │ │ ├── __init__.py │ │ │ ├── test_account_balance.py │ │ │ ├── test_amount.py │ │ │ ├── test_position.py │ │ │ └── test_price.py │ │ └── dsl │ │ │ ├── __init__.py │ │ │ └── test_quantity.py │ ├── test_abstract_mode_consumer.py │ ├── test_abstract_trading_mode.py │ └── test_modes_util.py ├── personal_data │ ├── __init__.py │ ├── orders │ │ ├── __init__.py │ │ ├── active_order_swap_strategies │ │ │ ├── __init__.py │ │ │ ├── test_active_order_swap_strategy.py │ │ │ ├── test_stop_first_active_order_swap_strategy.py │ │ │ └── test_take_profit_first_active_order_swap_strategy.py │ │ ├── groups │ │ │ ├── __init__.py │ │ │ ├── test_balanced_take_profit_and_stop_order_group.py │ │ │ ├── test_group_util.py │ │ │ ├── test_one_cancels_the_other_order_group.py │ │ │ └── test_trailing_on_filled_tp_balanced_order_group.py │ │ ├── states │ │ │ ├── __init__.py │ │ │ ├── test_cancel_order_state.py │ │ │ ├── test_close_order_state.py │ │ │ ├── test_fill_order_state.py │ │ │ ├── test_open_order_state.py │ │ │ ├── test_order_state.py │ │ │ ├── test_order_state_factory.py │ │ │ ├── test_pending_creation_chained_order_state.py │ │ │ └── test_pending_creation_order_state.py │ │ ├── test_decimal_order_adapter.py │ │ ├── test_double_filled_order.py │ │ ├── test_order.py │ │ ├── test_order_adapter.py │ │ ├── test_order_factory.py │ │ ├── test_order_util.py │ │ ├── test_orders_manager.py │ │ ├── test_orders_storage_operations.py │ │ ├── trailing_profiles │ │ │ ├── __init__.py │ │ │ ├── test_filled_take_profit_trailing_profile.py │ │ │ └── test_trailing_profile_factory.py │ │ ├── triggers │ │ │ ├── __init__.py │ │ │ ├── test_base_trigger.py │ │ │ └── test_price_trigger.py │ │ └── types │ │ │ ├── __init__.py │ │ │ ├── limit │ │ │ ├── __init__.py │ │ │ ├── test_buy_limit_order.py │ │ │ ├── test_limit_order.py │ │ │ ├── test_sell_limit_order.py │ │ │ ├── test_stop_loss_limit_order.py │ │ │ ├── test_stop_loss_order.py │ │ │ ├── test_take_profit_limit_order.py │ │ │ └── test_take_profit_order.py │ │ │ ├── market │ │ │ ├── __init__.py │ │ │ ├── test_buy_market_order.py │ │ │ └── test_sell_market_order.py │ │ │ ├── test_unknown_order.py │ │ │ └── trailing │ │ │ ├── __init__.py │ │ │ ├── test_trailing_stop_limit_order.py │ │ │ └── test_trailing_stop_order.py │ ├── portfolios │ │ ├── __init__.py │ │ ├── assets │ │ │ ├── __init__.py │ │ │ ├── test_future_asset.py │ │ │ ├── test_margin_asset.py │ │ │ └── test_spot_asset.py │ │ ├── history │ │ │ ├── __init__.py │ │ │ ├── test_historical_asset_value_factory.py │ │ │ └── test_historical_portfolio_value_manager.py │ │ ├── test_asset.py │ │ ├── test_portfolio.py │ │ ├── test_portfolio_manager.py │ │ ├── test_portfolio_profitability.py │ │ ├── test_portfolio_util.py │ │ ├── test_portfolio_value_holder.py │ │ ├── test_sub_portfolio_data.py │ │ ├── test_value_converter.py │ │ └── types │ │ │ ├── __init__.py │ │ │ ├── test_future_portfolio.py │ │ │ ├── test_margin_portfolio.py │ │ │ └── test_spot_portfolio.py │ ├── positions │ │ ├── __init__.py │ │ ├── channel │ │ │ └── __init__.py │ │ ├── states │ │ │ └── __init__.py │ │ ├── test_position.py │ │ ├── test_position_factory.py │ │ ├── test_positions_manager.py │ │ └── types │ │ │ ├── __init__.py │ │ │ ├── test_inverse_position.py │ │ │ └── test_linear_position.py │ ├── trades │ │ ├── __init__.py │ │ ├── test_trade_factory.py │ │ ├── test_trade_manager.py │ │ ├── test_trade_pnl.py │ │ └── test_trade_util.py │ └── transactions │ │ ├── __init__.py │ │ ├── test_transaction_factory.py │ │ └── test_transactions_manager.py ├── signals │ ├── __init__.py │ ├── test_trading_signal_bundle_builder.py │ └── test_util.py ├── static │ ├── config.json │ └── profile.json ├── test_utils │ ├── __init__.py │ ├── order_util.py │ └── random_numbers.py └── util │ ├── __init__.py │ └── test_config_util.py └── tests_additional ├── __init__.py └── real_exchanges ├── .env.template ├── __init__.py ├── real_exchange_tester.py ├── real_futures_exchange_tester.py ├── test_ascendex.py ├── test_binance.py ├── test_binance_futures.py ├── test_bingx.py ├── test_bitfinex.py ├── test_bitget.py ├── test_bithumb.py ├── test_bitmart.py ├── test_bitmex.py ├── test_bitso.py ├── test_bitstamp.py ├── test_bybit.py ├── test_bybit_futures.py ├── test_coinbase.py ├── test_coinex.py ├── test_cryptocom.py ├── test_gateio.py ├── test_hitbtc.py ├── test_hollaex.py ├── test_htx.py ├── test_hyperliquid.py ├── test_kraken.py ├── test_kucoin.py ├── test_kucoin_futures.py ├── test_mexc.py ├── test_ndax.py ├── test_okcoin.py ├── test_okx.py ├── test_okx_futures.py ├── test_phemex.py ├── test_poloniex.py ├── test_upbit.py └── test_wavesexchange.py /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | octobot_trading/cli/* 4 | octobot_trading/api/* 5 | octobot_trading/util/test_tools/* 6 | tests/* 7 | tests_additional/* 8 | tentacles/* 9 | logs/* 10 | backtesting/* 11 | demo.py 12 | setup.py 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: pip 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | open-pull-requests-limit: 10 8 | allow: 9 | # - dependency-name: "OctoBot*" 10 | # - dependency-name: "cython" 11 | # - dependency-name: "numpy" 12 | # - dependency-name: "ccxt" 13 | - dependency-name: "websockets" 14 | # - dependency-name: "sortedcontainers" 15 | reviewers: 16 | - Herklos 17 | - GuillaumeDSM 18 | assignees: 19 | - Herklos 20 | - GuillaumeDSM 21 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: OctoBot-Trading-CI 2 | on: 3 | push: 4 | branches: 5 | - 'master' 6 | tags: 7 | - '*' 8 | pull_request: 9 | 10 | jobs: 11 | lint: 12 | uses: Drakkar-Software/.github/.github/workflows/python3_lint_workflow.yml@master 13 | with: 14 | project_main_package: octobot_trading 15 | 16 | tests: 17 | needs: lint 18 | uses: Drakkar-Software/.github/.github/workflows/python3_tests_workflow.yml@master 19 | secrets: 20 | COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} 21 | http_proxy: ${{ secrets.EXCHANGE_HTTP_PROXY }} 22 | 23 | publish: 24 | needs: tests 25 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 26 | uses: Drakkar-Software/.github/.github/workflows/python3_sdist_workflow.yml@master 27 | secrets: 28 | PYPI_OFFICIAL_UPLOAD_URL: ${{ secrets.PYPI_OFFICIAL_UPLOAD_URL }} 29 | PYPI_USERNAME: __token__ 30 | PYPI_PASSWORD: ${{ secrets.PYPI_TOKEN }} 31 | 32 | notify: 33 | if: ${{ failure() }} 34 | needs: 35 | - lint 36 | - tests 37 | - publish 38 | uses: Drakkar-Software/.github/.github/workflows/failure_notify_workflow.yml@master 39 | secrets: 40 | DISCORD_GITHUB_WEBHOOK: ${{ secrets.DISCORD_GITHUB_WEBHOOK }} 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | *.c 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .coverage 43 | .coverage.* 44 | .cache 45 | nosetests.xml 46 | coverage.xml 47 | *.cover 48 | .hypothesis/ 49 | .pytest_cache/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | local_settings.py 58 | db.sqlite3 59 | 60 | # Flask stuff: 61 | instance/ 62 | .webassets-cache 63 | 64 | # Scrapy stuff: 65 | .scrapy 66 | 67 | # Sphinx documentation 68 | docs/_build/ 69 | 70 | # PyBuilder 71 | target/ 72 | 73 | # Jupyter Notebook 74 | .ipynb_checkpoints 75 | 76 | # pyenv 77 | .python-version 78 | 79 | # celery beat schedule file 80 | celerybeat-schedule 81 | 82 | # SageMath parsed files 83 | *.sage.py 84 | 85 | # Environments 86 | .env 87 | .venv 88 | env/ 89 | venv/ 90 | ENV/ 91 | env.bak/ 92 | venv.bak/ 93 | 94 | # Spyder project settings 95 | .spyderproject 96 | .spyproject 97 | 98 | # Rope project settings 99 | .ropeproject 100 | 101 | # mkdocs documentation 102 | /site 103 | 104 | # mypy 105 | .mypy_cache/ 106 | 107 | # OctoBot 108 | .idea 109 | cython_debug 110 | logs 111 | backtesting/data/*.data 112 | tentacles 113 | user 114 | 115 | tests/static/tentacles.zip 116 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.8-slim-stretch 2 | 3 | ENV LOGS_DIR="logs" \ 4 | BUILD_DEPS="build-essential" 5 | 6 | # Set up octobot's environment 7 | COPY . /trading-bot 8 | WORKDIR /trading-bot 9 | 10 | # install dependencies 11 | RUN apt-get update \ 12 | && apt-get install -qq -y --no-install-recommends $BUILD_DEPS \ 13 | && apt-get clean -yq \ 14 | && apt-get autoremove -yq \ 15 | && rm -rf /var/lib/apt/lists/* 16 | 17 | # configuration and installation 18 | RUN pip3 install cython \ 19 | && pip3 install -r requirements.txt -r dev_requirements.txt 20 | 21 | # tests 22 | #RUN pytest tests 23 | 24 | VOLUME /trading-bot/$LOGS_DIR 25 | 26 | ENTRYPOINT ["python", "./cli/cli.py"] 27 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include octobot_trading *.pxd 2 | 3 | include README.md 4 | include LICENSE 5 | include CHANGELOG.md 6 | include requirements.txt 7 | 8 | global-exclude *.c 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PYTHON=python 2 | PYTHON_VENV=venv/bin/python 3 | COMPILER=gcc 4 | LINKER=gcc 5 | 6 | CLEAN_EXT=*.o *.c *.so 7 | EXTENSION_FOLDER=octobot_trading 8 | CFLAGS=-O9 9 | 10 | PYTHON=$(PYTHON_VENV) 11 | 12 | # export PYTHONPATH=$PYTHONPATH:../OctoBot-Commons 13 | 14 | help: 15 | @echo "OctoBot-Trading Cython Makefile. Available tasks:" 16 | @echo "build -> build the Cython extension module." 17 | @echo "clean -> clean the Cython extension module." 18 | @echo "debug -> debug the Cython extension module." 19 | @echo "run -> run the Cython extension module." 20 | 21 | all: build 22 | 23 | .PHONY: build 24 | build: clean 25 | $(PYTHON) setup.py build_ext --inplace 26 | 27 | .PHONY: clean 28 | clean: 29 | rm -rf build 30 | rm -rf auditwheel 31 | rm -rf dist 32 | rm -rf .eggs 33 | rm -rf *.egg-info 34 | for i in $(CLEAN_EXT); do find $(EXTENSION_FOLDER) -name "$$i" -delete; done 35 | 36 | .PHONY: debug 37 | debug: 38 | gdb -ex r --args $(PYTHON) demo.py 39 | 40 | .PHONY: run 41 | run: build 42 | $(PYTHON) demo.py 43 | 44 | # Suffix rules 45 | .PRECIOUS: %.c 46 | %: %.o 47 | $(LINKER) -o $@ -L$(LIBRARY_DIR) -l$(PYTHON_LIB) $(SYSLIBS) $< 48 | 49 | %.o: %.c 50 | $(COMPILER) $(CFLAGS) -I$(INCLUDE_DIR) -c $< -o $@ 51 | 52 | %.c: %.py 53 | cython -a --embed $< 54 | 55 | %.c: %.pyx 56 | cython -a --embed $< 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OctoBot-Trading [2.4.190](https://github.com/Drakkar-Software/OctoBot-Trading/blob/master/CHANGELOG.md) 2 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/903b6b22bceb4661b608a86fea655f69)](https://app.codacy.com/gh/Drakkar-Software/OctoBot-Trading?utm_source=github.com&utm_medium=referral&utm_content=Drakkar-Software/OctoBot-Trading&utm_campaign=Badge_Grade_Dashboard) 3 | [![PyPI](https://img.shields.io/pypi/v/OctoBot-Trading.svg)](https://pypi.python.org/pypi/OctoBot-Trading/) 4 | [![Coverage Status](https://coveralls.io/repos/github/Drakkar-Software/OctoBot-Trading/badge.svg?branch=master)](https://coveralls.io/github/Drakkar-Software/OctoBot-Trading?branch=master) 5 | [![Github-Action-CI](https://github.com/Drakkar-Software/OctoBot-Trading/workflows/OctoBot-Trading-CI/badge.svg)](https://github.com/Drakkar-Software/OctoBot-Trading/actions) 6 | [![Build Status](https://cloud.drone.io/api/badges/Drakkar-Software/OctoBot-Trading/status.svg)](https://cloud.drone.io/Drakkar-Software/OctoBot-Trading) 7 | 8 | OctoBot trading package. 9 | 10 | OctoBot trading is currently support exchange connections via CCXT. 11 | If you wish to add new connectors, please contact the OctoBot team. 12 | -------------------------------------------------------------------------------- /dev_requirements.txt: -------------------------------------------------------------------------------- 1 | pytest>=7.1 2 | pytest-asyncio>=0.19 3 | pytest-pep8 4 | pytest-cov 5 | pytest-xdist 6 | pytest-randomly 7 | 8 | mock>=4.0.2 9 | 10 | coverage 11 | coveralls 12 | 13 | twine 14 | pip 15 | setuptools 16 | wheel 17 | 18 | pur 19 | 20 | aiohttp 21 | python-dotenv 22 | 23 | pylint<2.15.2 # bug with pylint 2.15.2 24 | -------------------------------------------------------------------------------- /octobot_trading/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | PROJECT_NAME = "OctoBot-Trading" 18 | VERSION = "2.4.190" # major.minor.revision 19 | -------------------------------------------------------------------------------- /octobot_trading/api/channels.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.exchange_channel as exchange_channel 17 | import octobot_trading.exchange_data as exchange_data 18 | import octobot_trading.personal_data as personal_data 19 | 20 | 21 | async def subscribe_to_ohlcv_channel(callback, exchange_id): 22 | await _subscribe_to_channel(callback, exchange_id, exchange_data.OHLCVChannel) 23 | 24 | 25 | async def subscribe_to_trades_channel(callback, exchange_id): 26 | await _subscribe_to_channel(callback, exchange_id, personal_data.TradesChannel) 27 | 28 | 29 | async def subscribe_to_order_channel(callback, exchange_id): 30 | await _subscribe_to_channel(callback, exchange_id, personal_data.OrdersChannel) 31 | 32 | 33 | async def _subscribe_to_channel(callback, exchange_id, channel): 34 | channel = exchange_channel.get_chan(channel.get_name(), exchange_id) 35 | await channel.new_consumer(callback) 36 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/contracts/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.contracts import margin_contract 18 | from octobot_trading.exchange_data.contracts.margin_contract import ( 19 | MarginContract, 20 | ) 21 | 22 | from octobot_trading.exchange_data.contracts import future_contract 23 | from octobot_trading.exchange_data.contracts.future_contract import ( 24 | FutureContract, 25 | ) 26 | 27 | from octobot_trading.exchange_data.contracts import contract_factory 28 | from octobot_trading.exchange_data.contracts.contract_factory import ( 29 | update_contracts_from_positions, 30 | update_future_contract_from_dict, 31 | create_default_future_contract, 32 | ) 33 | 34 | __all__ = [ 35 | "MarginContract", 36 | "FutureContract", 37 | "update_contracts_from_positions", 38 | "update_future_contract_from_dict", 39 | "create_default_future_contract", 40 | ] 41 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/exchange_symbols_data.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_commons.logging as logging 17 | 18 | from octobot_trading.exchange_data.exchange_symbol_data import ExchangeSymbolData 19 | 20 | 21 | class ExchangeSymbolsData: 22 | def __init__(self, exchange_manager): 23 | self.logger = logging.get_logger(self.__class__.__name__) 24 | self.exchange_manager = exchange_manager 25 | self.exchange = exchange_manager.exchange 26 | self.config = exchange_manager.config 27 | self.exchange_symbol_data = {} 28 | 29 | async def stop(self): 30 | self.exchange_manager = None 31 | self.exchange = None 32 | for exchange_symbol_data in self.exchange_symbol_data.values(): 33 | exchange_symbol_data.stop() 34 | self.exchange_symbol_data = {} 35 | 36 | def get_exchange_symbol_data(self, symbol, allow_creation=True) -> ExchangeSymbolData: 37 | try: 38 | return self.exchange_symbol_data[symbol] 39 | except KeyError as e: 40 | if allow_creation: 41 | # warning: should only be called in the async loop thread 42 | self.exchange_symbol_data[symbol] = ExchangeSymbolData(self.exchange_manager, symbol) 43 | return self.exchange_symbol_data[symbol] 44 | raise e 45 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/funding/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.funding import channel 18 | 19 | from octobot_trading.exchange_data.funding import funding_manager 20 | from octobot_trading.exchange_data.funding.channel import ( 21 | FundingProducer, 22 | FundingChannel, 23 | FundingUpdaterSimulator, 24 | FundingUpdater, 25 | ) 26 | 27 | from octobot_trading.exchange_data.funding.funding_manager import ( 28 | FundingManager, 29 | ) 30 | 31 | __all__ = [ 32 | "FundingUpdaterSimulator", 33 | "FundingUpdater", 34 | "FundingManager", 35 | "FundingProducer", 36 | "FundingChannel", 37 | ] 38 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/funding/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.funding.channel import funding 18 | from octobot_trading.exchange_data.funding.channel.funding import ( 19 | FundingProducer, 20 | FundingChannel, 21 | ) 22 | 23 | from octobot_trading.exchange_data.funding.channel import funding_updater 24 | from octobot_trading.exchange_data.funding.channel.funding_updater import ( 25 | FundingUpdater, 26 | ) 27 | 28 | from octobot_trading.exchange_data.funding.channel import funding_updater_simulator 29 | from octobot_trading.exchange_data.funding.channel.funding_updater_simulator import ( 30 | FundingUpdaterSimulator, 31 | ) 32 | 33 | __all__ = [ 34 | "FundingUpdaterSimulator", 35 | "FundingUpdater", 36 | "FundingProducer", 37 | "FundingChannel", 38 | ] 39 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/funding/funding_manager.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_commons.logging as logging 17 | import octobot_trading.constants as constants 18 | import octobot_trading.util as util 19 | 20 | 21 | class FundingManager(util.Initializable): 22 | def __init__(self): 23 | super().__init__() 24 | self.logger = logging.get_logger(self.__class__.__name__) 25 | self.funding_rate = constants.NaN 26 | self.predicted_funding_rate = constants.NaN 27 | self.next_update = 0 28 | self.last_updated = 0 29 | self.reset_funding() 30 | 31 | async def initialize_impl(self): 32 | self.reset_funding() 33 | 34 | def initialized(self): 35 | return self.funding_rate.is_nan() 36 | 37 | def reset_funding(self): 38 | self.funding_rate = constants.NaN 39 | self.predicted_funding_rate = constants.NaN 40 | self.next_update = 0 41 | self.last_updated = 0 42 | 43 | def funding_update(self, funding_rate, predicted_funding_rate, next_funding_time, timestamp): 44 | if funding_rate and next_funding_time: 45 | self.funding_rate = funding_rate 46 | self.predicted_funding_rate = predicted_funding_rate 47 | self.next_update = next_funding_time 48 | self.last_updated = timestamp 49 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/kline/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.kline import channel 18 | from octobot_trading.exchange_data.kline import kline_manager 19 | 20 | from octobot_trading.exchange_data.kline.kline_manager import ( 21 | KlineManager, 22 | ) 23 | from octobot_trading.exchange_data.kline.channel import ( 24 | KlineUpdater, 25 | KlineUpdaterSimulator, 26 | KlineProducer, 27 | KlineChannel, 28 | ) 29 | 30 | __all__ = [ 31 | "KlineUpdaterSimulator", 32 | "KlineProducer", 33 | "KlineChannel", 34 | "KlineManager", 35 | "KlineUpdater", 36 | ] 37 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/kline/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | 18 | from octobot_trading.exchange_data.kline.channel import kline 19 | from octobot_trading.exchange_data.kline.channel.kline import ( 20 | KlineProducer, 21 | KlineChannel, 22 | ) 23 | 24 | from octobot_trading.exchange_data.kline.channel import kline_updater 25 | from octobot_trading.exchange_data.kline.channel.kline_updater import ( 26 | KlineUpdater, 27 | ) 28 | 29 | from octobot_trading.exchange_data.kline.channel import kline_updater_simulator 30 | from octobot_trading.exchange_data.kline.channel.kline_updater_simulator import ( 31 | KlineUpdaterSimulator, 32 | ) 33 | 34 | __all__ = [ 35 | "KlineUpdaterSimulator", 36 | "KlineProducer", 37 | "KlineChannel", 38 | "KlineUpdater", 39 | ] 40 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/ohlcv/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.ohlcv.channel import ohlcv 18 | from octobot_trading.exchange_data.ohlcv.channel.ohlcv import ( 19 | OHLCVProducer, 20 | OHLCVChannel, 21 | ) 22 | from octobot_trading.exchange_data.ohlcv.channel import ohlcv_updater 23 | from octobot_trading.exchange_data.ohlcv.channel.ohlcv_updater import ( 24 | OHLCVUpdater, 25 | ) 26 | 27 | from octobot_trading.exchange_data.ohlcv.channel import ohlcv_updater_simulator 28 | from octobot_trading.exchange_data.ohlcv.channel.ohlcv_updater_simulator import ( 29 | OHLCVUpdaterSimulator, 30 | ) 31 | 32 | 33 | __all__ = [ 34 | "OHLCVUpdaterSimulator", 35 | "OHLCVProducer", 36 | "OHLCVChannel", 37 | "OHLCVUpdater", 38 | ] 39 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/order_book/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.order_book import order_book_manager 18 | from octobot_trading.exchange_data.order_book import channel 19 | 20 | from octobot_trading.exchange_data.order_book.channel import ( 21 | OrderBookUpdater, 22 | OrderBookProducer, 23 | OrderBookChannel, 24 | OrderBookTickerProducer, 25 | OrderBookTickerChannel, 26 | ) 27 | from octobot_trading.exchange_data.order_book.order_book_manager import ( 28 | OrderBookManager, 29 | ) 30 | from octobot_trading.exchange_data.order_book.channel.order_book_updater_simulator import ( 31 | OrderBookUpdaterSimulator, 32 | ) 33 | 34 | __all__ = [ 35 | "OrderBookUpdater", 36 | "OrderBookProducer", 37 | "OrderBookChannel", 38 | "OrderBookTickerProducer", 39 | "OrderBookTickerChannel", 40 | "OrderBookManager", 41 | "OrderBookUpdaterSimulator", 42 | ] 43 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/order_book/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | 18 | from octobot_trading.exchange_data.order_book.channel import order_book 19 | from octobot_trading.exchange_data.order_book.channel.order_book import ( 20 | OrderBookProducer, 21 | OrderBookChannel, 22 | OrderBookTickerProducer, 23 | OrderBookTickerChannel, 24 | ) 25 | 26 | from octobot_trading.exchange_data.order_book.channel import order_book_updater 27 | from octobot_trading.exchange_data.order_book.channel.order_book_updater import ( 28 | OrderBookUpdater, 29 | ) 30 | 31 | from octobot_trading.exchange_data.order_book.channel import ( 32 | order_book_updater_simulator, 33 | ) 34 | from octobot_trading.exchange_data.order_book.channel.order_book_updater_simulator import ( 35 | OrderBookUpdaterSimulator, 36 | ) 37 | 38 | __all__ = [ 39 | "OrderBookUpdater", 40 | "OrderBookProducer", 41 | "OrderBookChannel", 42 | "OrderBookTickerProducer", 43 | "OrderBookTickerChannel", 44 | "OrderBookUpdaterSimulator", 45 | ] 46 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/prices/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.prices import channel 18 | from octobot_trading.exchange_data.prices import prices_manager 19 | from octobot_trading.exchange_data.prices import price_events_manager 20 | 21 | from octobot_trading.exchange_data.prices.channel import ( 22 | MarkPriceUpdater, 23 | MarkPriceUpdaterSimulator, 24 | MarkPriceProducer, 25 | MarkPriceChannel, 26 | ) 27 | from octobot_trading.exchange_data.prices.prices_manager import ( 28 | PricesManager, 29 | calculate_mark_price_from_recent_trade_prices, 30 | ) 31 | from octobot_trading.exchange_data.prices.price_events_manager import ( 32 | PriceEventsManager, 33 | ) 34 | 35 | __all__ = [ 36 | "MarkPriceUpdaterSimulator", 37 | "MarkPriceProducer", 38 | "MarkPriceChannel", 39 | "PricesManager", 40 | "calculate_mark_price_from_recent_trade_prices", 41 | "MarkPriceUpdater", 42 | "PriceEventsManager", 43 | ] 44 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/prices/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.prices.channel import price 18 | from octobot_trading.exchange_data.prices.channel.price import ( 19 | MarkPriceProducer, 20 | MarkPriceChannel, 21 | ) 22 | from octobot_trading.exchange_data.prices.channel import prices_updater 23 | from octobot_trading.exchange_data.prices.channel.prices_updater import ( 24 | MarkPriceUpdater, 25 | ) 26 | from octobot_trading.exchange_data.prices.channel import prices_updater_simulator 27 | from octobot_trading.exchange_data.prices.channel.prices_updater_simulator import ( 28 | MarkPriceUpdaterSimulator, 29 | ) 30 | 31 | __all__ = [ 32 | "MarkPriceUpdaterSimulator", 33 | "MarkPriceProducer", 34 | "MarkPriceChannel", 35 | "MarkPriceUpdater", 36 | ] 37 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/recent_trades/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.recent_trades import recent_trades_manager 18 | from octobot_trading.exchange_data.recent_trades import channel 19 | 20 | from octobot_trading.exchange_data.recent_trades.recent_trades_manager import ( 21 | RecentTradesManager, 22 | ) 23 | from octobot_trading.exchange_data.recent_trades.channel import ( 24 | RecentTradeUpdater, 25 | RecentTradeProducer, 26 | RecentTradeChannel, 27 | LiquidationsProducer, 28 | LiquidationsChannel, 29 | ) 30 | from octobot_trading.exchange_data.recent_trades.channel.recent_trade_updater_simulator import ( 31 | RecentTradeUpdaterSimulator, 32 | ) 33 | 34 | __all__ = [ 35 | "RecentTradeProducer", 36 | "RecentTradeChannel", 37 | "LiquidationsProducer", 38 | "LiquidationsChannel", 39 | "RecentTradesManager", 40 | "RecentTradeUpdater", 41 | "RecentTradeUpdaterSimulator", 42 | ] 43 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/recent_trades/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.recent_trades.channel import recent_trade 18 | from octobot_trading.exchange_data.recent_trades.channel.recent_trade import ( 19 | RecentTradeProducer, 20 | RecentTradeChannel, 21 | LiquidationsProducer, 22 | LiquidationsChannel, 23 | ) 24 | from octobot_trading.exchange_data.recent_trades.channel import recent_trade_updater 25 | from octobot_trading.exchange_data.recent_trades.channel.recent_trade_updater import ( 26 | RecentTradeUpdater, 27 | ) 28 | from octobot_trading.exchange_data.recent_trades.channel import ( 29 | recent_trade_updater_simulator, 30 | ) 31 | from octobot_trading.exchange_data.recent_trades.channel.recent_trade_updater_simulator import ( 32 | RecentTradeUpdaterSimulator, 33 | ) 34 | 35 | __all__ = [ 36 | "RecentTradeProducer", 37 | "RecentTradeChannel", 38 | "LiquidationsProducer", 39 | "LiquidationsChannel", 40 | "RecentTradeUpdater", 41 | "RecentTradeUpdaterSimulator", 42 | ] 43 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/ticker/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.ticker import ticker_manager 18 | from octobot_trading.exchange_data.ticker import channel 19 | 20 | from octobot_trading.exchange_data.ticker.ticker_manager import ( 21 | TickerManager, 22 | ) 23 | from octobot_trading.exchange_data.ticker.channel import ( 24 | TickerProducer, 25 | TickerChannel, 26 | TickerUpdater, 27 | TickerUpdaterSimulator, 28 | MiniTickerProducer, 29 | MiniTickerChannel, 30 | ) 31 | 32 | __all__ = [ 33 | "TickerManager", 34 | "TickerUpdater", 35 | "TickerProducer", 36 | "TickerChannel", 37 | "MiniTickerProducer", 38 | "MiniTickerChannel", 39 | "TickerUpdaterSimulator", 40 | ] 41 | -------------------------------------------------------------------------------- /octobot_trading/exchange_data/ticker/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchange_data.ticker.channel import ticker 18 | from octobot_trading.exchange_data.ticker.channel.ticker import ( 19 | TickerProducer, 20 | TickerChannel, 21 | MiniTickerProducer, 22 | MiniTickerChannel, 23 | ) 24 | from octobot_trading.exchange_data.ticker.channel import ticker_updater 25 | from octobot_trading.exchange_data.ticker.channel.ticker_updater import ( 26 | TickerUpdater, 27 | ) 28 | from octobot_trading.exchange_data.ticker.channel import ticker_updater_simulator 29 | from octobot_trading.exchange_data.ticker.channel.ticker_updater_simulator import ( 30 | TickerUpdaterSimulator, 31 | ) 32 | 33 | __all__ = [ 34 | "TickerUpdater", 35 | "TickerProducer", 36 | "TickerChannel", 37 | "MiniTickerProducer", 38 | "MiniTickerChannel", 39 | "TickerUpdaterSimulator", 40 | ] 41 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/adapters/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | 18 | from octobot_trading.exchanges.adapters import abstract_adapter 19 | from octobot_trading.exchanges.adapters.abstract_adapter import ( 20 | AbstractAdapter, 21 | ) 22 | 23 | __all__ = [ 24 | "AbstractAdapter", 25 | ] 26 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/config/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | 18 | from octobot_trading.exchanges.config import exchange_config_data 19 | from octobot_trading.exchanges.config.exchange_config_data import ( 20 | ExchangeConfig, 21 | ) 22 | from octobot_trading.exchanges.config import backtesting_exchange_config 23 | from octobot_trading.exchanges.config.backtesting_exchange_config import ( 24 | BacktestingExchangeConfig, 25 | ) 26 | from octobot_trading.exchanges.config import proxy_config 27 | from octobot_trading.exchanges.config.proxy_config import ( 28 | ProxyConfig, 29 | ) 30 | from octobot_trading.exchanges.config import proxy_config 31 | from octobot_trading.exchanges.config.exchange_credentials_data import ( 32 | ExchangeCredentialsData, 33 | ) 34 | 35 | __all__ = [ 36 | "ExchangeConfig", 37 | "BacktestingExchangeConfig", 38 | "ProxyConfig", 39 | "ExchangeCredentialsData", 40 | ] 41 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/config/backtesting_exchange_config.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.constants as trading_constants 17 | 18 | 19 | class BacktestingExchangeConfig: 20 | def __init__(self): 21 | # future trading config data 22 | self.future_contract_type = trading_constants.DEFAULT_SYMBOL_CONTRACT_TYPE 23 | self.funding_rate = trading_constants.DEFAULT_SYMBOL_FUNDING_RATE 24 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/config/exchange_credentials_data.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import dataclasses 17 | import typing 18 | 19 | 20 | @dataclasses.dataclass 21 | class ExchangeCredentialsData: 22 | # CEXes 23 | api_key: typing.Optional[str] = None 24 | secret: typing.Optional[str] = None 25 | password: typing.Optional[str] = None 26 | uid: typing.Optional[str] = None 27 | # Oauth 28 | auth_token: typing.Optional[str] = None 29 | auth_token_header_prefix: typing.Optional[str] = None 30 | # DEXes 31 | wallet_address: typing.Optional[str] = None 32 | private_key: typing.Optional[str] = None 33 | 34 | def has_credentials(self) -> bool: 35 | return bool( 36 | (self.api_key and self.secret) # CEX 37 | or (self.wallet_address and self.private_key) # DEX 38 | ) 39 | 40 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/connectors/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchanges.connectors import ccxt 18 | from octobot_trading.exchanges.connectors.ccxt import ( 19 | CCXTAdapter, 20 | CCXTConnector, 21 | CCXTWebsocketConnector, 22 | ) 23 | 24 | from octobot_trading.exchanges.connectors import simulator 25 | from octobot_trading.exchanges.connectors.simulator import ( 26 | ExchangeSimulatorAdapter, 27 | ExchangeSimulatorConnector, 28 | ) 29 | 30 | __all__ = [ 31 | "CCXTAdapter", 32 | "CCXTConnector", 33 | "CCXTWebsocketConnector", 34 | "ExchangeSimulatorAdapter", 35 | "ExchangeSimulatorConnector", 36 | ] 37 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/connectors/ccxt/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchanges.connectors.ccxt import ccxt_adapter 18 | from octobot_trading.exchanges.connectors.ccxt.ccxt_adapter import ( 19 | CCXTAdapter, 20 | ) 21 | from octobot_trading.exchanges.connectors.ccxt import ccxt_connector 22 | from octobot_trading.exchanges.connectors.ccxt.ccxt_connector import ( 23 | CCXTConnector, 24 | ) 25 | 26 | from octobot_trading.exchanges.connectors.ccxt import ccxt_websocket_connector 27 | from octobot_trading.exchanges.connectors.ccxt.ccxt_websocket_connector import ( 28 | CCXTWebsocketConnector, 29 | ) 30 | 31 | __all__ = [ 32 | "CCXTAdapter", 33 | "CCXTConnector", 34 | "CCXTWebsocketConnector", 35 | ] 36 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/connectors/ccxt/ccxt_clients_cache.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import cachetools 17 | import json 18 | 19 | import octobot_commons.constants as commons_constants 20 | 21 | 22 | # To avoid side effects related to a cache refresh at a fix time of the day every day, 23 | # cache should not be refreshed at the same time every day. 24 | # Use 30h and 18min as a period. It could be anything else as long as it doesn't make it so 25 | # that cache ends up refreshed approximately at the same time of the day 26 | _CACHE_TIME = commons_constants.HOURS_TO_SECONDS * 30 + commons_constants.MINUTE_TO_SECONDS * 18 27 | _MARKETS_BY_EXCHANGE = cachetools.TTLCache(maxsize=50, ttl=_CACHE_TIME) 28 | 29 | 30 | def get_client_key(client) -> str: 31 | return f"{client.__class__.__name__}:{json.dumps(client.urls.get('api'))}" 32 | 33 | 34 | def get_exchange_parsed_markets(client_key: str): 35 | return _MARKETS_BY_EXCHANGE[client_key] 36 | 37 | 38 | def set_exchange_parsed_markets(client_key: str, markets): 39 | _MARKETS_BY_EXCHANGE[client_key] = markets 40 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/connectors/ccxt/constants.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | CCXT_INFO = "info" 18 | CCXT_OPTIONS = "options" 19 | CCXT_FEES = "fees" 20 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/connectors/simulator/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchanges.connectors.simulator import exchange_simulator_adapter 18 | from octobot_trading.exchanges.connectors.simulator.exchange_simulator_adapter import ( 19 | ExchangeSimulatorAdapter, 20 | ) 21 | from octobot_trading.exchanges.connectors.simulator import exchange_simulator_connector 22 | from octobot_trading.exchanges.connectors.simulator.exchange_simulator_connector import ( 23 | ExchangeSimulatorConnector, 24 | ) 25 | 26 | __all__ = [ 27 | "ExchangeSimulatorConnector", 28 | "ExchangeSimulatorAdapter", 29 | ] 30 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/connectors/simulator/ccxt_client_simulation.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import decimal 17 | 18 | import octobot_trading.exchanges.connectors.ccxt.ccxt_client_util as ccxt_client_util 19 | 20 | 21 | def parse_markets(exchange_name: str, additional_client_config: dict, market_filter) -> dict: 22 | exchange_class = ccxt_client_util.ccxt_exchange_class_factory(exchange_name) 23 | config = { 24 | **additional_client_config, 25 | **ccxt_client_util.get_custom_domain_config(exchange_class) 26 | } 27 | client = exchange_class(config) 28 | ccxt_client_util.load_markets_from_cache(client, market_filter) 29 | return client.markets 30 | 31 | 32 | def get_fees(market_status) -> dict: 33 | return ccxt_client_util.get_fees(market_status) 34 | 35 | 36 | def get_contract_size(market_status: dict) -> decimal.Decimal: 37 | return decimal.Decimal(str(ccxt_client_util.get_market_status_contract_size(market_status))) 38 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/connectors/simulator/exchange_simulator_adapter.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import octobot_trading.exchanges.adapters as adapters 18 | 19 | 20 | class ExchangeSimulatorAdapter(adapters.AbstractAdapter): 21 | 22 | def __init__(self, connector): 23 | super().__init__(connector) 24 | self._tentacle_adapter_proxy = None 25 | 26 | def _get_tentacle_adapter_proxy(self): 27 | if self._tentacle_adapter_proxy is None: 28 | return self 29 | return self._tentacle_adapter_proxy 30 | 31 | def set_tentacles_adapter_proxy(self, adapter_class): 32 | self._tentacle_adapter_proxy = adapter_class(self.connector) 33 | 34 | def adapt_market_status(self, raw, remove_price_limits=False, **kwargs): 35 | return self._get_tentacle_adapter_proxy().adapt_market_status( 36 | raw, remove_price_limits=remove_price_limits, **kwargs 37 | ) 38 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/exchange_details.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import dataclasses 17 | 18 | 19 | @dataclasses.dataclass 20 | class ExchangeDetails: 21 | id: str 22 | name: str 23 | url: str 24 | api: str 25 | logo_url: str 26 | has_websocket: bool 27 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/implementations/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchanges.implementations import default_websocket_exchange 18 | from octobot_trading.exchanges.implementations.default_websocket_exchange import ( 19 | DefaultWebSocketExchange, 20 | ) 21 | from octobot_trading.exchanges.implementations import default_rest_exchange 22 | from octobot_trading.exchanges.implementations.default_rest_exchange import ( 23 | DefaultRestExchange, 24 | ) 25 | from octobot_trading.exchanges.implementations import exchange_simulator 26 | from octobot_trading.exchanges.implementations.exchange_simulator import ( 27 | ExchangeSimulator, 28 | ) 29 | 30 | __all__ = [ 31 | "DefaultWebSocketExchange", 32 | "DefaultRestExchange", 33 | "ExchangeSimulator", 34 | ] 35 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/implementations/default_rest_exchange.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.enums as trading_enums 17 | import octobot_trading.exchanges.types.rest_exchange as rest_exchange 18 | 19 | 20 | class DefaultRestExchange(rest_exchange.RestExchange): 21 | @classmethod 22 | def get_name(cls) -> str: 23 | return cls.__name__ 24 | 25 | @classmethod 26 | def is_default_exchange(cls) -> bool: 27 | return True 28 | 29 | @classmethod 30 | def is_supporting_exchange(cls, exchange_candidate_name) -> bool: 31 | return isinstance(exchange_candidate_name, str) 32 | 33 | async def switch_to_account(self, account_type: trading_enums.AccountTypes): 34 | # Currently not supported 35 | pass 36 | 37 | @classmethod 38 | def load_user_inputs_from_class(cls, tentacles_setup_config, tentacle_config): 39 | # default exchange can't be configured 40 | return {} 41 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/implementations/default_websocket_exchange.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import octobot_trading.exchanges.connectors.ccxt.ccxt_websocket_connector as ccxt_websocket_connector 18 | import octobot_trading.exchanges.types as exchanges_types 19 | import octobot_tentacles_manager.api as api 20 | 21 | 22 | class DefaultWebSocketExchange(exchanges_types.WebSocketExchange): 23 | DEFAULT_CONNECTOR_CLASS = ccxt_websocket_connector.CCXTWebsocketConnector 24 | 25 | @classmethod 26 | def get_exchange_connector_class(cls, exchange_manager): 27 | return api.get_class_from_name_with_activated_required_tentacles( 28 | name=exchange_manager.exchange.get_associated_websocket_exchange_name(), 29 | tentacles_setup_config=exchange_manager.tentacles_setup_config, 30 | parent_class=cls.DEFAULT_CONNECTOR_CLASS 31 | ) 32 | 33 | def create_feeds(self): 34 | try: 35 | connector = self.websocket_connector(config=self.config, exchange_manager=self.exchange_manager, 36 | websocket_name=self.websocket_connector.get_name()) 37 | connector.initialize(pairs=self.pairs, time_frames=self.time_frames, channels=self.channels) 38 | self.websocket_connectors.append(connector) 39 | 40 | except ValueError as e: 41 | self.logger.exception(e, True, f"Fail to create feed : {e}") 42 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/traders/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchanges.traders import trader 18 | from octobot_trading.exchanges.traders.trader import ( 19 | Trader, 20 | ) 21 | from octobot_trading.exchanges.traders import trader_simulator 22 | from octobot_trading.exchanges.traders.trader_simulator import ( 23 | TraderSimulator, 24 | ) 25 | 26 | __all__ = [ 27 | "TraderSimulator", 28 | "Trader", 29 | ] 30 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/traders/trader_simulator.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.constants 17 | import octobot_trading.exchanges.traders.trader as trader 18 | import octobot_trading.util as util 19 | import octobot_trading.personal_data.orders.order_util as order_util 20 | 21 | 22 | class TraderSimulator(trader.Trader): 23 | """ 24 | TraderSimulator has a role of exchange response simulator 25 | - During order creation / filling / canceling process 26 | """ 27 | 28 | NO_HISTORY_MESSAGE = "Starting a fresh new trading simulation session using trader simulator initial portfolio " \ 29 | "in configuration." 30 | 31 | def __init__(self, config, exchange_manager): 32 | self.simulate = True 33 | super().__init__(config, exchange_manager) 34 | 35 | self.trader_type_str = octobot_trading.constants.SIMULATOR_TRADER_STR 36 | 37 | @staticmethod 38 | def enabled(config): 39 | return util.is_trader_simulator_enabled(config) 40 | 41 | def parse_order_id(self, order_id): 42 | return order_util.generate_order_id() if order_id is None else order_id 43 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.exchanges.types import websocket_exchange 18 | from octobot_trading.exchanges.types.websocket_exchange import ( 19 | WebSocketExchange, 20 | ) 21 | from octobot_trading.exchanges.types import rest_exchange 22 | from octobot_trading.exchanges.types.rest_exchange import ( 23 | RestExchange, 24 | ) 25 | 26 | __all__ = [ 27 | "WebSocketExchange", 28 | "RestExchange", 29 | ] 30 | -------------------------------------------------------------------------------- /octobot_trading/exchanges/util/symbol_details.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import dataclasses 17 | 18 | 19 | import octobot_commons.dataclasses 20 | 21 | 22 | @dataclasses.dataclass 23 | class CCXTDetails(octobot_commons.dataclasses.FlexibleDataclass, octobot_commons.dataclasses.UpdatableDataclass): 24 | info: dict = dataclasses.field(default_factory=dict) # deprecated, will be removed soon 25 | parsed: dict = dataclasses.field(default_factory=dict) # deprecated, will be removed soon 26 | 27 | 28 | @dataclasses.dataclass 29 | class SymbolDetails(octobot_commons.dataclasses.FlexibleDataclass, octobot_commons.dataclasses.UpdatableDataclass): 30 | ccxt: CCXTDetails = dataclasses.field(default_factory=CCXTDetails) 31 | -------------------------------------------------------------------------------- /octobot_trading/modes/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.modes.channel import mode 18 | from octobot_trading.modes.channel.mode import ( 19 | ModeChannelConsumer, 20 | ModeChannelProducer, 21 | ModeChannel, 22 | ) 23 | 24 | from octobot_trading.modes.channel import abstract_mode_producer 25 | from octobot_trading.modes.channel import abstract_mode_consumer 26 | 27 | from octobot_trading.modes.channel.abstract_mode_consumer import ( 28 | AbstractTradingModeConsumer, 29 | check_factor, 30 | ) 31 | from octobot_trading.modes.channel.abstract_mode_producer import ( 32 | AbstractTradingModeProducer, 33 | ) 34 | 35 | __all__ = [ 36 | "ModeChannelConsumer", 37 | "ModeChannelProducer", 38 | "ModeChannel", 39 | "AbstractTradingModeProducer", 40 | "AbstractTradingModeConsumer", 41 | "check_factor", 42 | ] 43 | -------------------------------------------------------------------------------- /octobot_trading/modes/mode_activity.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library 16 | import dataclasses 17 | import enum 18 | import octobot_trading.enums 19 | import octobot_trading.constants 20 | 21 | 22 | @dataclasses.dataclass 23 | class TradingModeActivity: 24 | type: enum.Enum = octobot_trading.enums.TradingModeActivityType.NO_ACTIVITY 25 | details: dict = dataclasses.field(default_factory=dict) 26 | 27 | def set_reason(self, reason): 28 | self.details = {octobot_trading.constants.TRADING_MODE_ACTIVITY_REASON: reason} 29 | -------------------------------------------------------------------------------- /octobot_trading/modes/script_keywords/basic_keywords/run_persistence.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import octobot_commons.enums as commons_enums 18 | import octobot_commons.databases as commons_databases 19 | 20 | 21 | def set_plot_orders(ctx, value): 22 | ctx.plot_orders = value 23 | 24 | 25 | async def disable_candles_plot(ctx, exchange_manager=None): 26 | storage = (exchange_manager or ctx.exchange_manager).storage_manager.candles_storage 27 | await storage.enable(False) 28 | await storage.clear_history() 29 | 30 | 31 | async def clear_orders_cache(writer): 32 | await _clear_table(writer, commons_enums.DBTables.ORDERS.value) 33 | await writer.clear() 34 | 35 | 36 | async def clear_symbol_plot_cache(writer): 37 | await _clear_table(writer, commons_enums.DBTables.CACHE_SOURCE.value) 38 | await writer.clear() 39 | 40 | 41 | async def _clear_table(writer, table, flush=True): 42 | await writer.delete(table, None) 43 | if flush: 44 | await writer.flush() 45 | 46 | 47 | def get_shared_element(key): 48 | return commons_databases.GlobalSharedMemoryStorage.instance()[key] 49 | 50 | 51 | def set_shared_element(key, element): 52 | commons_databases.GlobalSharedMemoryStorage.instance()[key] = element 53 | -------------------------------------------------------------------------------- /octobot_trading/modes/script_keywords/basic_keywords/trading_signals.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | 18 | def is_emitting_trading_signals(ctx): 19 | return ctx.is_trading_signal_emitter() 20 | 21 | 22 | async def emit_trading_signals(ctx): 23 | try: 24 | return await ctx.emit_signal() 25 | except Exception as e: 26 | ctx.logger.exception(e, True, f"Error when emitting trading signal: {e}") 27 | -------------------------------------------------------------------------------- /octobot_trading/modes/script_keywords/dsl/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.modes.script_keywords.dsl.quantity import ( 18 | parse_quantity, 19 | ) 20 | from octobot_trading.modes.script_keywords.dsl.values import ( 21 | QuantityType, 22 | ) 23 | 24 | __all__ = [ 25 | "parse_quantity", 26 | "QuantityType", 27 | ] -------------------------------------------------------------------------------- /octobot_trading/modes/script_keywords/dsl/values.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import enum 18 | 19 | 20 | class QuantityType(enum.Enum): 21 | DELTA = "" 22 | DELTA_EXPLICIT = "d" 23 | DELTA_QUOTE = "q" 24 | DELTA_BASE = "b" 25 | PERCENT = "%" 26 | AVAILABLE = "a" 27 | ENTRY = "e" 28 | AVAILABLE_PERCENT = "a%" 29 | POSITION_PERCENT = "p%" 30 | POSITION_PERCENT_ALIAS = "p" 31 | ENTRY_PERCENT = "e%" 32 | CURRENT_SYMBOL_ASSETS_PERCENT = "s%" 33 | TRADED_SYMBOLS_ASSETS_PERCENT = "t%" 34 | FLAT = "@" 35 | UNKNOWN = "?" 36 | 37 | @staticmethod 38 | def parse(value): 39 | try: 40 | # try reading directly as enum 41 | return QuantityType(value), value 42 | except ValueError: 43 | # try with letters in reverse order 44 | reversed_value = value[::-1] 45 | return QuantityType(reversed_value), value 46 | -------------------------------------------------------------------------------- /octobot_trading/modes/scripted_trading_mode/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | 18 | from octobot_trading.modes.scripted_trading_mode import abstract_scripted_trading_mode 19 | from octobot_trading.modes.scripted_trading_mode.abstract_scripted_trading_mode import ( 20 | AbstractScriptedTradingMode, 21 | AbstractScriptedTradingModeProducer, 22 | ) 23 | 24 | __all__ = [ 25 | "AbstractScriptedTradingMode", 26 | "AbstractScriptedTradingModeProducer", 27 | ] 28 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/active_order_swap_strategies/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.orders.active_order_swap_strategies import active_order_swap_strategy 18 | from octobot_trading.personal_data.orders.active_order_swap_strategies.active_order_swap_strategy import ( 19 | ActiveOrderSwapStrategy, 20 | ) 21 | 22 | from octobot_trading.personal_data.orders.active_order_swap_strategies import stop_first_active_order_swap_strategy 23 | from octobot_trading.personal_data.orders.active_order_swap_strategies.stop_first_active_order_swap_strategy import ( 24 | StopFirstActiveOrderSwapStrategy, 25 | ) 26 | 27 | from octobot_trading.personal_data.orders.active_order_swap_strategies import take_profit_first_active_order_swap_strategy 28 | from octobot_trading.personal_data.orders.active_order_swap_strategies.take_profit_first_active_order_swap_strategy import ( 29 | TakeProfitFirstActiveOrderSwapStrategy, 30 | ) 31 | 32 | 33 | __all__ = [ 34 | "ActiveOrderSwapStrategy", 35 | "StopFirstActiveOrderSwapStrategy", 36 | "TakeProfitFirstActiveOrderSwapStrategy", 37 | ] 38 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/active_order_swap_strategies/stop_first_active_order_swap_strategy.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data.orders.active_order_swap_strategies.active_order_swap_strategy as active_order_swap_strategy 17 | import octobot_trading.enums as enums 18 | 19 | _STOP_ORDER_TYPES = ( 20 | enums.TraderOrderType.TRAILING_STOP, enums.TraderOrderType.STOP_LOSS, enums.TraderOrderType.STOP_LOSS_LIMIT 21 | ) 22 | 23 | class StopFirstActiveOrderSwapStrategy(active_order_swap_strategy.ActiveOrderSwapStrategy): 24 | """ 25 | Consider stop orders as priority orders 26 | """ 27 | 28 | def is_priority_order(self, order) -> bool: 29 | return order.order_type in _STOP_ORDER_TYPES 30 | 31 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/active_order_swap_strategies/take_profit_first_active_order_swap_strategy.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data.orders.active_order_swap_strategies.active_order_swap_strategy as active_order_swap_strategy 17 | import octobot_trading.enums as enums 18 | 19 | _TAKE_PROFIT_ORDER_TYPES = ( 20 | enums.TraderOrderType.SELL_LIMIT, enums.TraderOrderType.BUY_LIMIT, 21 | enums.TraderOrderType.TAKE_PROFIT_LIMIT, enums.TraderOrderType.TAKE_PROFIT, 22 | ) 23 | 24 | class TakeProfitFirstActiveOrderSwapStrategy(active_order_swap_strategy.ActiveOrderSwapStrategy): 25 | """ 26 | Consider stop orders as priority orders 27 | """ 28 | 29 | def is_priority_order(self, order) -> bool: 30 | return order.order_type in _TAKE_PROFIT_ORDER_TYPES 31 | 32 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.orders.channel import orders 18 | from octobot_trading.personal_data.orders.channel.orders import ( 19 | OrdersProducer, 20 | OrdersChannel, 21 | ) 22 | 23 | from octobot_trading.personal_data.orders.channel import orders_updater 24 | from octobot_trading.personal_data.orders.channel.orders_updater import ( 25 | OrdersUpdater, 26 | ) 27 | from octobot_trading.personal_data.orders.channel import orders_updater_simulator 28 | from octobot_trading.personal_data.orders.channel.orders_updater_simulator import ( 29 | OrdersUpdaterSimulator, 30 | ) 31 | 32 | __all__ = [ 33 | "OrdersUpdater", 34 | "OrdersProducer", 35 | "OrdersChannel", 36 | "OrdersUpdaterSimulator", 37 | ] 38 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/channel/orders_updater_simulator.py: -------------------------------------------------------------------------------- 1 | # pylint: disable=E0611 2 | # Drakkar-Software OctoBot-Trading 3 | # Copyright (c) Drakkar-Software, All rights reserved. 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3.0 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library. 17 | 18 | import octobot_trading.exchange_channel as exchange_channel 19 | import octobot_trading.constants as constants 20 | import octobot_trading.personal_data.orders.channel.orders_updater as orders_updater 21 | 22 | 23 | class OrdersUpdaterSimulator(orders_updater.OrdersUpdater): 24 | async def start(self): 25 | self.channel.exchange_manager.exchange_personal_data.orders_manager.are_exchange_orders_initialized = True 26 | await exchange_channel.get_chan(constants.RECENT_TRADES_CHANNEL, self.channel.exchange_manager.id) \ 27 | .new_consumer(self.ignore_recent_trades_update) 28 | for symbol in self.channel.exchange_manager.exchange_config.traded_symbol_pairs: 29 | self._set_initialized_event(symbol) 30 | 31 | async def ignore_recent_trades_update(self, exchange: str, exchange_id: str, 32 | cryptocurrency: str, symbol: str, recent_trades: list): 33 | """ 34 | Used to subscribe at least one recent trades consumer during backtesting 35 | """ 36 | 37 | async def _restore_required_virtual_orders(self): 38 | # nothing to do 39 | pass 40 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/groups/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.orders.groups import balanced_take_profit_and_stop_order_group 18 | from octobot_trading.personal_data.orders.groups.balanced_take_profit_and_stop_order_group import ( 19 | BalancedTakeProfitAndStopOrderGroup, 20 | ) 21 | 22 | from octobot_trading.personal_data.orders.groups import trailing_on_filled_tp_balanced_order_group 23 | from octobot_trading.personal_data.orders.groups.trailing_on_filled_tp_balanced_order_group import ( 24 | TrailingOnFilledTPBalancedOrderGroup, 25 | ) 26 | 27 | from octobot_trading.personal_data.orders.groups import one_cancels_the_other_order_group 28 | from octobot_trading.personal_data.orders.groups.one_cancels_the_other_order_group import ( 29 | OneCancelsTheOtherOrderGroup, 30 | ) 31 | 32 | 33 | from octobot_trading.personal_data.orders.groups import group_util 34 | from octobot_trading.personal_data.orders.groups.group_util import ( 35 | get_group_class, 36 | get_or_create_order_group_from_storage_order_details, 37 | ) 38 | 39 | __all__ = [ 40 | "BalancedTakeProfitAndStopOrderGroup", 41 | "TrailingOnFilledTPBalancedOrderGroup", 42 | "OneCancelsTheOtherOrderGroup", 43 | "get_group_class", 44 | "get_or_create_order_group_from_storage_order_details", 45 | ] 46 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/states/pending_creation_chained_order_state.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data.orders.states.pending_creation_order_state as pending_creation_order_state 17 | 18 | 19 | class PendingCreationChainedOrderState(pending_creation_order_state.PendingCreationOrderState): 20 | def is_created(self) -> bool: 21 | """ 22 | :return: True if the Order is created 23 | """ 24 | # order is to be triggered as chained order: not created 25 | return False 26 | 27 | async def update(self) -> None: 28 | pass 29 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/trailing_profiles/trailing_price_step.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import dataclasses 17 | 18 | import octobot_commons.dataclasses 19 | 20 | @dataclasses.dataclass 21 | class TrailingPriceStep(octobot_commons.dataclasses.FlexibleDataclass): 22 | trailing_price: float 23 | step_price: float 24 | trigger_above: bool 25 | reached: bool = False 26 | 27 | def should_be_reached(self, updated_price: float) -> bool: 28 | if self.trigger_above: 29 | return updated_price >= self.step_price 30 | return updated_price <= self.step_price -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/trailing_profiles/trailing_profile.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import dataclasses 17 | import decimal 18 | import octobot_commons.dataclasses 19 | 20 | import octobot_trading.personal_data.orders.trailing_profiles.trailing_profile_types as trailing_profile_types 21 | 22 | @dataclasses.dataclass 23 | class TrailingProfile(octobot_commons.dataclasses.FlexibleDataclass): 24 | 25 | @staticmethod 26 | def get_type() -> trailing_profile_types.TrailingProfileTypes: 27 | raise NotImplementedError("get_name is not implemented") 28 | 29 | def update_and_get_trailing_price(self, updated_price: decimal.Decimal) -> decimal.Decimal: 30 | raise NotImplementedError("update_and_get_trailing_price is not implemented") 31 | 32 | def to_dict(self) -> dict: 33 | return dataclasses.asdict(self) 34 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/trailing_profiles/trailing_profile_types.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import enum 17 | 18 | 19 | class TrailingProfileTypes(enum.Enum): 20 | FILLED_TAKE_PROFIT = "filled_take_profit" 21 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/triggers/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | 18 | from octobot_trading.personal_data.orders.triggers import base_trigger 19 | from octobot_trading.personal_data.orders.triggers.base_trigger import ( 20 | BaseTrigger, 21 | ) 22 | 23 | 24 | from octobot_trading.personal_data.orders.triggers import price_trigger 25 | from octobot_trading.personal_data.orders.triggers.price_trigger import ( 26 | PriceTrigger, 27 | ) 28 | 29 | __all__ = [ 30 | "BaseTrigger", 31 | "PriceTrigger", 32 | ] 33 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/types/limit/buy_limit_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import octobot_trading.enums as enums 18 | import octobot_trading.personal_data.orders.types.limit.limit_order as limit_order 19 | 20 | 21 | class BuyLimitOrder(limit_order.LimitOrder): 22 | def __init__(self, trader, side=enums.TradeOrderSide.BUY): 23 | super().__init__(trader, side) 24 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/types/limit/sell_limit_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.enums as enums 17 | import octobot_trading.personal_data.orders.types.limit.limit_order as limit_order 18 | 19 | 20 | class SellLimitOrder(limit_order.LimitOrder): 21 | def __init__(self, trader, side=enums.TradeOrderSide.SELL): 22 | super().__init__(trader, side) 23 | 24 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/types/market/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.orders.types.market import market_order 18 | from octobot_trading.personal_data.orders.types.market import sell_market_order 19 | from octobot_trading.personal_data.orders.types.market import buy_market_order 20 | 21 | from octobot_trading.personal_data.orders.types.market.market_order import ( 22 | MarketOrder, 23 | ) 24 | from octobot_trading.personal_data.orders.types.market.sell_market_order import ( 25 | SellMarketOrder, 26 | ) 27 | from octobot_trading.personal_data.orders.types.market.buy_market_order import ( 28 | BuyMarketOrder, 29 | ) 30 | 31 | __all__ = [ 32 | "MarketOrder", 33 | "SellMarketOrder", 34 | "BuyMarketOrder", 35 | ] 36 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/types/market/buy_market_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.enums as enums 17 | import octobot_trading.personal_data.orders.types.market.market_order as market_order 18 | 19 | 20 | class BuyMarketOrder(market_order.MarketOrder): 21 | def __init__(self, trader, side=None): 22 | super().__init__(trader, side=enums.TradeOrderSide.BUY) 23 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/types/market/sell_market_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.enums as enums 17 | import octobot_trading.personal_data.orders.types.market.market_order as market_order 18 | 19 | 20 | class SellMarketOrder(market_order.MarketOrder): 21 | def __init__(self, trader, side=None): 22 | super().__init__(trader, side=enums.TradeOrderSide.SELL) 23 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/types/trailing/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.orders.types.trailing import trailing_stop_order 18 | from octobot_trading.personal_data.orders.types.trailing import ( 19 | trailing_stop_limit_order, 20 | ) 21 | 22 | from octobot_trading.personal_data.orders.types.trailing.trailing_stop_order import ( 23 | TrailingStopOrder, 24 | ) 25 | from octobot_trading.personal_data.orders.types.trailing.trailing_stop_limit_order import ( 26 | TrailingStopLimitOrder, 27 | ) 28 | 29 | __all__ = [ 30 | "TrailingStopOrder", 31 | "TrailingStopLimitOrder", 32 | ] 33 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/types/unknown_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data.orders.types.unsupported_order as unsupported_order 17 | 18 | 19 | class UnknownOrder(unsupported_order.UnsupportedOrder): 20 | """UnknownOrder is used when an exchange is giving an order without a type (ex: binance 2yo+ orders)""" 21 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/orders/types/unsupported_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data.orders.order as order_class 17 | import octobot_trading.errors as errors 18 | 19 | 20 | class UnsupportedOrder(order_class.Order): 21 | """ 22 | UnsupportedOrder is used when an exchange order is fetched but is on purpose set to unsupported. 23 | Used to handle orders that are fetched but can't (yet) be handled in OctoBot. 24 | """ 25 | async def update_order_status(self, force_refresh=False): 26 | if self.trader.simulate: 27 | # SHOULD NEVER HAPPEN 28 | raise errors.NotSupported( 29 | f"{self.get_name()} can't be updated and should not appear in simulation mode" 30 | ) 31 | await self.default_exchange_update_order_status() 32 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/portfolios/assets/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.portfolios.assets import future_asset 18 | from octobot_trading.personal_data.portfolios.assets import margin_asset 19 | from octobot_trading.personal_data.portfolios.assets import spot_asset 20 | 21 | from octobot_trading.personal_data.portfolios.assets.future_asset import ( 22 | FutureAsset, 23 | ) 24 | from octobot_trading.personal_data.portfolios.assets.margin_asset import ( 25 | MarginAsset, 26 | ) 27 | from octobot_trading.personal_data.portfolios.assets.spot_asset import ( 28 | SpotAsset, 29 | ) 30 | 31 | __all__ = [ 32 | "FutureAsset", 33 | "MarginAsset", 34 | "SpotAsset", 35 | ] 36 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/portfolios/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.portfolios.channel import balance 18 | from octobot_trading.personal_data.portfolios.channel.balance import ( 19 | BalanceProducer, 20 | BalanceChannel, 21 | BalanceProfitabilityProducer, 22 | BalanceProfitabilityChannel, 23 | ) 24 | from octobot_trading.personal_data.portfolios.channel import balance_updater 25 | from octobot_trading.personal_data.portfolios.channel.balance_updater import ( 26 | BalanceUpdater, 27 | BalanceProfitabilityUpdater, 28 | ) 29 | from octobot_trading.personal_data.portfolios.channel import balance_updater_simulator 30 | from octobot_trading.personal_data.portfolios.channel.balance_updater_simulator import ( 31 | BalanceUpdaterSimulator, 32 | BalanceProfitabilityUpdaterSimulator, 33 | ) 34 | 35 | __all__ = [ 36 | "BalanceUpdaterSimulator", 37 | "BalanceProfitabilityUpdaterSimulator", 38 | "BalanceUpdater", 39 | "BalanceProfitabilityUpdater", 40 | "BalanceProducer", 41 | "BalanceChannel", 42 | "BalanceProfitabilityProducer", 43 | "BalanceProfitabilityChannel", 44 | ] 45 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/portfolios/channel/balance_updater_simulator.py: -------------------------------------------------------------------------------- 1 | # pylint: disable=E0611 2 | # Drakkar-Software OctoBot-Trading 3 | # Copyright (c) Drakkar-Software, All rights reserved. 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3.0 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library. 17 | import octobot_trading.personal_data.portfolios.channel.balance_updater as balance_updater 18 | 19 | 20 | class BalanceUpdaterSimulator(balance_updater.BalanceUpdater): 21 | pass 22 | 23 | 24 | class BalanceProfitabilityUpdaterSimulator(balance_updater.BalanceProfitabilityUpdater): 25 | pass 26 | 27 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/portfolios/history/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.portfolios.history import historical_asset_value_factory 18 | from octobot_trading.personal_data.portfolios.history.historical_asset_value_factory import ( 19 | create_historical_asset_value_from_dict_like_object, 20 | ) 21 | 22 | from octobot_trading.personal_data.portfolios.history import historical_asset_value 23 | from octobot_trading.personal_data.portfolios.history.historical_asset_value import ( 24 | HistoricalAssetValue, 25 | ) 26 | 27 | from octobot_trading.personal_data.portfolios.history import historical_portfolio_value_manager 28 | from octobot_trading.personal_data.portfolios.history.historical_portfolio_value_manager import ( 29 | HistoricalPortfolioValueManager, 30 | ) 31 | 32 | __all__ = [ 33 | "create_historical_asset_value_from_dict_like_object", 34 | "HistoricalAssetValue", 35 | "HistoricalPortfolioValueManager", 36 | ] 37 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/portfolios/history/historical_asset_value_factory.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import decimal 17 | 18 | 19 | def create_historical_asset_value_from_dict_like_object(historical_asset_class, asset_values): 20 | return historical_asset_class( 21 | asset_values[historical_asset_class.TIMESTAMP_KEY], 22 | { 23 | currency: decimal.Decimal(f"{value}") 24 | for currency, value in asset_values[historical_asset_class.VALUES_KEY].items() 25 | } 26 | ) 27 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/portfolios/portfolio_factory.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data.portfolios.types as portfolio_types 17 | 18 | 19 | def create_portfolio_from_exchange_manager(exchange_manager): 20 | """ 21 | Create a portfolio from an exchange manager 22 | :param exchange_manager: the exchange manager related to the new portfolio instance 23 | :return: the created portfolio instance 24 | """ 25 | if exchange_manager.is_future: 26 | return portfolio_types.FuturePortfolio(exchange_manager.get_exchange_name()) 27 | if exchange_manager.is_margin: 28 | return portfolio_types.MarginPortfolio(exchange_manager.get_exchange_name()) 29 | return portfolio_types.SpotPortfolio(exchange_manager.get_exchange_name()) 30 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/portfolios/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.portfolios.types import future_portfolio 18 | from octobot_trading.personal_data.portfolios.types import margin_portfolio 19 | from octobot_trading.personal_data.portfolios.types import spot_portfolio 20 | 21 | from octobot_trading.personal_data.portfolios.types.future_portfolio import ( 22 | FuturePortfolio, 23 | ) 24 | from octobot_trading.personal_data.portfolios.types.margin_portfolio import ( 25 | MarginPortfolio, 26 | ) 27 | from octobot_trading.personal_data.portfolios.types.spot_portfolio import ( 28 | SpotPortfolio, 29 | ) 30 | 31 | __all__ = [ 32 | "FuturePortfolio", 33 | "MarginPortfolio", 34 | "SpotPortfolio", 35 | ] 36 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/portfolios/types/margin_portfolio.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.constants as constants 17 | import octobot_trading.personal_data.portfolios.assets.margin_asset as margin_asset 18 | import octobot_trading.personal_data.portfolios.portfolio as portfolio_class 19 | 20 | 21 | class MarginPortfolio(portfolio_class.Portfolio): 22 | def create_currency_asset(self, currency, available=constants.ZERO, total=constants.ZERO): 23 | return margin_asset.MarginAsset(name=currency, available=available, total=total) 24 | 25 | def update_portfolio_data_from_order(self, order): 26 | pass # TODO 27 | 28 | def update_portfolio_data_from_withdrawal(self, amount, currency): 29 | pass # TODO 30 | 31 | def update_portfolio_available_from_order(self, order, is_new_order=True): 32 | pass # TODO 33 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/positions/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.positions.channel.positions import ( 18 | PositionsProducer, 19 | PositionsChannel, 20 | ) 21 | 22 | from octobot_trading.personal_data.positions.channel import positions_updater 23 | from octobot_trading.personal_data.positions.channel.positions_updater import ( 24 | PositionsUpdater, 25 | ) 26 | from octobot_trading.personal_data.positions.channel import positions_updater_simulator 27 | from octobot_trading.personal_data.positions.channel.positions_updater_simulator import ( 28 | PositionsUpdaterSimulator, 29 | ) 30 | 31 | __all__ = [ 32 | "PositionsProducer", 33 | "PositionsChannel", 34 | "PositionsUpdaterSimulator", 35 | "PositionsUpdater", 36 | ] 37 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/positions/position_util.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.enums as enums 17 | 18 | 19 | def parse_position_status(raw_position): 20 | try: 21 | return enums.PositionStatus(raw_position[enums.ExchangeConstantsPositionColumns.STATUS.value]) 22 | except KeyError: 23 | return None 24 | 25 | 26 | def parse_position_side(raw_position): 27 | try: 28 | return enums.PositionSide(raw_position[enums.ExchangeConstantsPositionColumns.SIDE.value]) 29 | except KeyError: 30 | return None 31 | 32 | 33 | def parse_position_margin_type(raw_position): 34 | try: 35 | return enums.MarginType(raw_position[enums.ExchangeConstantsPositionColumns.MARGIN_TYPE.value]) 36 | except KeyError: 37 | return None 38 | 39 | 40 | def parse_position_mode(raw_position): 41 | try: 42 | return enums.PositionMode(raw_position[enums.ExchangeConstantsPositionColumns.POSITION_MODE.value]) 43 | except KeyError: 44 | return None 45 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/positions/states/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.positions.states import position_state_factory 18 | from octobot_trading.personal_data.positions.states.position_state_factory import ( 19 | create_position_state, 20 | ) 21 | 22 | from octobot_trading.personal_data.positions.states import idle_position_state 23 | from octobot_trading.personal_data.positions.states import active_position_state 24 | from octobot_trading.personal_data.positions.states import liquidate_position_state 25 | 26 | from octobot_trading.personal_data.positions.states.liquidate_position_state import ( 27 | LiquidatePositionState, 28 | ) 29 | from octobot_trading.personal_data.positions.states.idle_position_state import ( 30 | IdlePositionState, 31 | ) 32 | from octobot_trading.personal_data.positions.states.active_position_state import ( 33 | ActivePositionState, 34 | ) 35 | 36 | __all__ = [ 37 | "LiquidatePositionState", 38 | "IdlePositionState", 39 | "ActivePositionState", 40 | "create_position_state", 41 | ] 42 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/positions/states/active_position_state.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data.positions.states.idle_position_state as idle_position_state 17 | 18 | 19 | class ActivePositionState(idle_position_state.IdlePositionState): 20 | """ 21 | ActivePositionState is the state of a position that has a non-zero size 22 | """ 23 | def is_active(self) -> bool: 24 | """ 25 | :return: True if the Position has a non-zero size 26 | """ 27 | return True 28 | 29 | def _is_compatible_size(self): 30 | return not self.position.is_idle() 31 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/positions/states/position_state_factory.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.enums as enums 17 | 18 | 19 | def create_position_state(position, is_from_exchange_data=False, ignore_states=None): 20 | if ignore_states is None: 21 | ignore_states = [] 22 | if position.status is enums.PositionStatus.OPEN and enums.States.OPEN not in ignore_states: 23 | if position.is_idle() and (position.state is None or position.state.is_active()): 24 | _pre_change_state(position) 25 | position.on_idle(force_open=False, is_from_exchange_data=is_from_exchange_data) 26 | elif not position.is_idle() and (position.state is None or not position.state.is_active()): 27 | _pre_change_state(position) 28 | position.on_active(force_open=False, is_from_exchange_data=is_from_exchange_data) 29 | elif position.status is enums.PositionStatus.LIQUIDATING and enums.PositionStates.LIQUIDATED not in ignore_states: 30 | _pre_change_state(position) 31 | position.on_liquidate(force_liquidate=False, is_from_exchange_data=is_from_exchange_data) 32 | 33 | 34 | def _pre_change_state(position): 35 | if position.state is not None: 36 | position.state.set_is_changing_state() 37 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/positions/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.positions.types import linear_position 18 | from octobot_trading.personal_data.positions.types import inverse_position 19 | 20 | from octobot_trading.personal_data.positions.types.linear_position import ( 21 | LinearPosition, 22 | ) 23 | 24 | from octobot_trading.personal_data.positions.types.inverse_position import ( 25 | InversePosition, 26 | ) 27 | 28 | __all__ = [ 29 | "LinearPosition", 30 | "InversePosition", 31 | ] 32 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/trades/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.trades.channel import trades 18 | from octobot_trading.personal_data.trades.channel.trades import ( 19 | TradesProducer, 20 | TradesChannel, 21 | ) 22 | 23 | from octobot_trading.personal_data.trades.channel import trades_updater 24 | from octobot_trading.personal_data.trades.channel.trades_updater import ( 25 | TradesUpdater, 26 | ) 27 | 28 | __all__ = [ 29 | "TradesProducer", 30 | "TradesChannel", 31 | "TradesUpdater", 32 | ] 33 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/transactions/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.transactions import transactions_manager 18 | from octobot_trading.personal_data.transactions import transaction_factory 19 | from octobot_trading.personal_data.transactions import transaction 20 | from octobot_trading.personal_data.transactions import types 21 | 22 | from octobot_trading.personal_data.transactions.transactions_manager import ( 23 | TransactionsManager, 24 | ) 25 | from octobot_trading.personal_data.transactions.transaction_factory import ( 26 | create_blockchain_transaction, 27 | create_realised_pnl_transaction, 28 | create_fee_transaction, 29 | create_transfer_transaction, 30 | ) 31 | from octobot_trading.personal_data.transactions.transaction import ( 32 | Transaction, 33 | ) 34 | from octobot_trading.personal_data.transactions.types import ( 35 | BlockchainTransaction, 36 | FeeTransaction, 37 | RealisedPnlTransaction, 38 | TransferTransaction, 39 | ) 40 | 41 | __all__ = [ 42 | "TransactionsManager", 43 | "Transaction", 44 | "BlockchainTransaction", 45 | "FeeTransaction", 46 | "RealisedPnlTransaction", 47 | "TransferTransaction", 48 | "create_blockchain_transaction", 49 | "create_realised_pnl_transaction", 50 | "create_fee_transaction", 51 | "create_transfer_transaction", 52 | ] 53 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/transactions/transaction.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import uuid 17 | 18 | import octobot_commons.logging as logging 19 | 20 | 21 | class Transaction: 22 | 23 | def __init__(self, exchange_name, creation_time, transaction_type, currency, symbol=None, transaction_id=None): 24 | self.logger = logging.get_logger(self.__class__.__name__) 25 | self.transaction_id = transaction_id 26 | self.transaction_type = transaction_type 27 | self.creation_time = creation_time 28 | 29 | self.exchange_name = exchange_name 30 | self.symbol = symbol 31 | self.currency = currency 32 | 33 | # generate default transaction id 34 | if self.transaction_id is None: 35 | self.transaction_id = str(uuid.uuid4()) 36 | 37 | def set_transaction_id(self, new_id): 38 | """ 39 | Shouldn't be called outside of TransactionsManager.update_transaction_id 40 | to maintain TransactionsManager.transactions integrity 41 | :param new_id: the new transaction id 42 | """ 43 | self.transaction_id = new_id 44 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/transactions/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | from octobot_trading.personal_data.transactions.types import blockchain_transaction 18 | from octobot_trading.personal_data.transactions.types import fee_transaction 19 | from octobot_trading.personal_data.transactions.types import realised_pnl_transaction 20 | from octobot_trading.personal_data.transactions.types import transfer_transaction 21 | 22 | from octobot_trading.personal_data.transactions.types.blockchain_transaction import ( 23 | BlockchainTransaction, 24 | ) 25 | from octobot_trading.personal_data.transactions.types.fee_transaction import ( 26 | FeeTransaction, 27 | ) 28 | from octobot_trading.personal_data.transactions.types.realised_pnl_transaction import ( 29 | RealisedPnlTransaction, 30 | ) 31 | from octobot_trading.personal_data.transactions.types.transfer_transaction import ( 32 | TransferTransaction, 33 | ) 34 | 35 | __all__ = [ 36 | "BlockchainTransaction", 37 | "FeeTransaction", 38 | "RealisedPnlTransaction", 39 | "TransferTransaction", 40 | ] 41 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/transactions/types/fee_transaction.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import uuid 17 | 18 | import octobot_trading.constants as constants 19 | import octobot_trading.enums as enums 20 | import octobot_trading.personal_data.transactions.transaction as transaction 21 | 22 | 23 | class FeeTransaction(transaction.Transaction): 24 | def __init__(self, exchange_name, creation_time, transaction_type, currency, symbol, quantity, 25 | order_id=None, 26 | funding_rate=constants.ZERO): 27 | self.quantity = quantity 28 | self.order_id = order_id 29 | self.funding_rate = funding_rate 30 | super().__init__(exchange_name, creation_time, transaction_type, currency, symbol=symbol) 31 | self.transaction_id = f"{self.exchange_name}" \ 32 | f"-{self.order_id if self.order_id else str(uuid.uuid4())}" \ 33 | f"-{self.symbol}" \ 34 | f"-{str(self.creation_time)}" 35 | 36 | def is_funding_fee(self): 37 | return self.transaction_type is enums.TransactionType.FUNDING_FEE 38 | 39 | def is_trading_fee(self): 40 | return self.transaction_type is enums.TransactionType.TRADING_FEE 41 | -------------------------------------------------------------------------------- /octobot_trading/personal_data/transactions/types/transfer_transaction.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import octobot_trading.enums as enums 18 | import octobot_trading.personal_data.transactions.transaction as transaction 19 | 20 | 21 | class TransferTransaction(transaction.Transaction): 22 | def __init__(self, exchange_name, creation_time, currency, symbol): 23 | super().__init__(exchange_name, creation_time, 24 | transaction_type=enums.TransactionType.TRANSFER, 25 | currency=currency, 26 | symbol=symbol) 27 | -------------------------------------------------------------------------------- /octobot_trading/signals/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | 18 | from octobot_trading.signals.channel import remote_trading_signal 19 | from octobot_trading.signals.channel.remote_trading_signal import ( 20 | RemoteTradingSignalsChannel, 21 | RemoteTradingSignalChannelProducer, 22 | RemoteTradingSignalChannelConsumer, 23 | ) 24 | from octobot_trading.signals.channel import remote_trading_signal_channel_factory 25 | from octobot_trading.signals.channel.remote_trading_signal_channel_factory import ( 26 | create_remote_trading_signal_channel_if_missing, 27 | ) 28 | from octobot_trading.signals.channel import signal_producer 29 | from octobot_trading.signals.channel.signal_producer import ( 30 | RemoteTradingSignalProducer, 31 | ) 32 | 33 | 34 | __all__ = [ 35 | "RemoteTradingSignalsChannel", 36 | "RemoteTradingSignalChannelProducer", 37 | "RemoteTradingSignalChannelConsumer", 38 | "create_remote_trading_signal_channel_if_missing", 39 | "RemoteTradingSignalProducer", 40 | ] 41 | -------------------------------------------------------------------------------- /octobot_trading/signals/channel/remote_trading_signal_channel_factory.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_commons.channels_name as channels_names 17 | import async_channel.util as channel_creator 18 | import async_channel.channels as channels 19 | import octobot_trading.signals.channel.remote_trading_signal as remote_trading_signal 20 | import octobot_trading.signals.channel.signal_producer as signal_producer 21 | 22 | 23 | async def create_remote_trading_signal_channel_if_missing(exchange_manager) -> \ 24 | (remote_trading_signal.RemoteTradingSignalsChannel, bool): 25 | try: 26 | return channels.get_chan(channels_names.OctoBotCommunityChannelsName.REMOTE_TRADING_SIGNALS_CHANNEL.value), \ 27 | False 28 | except KeyError: 29 | channel = await channel_creator.create_channel_instance(remote_trading_signal.RemoteTradingSignalsChannel, 30 | channels.set_chan) 31 | # also create the associated producer 32 | producer = signal_producer.RemoteTradingSignalProducer( 33 | channel, 34 | exchange_manager.bot_id 35 | ) 36 | await channel.register_producer(producer) 37 | return channel, True 38 | -------------------------------------------------------------------------------- /octobot_trading/supervisors/__init__.py: -------------------------------------------------------------------------------- 1 | # pylint: disable=E0611, E0401 2 | # Drakkar-Software OctoBot-Trading 3 | # Copyright (c) Drakkar-Software, All rights reserved. 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 3.0 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library. 17 | 18 | from octobot_trading.supervisors import abstract_supervisor 19 | from octobot_trading.supervisors.abstract_supervisor import ( 20 | AbstractSupervisor, 21 | ) 22 | 23 | from octobot_trading.supervisors import abstract_portfolio_supervisor 24 | from octobot_trading.supervisors.abstract_portfolio_supervisor import ( 25 | AbstractPortfolioSupervisor, 26 | ) 27 | 28 | __all__ = [ 29 | "AbstractSupervisor", 30 | "AbstractPortfolioSupervisor", 31 | ] 32 | -------------------------------------------------------------------------------- /octobot_trading/util/initializable.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import abc 18 | 19 | 20 | class Initializable: 21 | 22 | def __init__(self): 23 | self.is_initialized = False 24 | 25 | # calls initialize_impl if not initialized 26 | async def initialize(self, force=False, **kwargs): 27 | if not self.is_initialized or force: 28 | await self.initialize_impl(**kwargs) 29 | self.is_initialized = True 30 | return True 31 | return False 32 | 33 | @abc.abstractmethod 34 | async def initialize_impl(self, **kwargs): 35 | raise NotImplementedError("initialize_impl not implemented") 36 | -------------------------------------------------------------------------------- /octobot_trading/util/initialization_util.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import asyncio 17 | 18 | import octobot_commons.tree as commons_tree 19 | 20 | 21 | async def wait_for_topic_init(exchange_manager, timeout, topic, symbol=None, time_frame=None, symbols=None): 22 | if symbols: 23 | return await asyncio.gather( 24 | *[ 25 | wait_for_topic_init(exchange_manager, timeout, topic, symbol=local_symbol, time_frame=None) 26 | for local_symbol in symbols 27 | ] 28 | ) 29 | else: 30 | return await commons_tree.EventProvider.instance().wait_for_event( 31 | exchange_manager.bot_id, 32 | commons_tree.get_exchange_path( 33 | exchange_manager.exchange_name, 34 | topic, 35 | symbol=symbol, 36 | time_frame=time_frame 37 | ), 38 | timeout 39 | ) 40 | -------------------------------------------------------------------------------- /octobot_trading/util/test_tools/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library 16 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy==1.26.3 2 | 3 | # Drakkar-Software requirements 4 | OctoBot-Backtesting>=1.9, <1.10 5 | Async-Channel>=2.2, <2.3 6 | OctoBot-Commons>=1.9.64, <1.10 7 | OctoBot-Tentacles-Manager>=2.9, <2.10 8 | trading-backend>=1.2.35 9 | 10 | # Exchange connection requirements 11 | ccxt==4.4.85 # always ensure real exchanges tests (in tests_additional and authenticated exchange tests) are passing before changing the ccxt version 12 | aiohttp_socks==0.10.1 # used by ccxt socks proxy aiohttp connectors 13 | 14 | cryptography # Never specify a version (managed by https://github.com/Drakkar-Software/OctoBot-PyPi-Linux-Deployer) 15 | 16 | # OrderBook requirement 17 | sortedcontainers==2.4.0 18 | 19 | # Scripting requirements 20 | tinydb==4.5.2 21 | 22 | # Caching 23 | cachetools>=5.5.0, <6 24 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Commons 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | # from distutils.extension import Extension 17 | from setuptools import find_packages 18 | from setuptools import setup 19 | 20 | from octobot_trading import PROJECT_NAME, VERSION 21 | 22 | PACKAGES = find_packages(exclude=["tests"]) 23 | 24 | # long description from README file 25 | with open('README.md', encoding='utf-8') as f: 26 | DESCRIPTION = f.read() 27 | 28 | REQUIRED = open('requirements.txt').readlines() 29 | REQUIRES_PYTHON = '>=3.8' 30 | 31 | setup( 32 | name=PROJECT_NAME, 33 | version=VERSION, 34 | url='https://github.com/Drakkar-Software/OctoBot-Trading', 35 | license='LGPL-3.0', 36 | author='Drakkar-Software', 37 | author_email='contact@drakkar.software', 38 | description='OctoBot project trading package', 39 | packages=PACKAGES, 40 | include_package_data=True, 41 | long_description=DESCRIPTION, 42 | tests_require=["pytest"], 43 | test_suite="tests", 44 | zip_safe=False, 45 | data_files=[], 46 | install_requires=REQUIRED, 47 | python_requires=REQUIRES_PYTHON, 48 | classifiers=[ 49 | 'Development Status :: 5 - Production/Stable', 50 | 'Programming Language :: Python :: 3.8', 51 | 'Programming Language :: Python :: 3.9', 52 | 'Operating System :: OS Independent', 53 | 'Operating System :: MacOS :: MacOS X', 54 | 'Operating System :: Microsoft :: Windows', 55 | 'Operating System :: POSIX' 56 | ], 57 | ) 58 | -------------------------------------------------------------------------------- /tests/api/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/api/test_channels.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import pytest 17 | 18 | from tests import event_loop 19 | from octobot_trading.api.channels import subscribe_to_ohlcv_channel, subscribe_to_trades_channel, \ 20 | subscribe_to_order_channel 21 | 22 | from tests.exchanges import exchange_manager 23 | 24 | # All test coroutines will be treated as marked. 25 | pytestmark = pytest.mark.asyncio 26 | 27 | 28 | async def ohlcv_callback( 29 | exchange: str, 30 | exchange_id: str, 31 | cryptocurrency: str, 32 | symbol: str, 33 | time_frame, 34 | candle 35 | ): 36 | pass 37 | 38 | 39 | async def trades_callback(exchange: str, exchange_id: str, cryptocurrency: str, symbol: str, trade, old_trade): 40 | pass 41 | 42 | 43 | async def order_callback(self, exchange, exchange_id, cryptocurrency, symbol, order, update_type, is_from_bot): 44 | pass 45 | 46 | 47 | async def test_subscribe_to_ohlcv_channel(exchange_manager): 48 | await subscribe_to_ohlcv_channel(ohlcv_callback, exchange_manager.id) 49 | 50 | 51 | async def test_subscribe_to_trades_channel(exchange_manager): 52 | await subscribe_to_trades_channel(trades_callback, exchange_manager.id) 53 | 54 | 55 | async def test_subscribe_to_order_channel(exchange_manager): 56 | await subscribe_to_order_channel(order_callback, exchange_manager.id) 57 | -------------------------------------------------------------------------------- /tests/api/test_modes.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | 19 | # All test coroutines will be treated as marked. 20 | pytestmark = pytest.mark.asyncio 21 | -------------------------------------------------------------------------------- /tests/api/test_orders.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | 19 | # All test coroutines will be treated as marked. 20 | pytestmark = pytest.mark.asyncio 21 | -------------------------------------------------------------------------------- /tests/api/test_portfolio.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | 19 | # All test coroutines will be treated as marked. 20 | pytestmark = pytest.mark.asyncio 21 | -------------------------------------------------------------------------------- /tests/api/test_profitability.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | 19 | # All test coroutines will be treated as marked. 20 | pytestmark = pytest.mark.asyncio 21 | -------------------------------------------------------------------------------- /tests/api/test_symbol_data.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | 19 | # All test coroutines will be treated as marked. 20 | pytestmark = pytest.mark.asyncio 21 | -------------------------------------------------------------------------------- /tests/api/test_trader.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | 19 | # All test coroutines will be treated as marked. 20 | pytestmark = pytest.mark.asyncio 21 | -------------------------------------------------------------------------------- /tests/api/test_trades.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | 19 | # All test coroutines will be treated as marked. 20 | pytestmark = pytest.mark.asyncio 21 | -------------------------------------------------------------------------------- /tests/cli/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchange_data/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | 19 | # avoid circular imports when launching tests from this folder 20 | import octobot_trading.api # TODO fix circular import when importing octobot_trading.exchange_data first 21 | 22 | from octobot_trading.exchange_data.prices.price_events_manager import PriceEventsManager 23 | from octobot_trading.exchange_data.prices.prices_manager import PricesManager 24 | from octobot_trading.exchange_data.recent_trades.recent_trades_manager import RecentTradesManager 25 | 26 | 27 | @pytest.fixture() 28 | def price_events_manager(event_loop): 29 | return PriceEventsManager() 30 | 31 | 32 | @pytest.fixture() 33 | def prices_manager(event_loop, backtesting_exchange_manager): 34 | return PricesManager(backtesting_exchange_manager, "BTC/USDT") 35 | 36 | 37 | @pytest.fixture() 38 | def recent_trades_manager(event_loop): 39 | return RecentTradesManager() 40 | -------------------------------------------------------------------------------- /tests/exchange_data/contracts/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchange_data/funding/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchange_data/kline/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchange_data/ohlcv/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchange_data/order_book/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchange_data/prices/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchange_data/recent_trades/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchange_data/test_exchange_symbols_data.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import pytest 17 | import pytest_asyncio 18 | 19 | from octobot_trading.exchange_data.exchange_symbols_data import ExchangeSymbolsData 20 | 21 | # Import required fixtures 22 | from tests import event_loop 23 | from tests.exchanges import exchange_manager 24 | 25 | pytestmark = pytest.mark.asyncio 26 | 27 | 28 | @pytest.mark.usefixtures("event_loop", "exchange_manager") 29 | @pytest_asyncio.fixture(scope="function") 30 | async def exchange_symbols_data(exchange_manager): 31 | return ExchangeSymbolsData(exchange_manager) 32 | 33 | 34 | async def test_get_exchange_symbol_data(exchange_symbols_data): 35 | new_symbols_data = exchange_symbols_data.get_exchange_symbol_data("BTC/USDT") 36 | assert new_symbols_data is not None 37 | assert exchange_symbols_data.get_exchange_symbol_data("BTC/USDT") is new_symbols_data 38 | 39 | 40 | async def test_get_exchange_symbol_data_without_creation(exchange_symbols_data): 41 | with pytest.raises(KeyError): 42 | exchange_symbols_data.get_exchange_symbol_data("BTC/USDT", allow_creation=False) 43 | exchange_symbols_data.get_exchange_symbol_data("ETH/USDT", allow_creation=True) 44 | with pytest.raises(KeyError): 45 | exchange_symbols_data.get_exchange_symbol_data("ETH/BTC", allow_creation=False) 46 | -------------------------------------------------------------------------------- /tests/exchange_data/ticker/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchanges/connectors/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchanges/connectors/ccxt/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Drakkar-Software/OctoBot-Trading/768b31ed3a59ddca8ee0b6f93a5cff8f4ec7f5e3/tests/exchanges/connectors/ccxt/__init__.py -------------------------------------------------------------------------------- /tests/exchanges/implementations/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchanges/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/exchanges/types/test_websocket_exchange.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import mock 17 | 18 | import octobot_trading.exchanges.types as exchange_types 19 | import pytest 20 | 21 | from tests.exchanges import exchange_manager 22 | 23 | 24 | @pytest.fixture 25 | def websocket_exchange(exchange_manager): 26 | return exchange_types.WebSocketExchange(exchange_manager.config, exchange_manager) 27 | 28 | 29 | def test_clear(websocket_exchange): 30 | assert websocket_exchange.exchange_manager is not None 31 | assert websocket_exchange.exchange is not None 32 | websocket_exchange.websocket_connectors = [mock.Mock(), mock.Mock()] 33 | 34 | websocket_exchange.clear() 35 | assert websocket_exchange.exchange_manager is None 36 | assert websocket_exchange.exchange is None 37 | websocket_exchange.websocket_connectors[0].clear.assert_called_once() 38 | websocket_exchange.websocket_connectors[1].clear.assert_called_once() 39 | -------------------------------------------------------------------------------- /tests/exchanges/util/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/modes/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/modes/script_keywords/basic_keywords/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Drakkar-Software/OctoBot-Trading/768b31ed3a59ddca8ee0b6f93a5cff8f4ec7f5e3/tests/modes/script_keywords/basic_keywords/__init__.py -------------------------------------------------------------------------------- /tests/modes/script_keywords/dsl/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | DEFAULT_ORDER_SYMBOL = "BTC/USDT" 18 | DEFAULT_SYMBOL_QUANTITY = 10 19 | DEFAULT_MARKET_QUANTITY = 1000 20 | 21 | 22 | def check_created_transaction(exchange_manager, closed_quantity, cumulated_closed_quantity): 23 | transaction = get_latest_transaction(exchange_manager) 24 | assert transaction.closed_quantity == closed_quantity 25 | assert transaction.cumulated_closed_quantity == cumulated_closed_quantity 26 | 27 | 28 | def get_latest_transaction(exchange_manager): 29 | transactions = exchange_manager.exchange_personal_data.transactions_manager.transactions 30 | return list(transactions.values())[-1] if transactions else None 31 | -------------------------------------------------------------------------------- /tests/personal_data/orders/active_order_swap_strategies/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/orders/active_order_swap_strategies/test_stop_first_active_order_swap_strategy.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import mock 17 | import pytest 18 | import octobot_trading.personal_data as personal_data 19 | import octobot_trading.enums as enums 20 | 21 | 22 | @pytest.fixture 23 | def stop_first_strategy(): 24 | return personal_data.StopFirstActiveOrderSwapStrategy( 25 | 123, enums.ActiveOrderSwapTriggerPriceConfiguration.FILLING_PRICE.value 26 | ) 27 | 28 | 29 | def test_is_priority_order(stop_first_strategy): 30 | assert stop_first_strategy.swap_timeout == 123 31 | assert stop_first_strategy.is_priority_order(mock.Mock(order_type=enums.TraderOrderType.STOP_LOSS)) is True 32 | assert stop_first_strategy.is_priority_order(mock.Mock(order_type=enums.TraderOrderType.SELL_LIMIT)) is False 33 | assert stop_first_strategy.is_priority_order(mock.Mock(order_type=enums.TraderOrderType.BUY_LIMIT)) is False 34 | -------------------------------------------------------------------------------- /tests/personal_data/orders/active_order_swap_strategies/test_take_profit_first_active_order_swap_strategy.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import mock 17 | import pytest 18 | import octobot_trading.personal_data as personal_data 19 | import octobot_trading.enums as enums 20 | 21 | 22 | @pytest.fixture 23 | def take_profit_first_strategy(): 24 | return personal_data.TakeProfitFirstActiveOrderSwapStrategy( 25 | 123, enums.ActiveOrderSwapTriggerPriceConfiguration.FILLING_PRICE.value 26 | ) 27 | 28 | 29 | def test_is_priority_order(take_profit_first_strategy): 30 | assert take_profit_first_strategy.swap_timeout == 123 31 | assert take_profit_first_strategy.is_priority_order(mock.Mock(order_type=enums.TraderOrderType.STOP_LOSS)) is False 32 | assert take_profit_first_strategy.is_priority_order(mock.Mock(order_type=enums.TraderOrderType.SELL_LIMIT)) is True 33 | assert take_profit_first_strategy.is_priority_order(mock.Mock(order_type=enums.TraderOrderType.BUY_LIMIT)) is True 34 | -------------------------------------------------------------------------------- /tests/personal_data/orders/groups/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import mock 17 | 18 | 19 | def order_mock(**kwargs): 20 | order = mock.Mock(**kwargs) 21 | order.is_open = mock.Mock(return_value=True) 22 | order.is_cancelling = mock.Mock(return_value=False) 23 | order.trader = mock.Mock() 24 | order.trader.cancel_order = mock.AsyncMock() 25 | order.trader.edit_order = mock.AsyncMock() 26 | order.trader.exchange_manager = mock.Mock(trading_modes=[]) 27 | order.trader.exchange_manager.trader = order.trader 28 | return order 29 | -------------------------------------------------------------------------------- /tests/personal_data/orders/groups/test_group_util.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import pytest 17 | 18 | import octobot_trading.personal_data as personal_data 19 | 20 | 21 | def test_get_group_class(): 22 | with pytest.raises(KeyError): 23 | personal_data.get_group_class("") 24 | with pytest.raises(KeyError): 25 | personal_data.get_group_class("hello") 26 | assert personal_data.get_group_class(personal_data.OneCancelsTheOtherOrderGroup.__name__) is \ 27 | personal_data.OneCancelsTheOtherOrderGroup 28 | assert personal_data.get_group_class(personal_data.BalancedTakeProfitAndStopOrderGroup.__name__) is \ 29 | personal_data.BalancedTakeProfitAndStopOrderGroup 30 | -------------------------------------------------------------------------------- /tests/personal_data/orders/states/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/orders/states/test_close_order_state.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data as personal_data 17 | from octobot_trading.enums import OrderStatus 18 | from tests import event_loop 19 | from tests.exchanges import simulated_trader, simulated_exchange_manager 20 | from tests.personal_data.orders import sell_limit_order 21 | 22 | import pytest 23 | 24 | pytestmark = pytest.mark.asyncio 25 | 26 | 27 | async def test_on_order_refresh_successful(sell_limit_order): 28 | sell_limit_order.status = OrderStatus.CLOSED 29 | sell_limit_order.exchange_manager.is_backtesting = True 30 | await sell_limit_order.initialize() 31 | assert isinstance(sell_limit_order.state, personal_data.CloseOrderState) 32 | await sell_limit_order.state.on_refresh_successful() 33 | assert sell_limit_order.is_closed() 34 | sell_limit_order.clear() 35 | -------------------------------------------------------------------------------- /tests/personal_data/orders/states/test_open_order_state.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data as personal_data 17 | from octobot_trading.enums import OrderStatus, OrderStates, States 18 | from octobot_trading.personal_data.orders.states.order_state_factory import create_order_state 19 | from tests import event_loop 20 | from tests.exchanges import simulated_trader, simulated_exchange_manager 21 | from tests.personal_data.orders import buy_limit_order 22 | import pytest 23 | 24 | pytestmark = pytest.mark.asyncio 25 | 26 | 27 | async def test_on_order_refresh_successful(buy_limit_order): 28 | buy_limit_order.exchange_manager.is_backtesting = True 29 | await buy_limit_order.initialize() 30 | assert isinstance(buy_limit_order.state, personal_data.OpenOrderState) 31 | await buy_limit_order.state.on_refresh_successful() 32 | assert buy_limit_order.state.state is States.OPEN 33 | buy_limit_order.status = OrderStatus.FILLED 34 | await buy_limit_order.state.on_refresh_successful() 35 | assert buy_limit_order.is_filled() 36 | -------------------------------------------------------------------------------- /tests/personal_data/orders/states/test_pending_creation_chained_order_state.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data as personal_data 17 | from octobot_trading.enums import OrderStatus, States 18 | from octobot_trading.personal_data.orders.states.order_state_factory import create_order_state 19 | from tests import event_loop 20 | from tests.exchanges import simulated_trader, simulated_exchange_manager 21 | from tests.personal_data.orders import buy_limit_order 22 | import pytest 23 | 24 | pytestmark = pytest.mark.asyncio 25 | 26 | 27 | async def test_on_order_refresh_successful(buy_limit_order): 28 | buy_limit_order.exchange_manager.is_backtesting = True 29 | buy_limit_order.status = OrderStatus.PENDING_CREATION 30 | buy_limit_order.is_waiting_for_chained_trigger = True 31 | await buy_limit_order.initialize() 32 | assert isinstance(buy_limit_order.state, personal_data.PendingCreationChainedOrderState) 33 | await buy_limit_order.state.on_refresh_successful() 34 | assert buy_limit_order.state.state is States.PENDING_CREATION 35 | buy_limit_order.status = OrderStatus.PENDING_CREATION 36 | await buy_limit_order.state.on_refresh_successful() 37 | buy_limit_order.status = OrderStatus.PENDING_CREATION 38 | assert buy_limit_order.is_created() is False 39 | -------------------------------------------------------------------------------- /tests/personal_data/orders/trailing_profiles/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Drakkar-Software/OctoBot-Trading/768b31ed3a59ddca8ee0b6f93a5cff8f4ec7f5e3/tests/personal_data/orders/trailing_profiles/__init__.py -------------------------------------------------------------------------------- /tests/personal_data/orders/triggers/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/orders/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/orders/types/limit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Drakkar-Software/OctoBot-Trading/768b31ed3a59ddca8ee0b6f93a5cff8f4ec7f5e3/tests/personal_data/orders/types/limit/__init__.py -------------------------------------------------------------------------------- /tests/personal_data/orders/types/market/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Drakkar-Software/OctoBot-Trading/768b31ed3a59ddca8ee0b6f93a5cff8f4ec7f5e3/tests/personal_data/orders/types/market/__init__.py -------------------------------------------------------------------------------- /tests/personal_data/orders/types/market/test_buy_market_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import pytest 17 | 18 | from octobot_trading.enums import TraderOrderType 19 | from tests.personal_data import DEFAULT_ORDER_SYMBOL, DEFAULT_MARKET_QUANTITY 20 | from tests.test_utils.random_numbers import decimal_random_price, decimal_random_quantity 21 | 22 | from tests import event_loop 23 | from tests.exchanges import simulated_trader, simulated_exchange_manager 24 | from tests.personal_data.orders import buy_market_order 25 | 26 | pytestmark = pytest.mark.asyncio 27 | 28 | 29 | async def test_buy_market_order_trigger(buy_market_order): 30 | order_price = decimal_random_price() 31 | buy_market_order.update( 32 | price=order_price, 33 | quantity=decimal_random_quantity(max_value=DEFAULT_MARKET_QUANTITY / order_price), 34 | symbol=DEFAULT_ORDER_SYMBOL, 35 | order_type=TraderOrderType.BUY_MARKET, 36 | ) 37 | buy_market_order.exchange_manager.is_backtesting = True # force update_order_status 38 | await buy_market_order.initialize() 39 | assert buy_market_order.is_filled() 40 | -------------------------------------------------------------------------------- /tests/personal_data/orders/types/market/test_sell_market_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import pytest 17 | 18 | from octobot_trading.enums import TraderOrderType 19 | from tests.personal_data import DEFAULT_ORDER_SYMBOL, DEFAULT_SYMBOL_QUANTITY 20 | from tests.test_utils.random_numbers import decimal_random_price, decimal_random_quantity 21 | 22 | from octobot_trading.personal_data.orders.states.open_order_state import OpenOrderState 23 | from tests import event_loop 24 | from tests.exchanges import simulated_trader, simulated_exchange_manager 25 | from tests.personal_data.orders import sell_market_order 26 | 27 | pytestmark = pytest.mark.asyncio 28 | 29 | 30 | async def test_sell_market_order_trigger(sell_market_order): 31 | order_price = decimal_random_price() 32 | sell_market_order.update( 33 | price=order_price, 34 | quantity=decimal_random_quantity(max_value=DEFAULT_SYMBOL_QUANTITY), 35 | symbol=DEFAULT_ORDER_SYMBOL, 36 | order_type=TraderOrderType.SELL_MARKET, 37 | ) 38 | sell_market_order.exchange_manager.is_backtesting = True # force update_order_status 39 | await sell_market_order.initialize() 40 | assert sell_market_order.is_filled() 41 | -------------------------------------------------------------------------------- /tests/personal_data/orders/types/test_unknown_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | -------------------------------------------------------------------------------- /tests/personal_data/orders/types/trailing/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/orders/types/trailing/test_trailing_stop_limit_order.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | -------------------------------------------------------------------------------- /tests/personal_data/portfolios/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/portfolios/assets/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/portfolios/history/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Drakkar-Software/OctoBot-Trading/768b31ed3a59ddca8ee0b6f93a5cff8f4ec7f5e3/tests/personal_data/portfolios/history/__init__.py -------------------------------------------------------------------------------- /tests/personal_data/portfolios/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/portfolios/types/test_margin_portfolio.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | 17 | import pytest 18 | from octobot_commons.constants import PORTFOLIO_AVAILABLE, PORTFOLIO_TOTAL 19 | 20 | from octobot_trading.enums import TraderOrderType 21 | from octobot_trading.personal_data.orders.types.limit.sell_limit_order import SellLimitOrder 22 | from octobot_trading.personal_data.orders.types.market.buy_market_order import BuyMarketOrder 23 | from octobot_trading.personal_data.portfolios.types.margin_portfolio import MarginPortfolio 24 | 25 | from tests.exchanges import backtesting_trader, backtesting_config, backtesting_exchange_manager, fake_backtesting, \ 26 | DEFAULT_EXCHANGE_NAME 27 | 28 | # All test coroutines will be treated as marked. 29 | pytestmark = pytest.mark.asyncio 30 | 31 | 32 | @pytest.mark.parametrize("backtesting_exchange_manager", [(None, DEFAULT_EXCHANGE_NAME, False, True, False)], 33 | indirect=["backtesting_exchange_manager"]) 34 | async def test_initial_portfolio(backtesting_trader): 35 | config, exchange_manager, trader = backtesting_trader 36 | portfolio_manager = exchange_manager.exchange_personal_data.portfolio_manager 37 | 38 | assert isinstance(portfolio_manager.portfolio, MarginPortfolio) 39 | -------------------------------------------------------------------------------- /tests/personal_data/positions/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/positions/channel/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/positions/states/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/positions/types/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/personal_data/trades/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | import octobot_trading.personal_data as personal_data 17 | import octobot_trading.enums 18 | 19 | 20 | def create_trade(trader, exchange_order_id, is_closing_order, origin_order_id): 21 | trade = personal_data.Trade(trader) 22 | trade.exchange_order_id = exchange_order_id 23 | trade.is_closing_order = is_closing_order 24 | trade.origin_order_id = origin_order_id 25 | return trade 26 | 27 | 28 | def create_executed_trade(trader, side, executed_time, executed_quantity, executed_price, symbol, fee): 29 | trade = personal_data.Trade(trader) 30 | trade.executed_time = executed_time 31 | trade.executed_quantity = executed_quantity 32 | trade.executed_price = executed_price 33 | trade.symbol = symbol 34 | trade.fee = fee 35 | trade.side = side 36 | trade.trade_type = octobot_trading.enums.TraderOrderType.BUY_LIMIT 37 | trade.exchange_trade_type = octobot_trading.enums.TradeOrderType.LIMIT 38 | return trade 39 | -------------------------------------------------------------------------------- /tests/personal_data/transactions/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/signals/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests/static/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "time_frame": ["1h", "4h", "1d"], 3 | "exchanges": { 4 | "binanceus": { 5 | "api-key": "", 6 | "api-secret": "", 7 | "web-socket": false 8 | }, 9 | "bybit": { 10 | "api-key": "", 11 | "api-secret": "", 12 | "web-socket": false 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /tests/static/profile.json: -------------------------------------------------------------------------------- 1 | { 2 | "profile": { 3 | "avatar": "default_profile.png", 4 | "description": "OctoBot default profile.", 5 | "id": "default", 6 | "name": "default" 7 | }, 8 | "config": { 9 | "crypto-currencies": { 10 | "Bitcoin": { 11 | "pairs": [ 12 | "BTC/USDT", 13 | "BTC/USD" 14 | ] 15 | }, 16 | "Ethereum": { 17 | "pairs": [ 18 | "ETH/USDT", 19 | "ETH/BTC" 20 | ] 21 | }, 22 | "Cardano": { 23 | "pairs": [ 24 | "ADA/BTC" 25 | ] 26 | }, 27 | "Chainlink": { 28 | "pairs": [ 29 | "LINK/BTC" 30 | ] 31 | } 32 | }, 33 | "exchanges": {}, 34 | "trading": { 35 | "risk": 1, 36 | "reference-market": "BTC" 37 | }, 38 | "trader": { 39 | "enabled": false 40 | }, 41 | "trader-simulator": { 42 | "enabled": true, 43 | "starting-portfolio": { 44 | "BTC": 10, 45 | "USDT": 1000 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/test_utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Drakkar-Software/OctoBot-Trading/768b31ed3a59ddca8ee0b6f93a5cff8f4ec7f5e3/tests/test_utils/__init__.py -------------------------------------------------------------------------------- /tests/test_utils/order_util.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | from octobot_commons.asyncio_tools import wait_asyncio_next_cycle 17 | 18 | 19 | async def fill_limit_or_stop_order(limit_or_stop_order): 20 | await limit_or_stop_order.on_fill() 21 | await wait_asyncio_next_cycle() 22 | 23 | 24 | async def fill_market_order(market_order): 25 | await market_order.on_fill() 26 | await wait_asyncio_next_cycle() 27 | -------------------------------------------------------------------------------- /tests/util/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests_additional/__init__.py: -------------------------------------------------------------------------------- 1 | # Drakkar-Software OctoBot-Trading 2 | # Copyright (c) Drakkar-Software, All rights reserved. 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 3.0 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library. 16 | -------------------------------------------------------------------------------- /tests_additional/real_exchanges/.env.template: -------------------------------------------------------------------------------- 1 | COINBASE_KEY= 2 | COINBASE_SECRET= 3 | 4 | XYZ_KEY= 5 | XYZ_SECRET= 6 | XYZ_PASSWORD= 7 | --------------------------------------------------------------------------------