# Copyright 2024 The TensorTrade and TensorTrade-NG Authors.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the Licensefrom__future__importannotationsimporttypingfromabcimportabstractmethodfromtensortrade.core.componentimportComponentfromtensortrade.core.baseimportTimeIndexedfromtensortrade.env.mixins.schemeimportSchemeMixiniftyping.TYPE_CHECKING:fromtypingimportListfromgymnasium.coreimportActTypefromgymnasium.spacesimportSpacefromtensortrade.oms.ordersimportOrder
[docs]classAbstractActionScheme(SchemeMixin,Component,TimeIndexed):"""An abstract base class for any `ActionScheme` that wants to be compatible with the built-in OMS. The structure of the action scheme is built to make sure that action space can be used with the system, provided that the user defines the methods to interpret that action. """registered_name="action_scheme"@property@abstractmethoddefaction_space(self)->Space:"""The action space of the :class:`TradingEnv`. :return: The gymnasium action space of the :class:`TradingEnv`. :rtype: Space """raiseNotImplementedError()
[docs]@abstractmethoddefget_orders(self,action:ActType)->List[Order]:"""Gets the list of orders to be submitted for the given action. :param action: The action to be interpreted. :type action: :class:`gymnasium.core.ActType` :return: A list of orders to be submitted to the broker. :rtype: List[Order] """raiseNotImplementedError()
[docs]defperform_action(self,action:ActType)->None:"""Performs the action on the given environment. :param action: The action selected by the agent to perform on the environment. :type action: ActType """orders=self.get_orders(action)fororderinorders:iforder:self.trading_env.broker.submit(order)self.trading_env.broker.update()
[docs]defreset(self)->None:"""Performs a reset on the action scheme. Will be called when :class:`TradingEnv` is reset. """pass