How to use the tensortrade.TradingContext function in tensortrade

To help you get started, we’ve selected a few tensortrade examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github notadamking / tensortrade / tests / tensortrade / strategies / test_trading_strategy.py View on Github external
def test_injects_trading_strategy_with_context():

    with TradingContext(**config):

        env = TradingEnvironment(
            exchange='simulated',
            action_scheme='discrete',
            reward_scheme='simple'
        )

        strategy = ConcreteTradingStrategy(environment=env)

        assert hasattr(strategy.environment.exchange.context, 'credentials')
        assert strategy.environment.exchange.context.credentials == config['exchanges']['credentials']

        assert hasattr(strategy.environment.action_scheme.context, 'n_actions')
        assert strategy.environment.action_scheme.context.n_actions == 24

        print(strategy.environment.reward_scheme.context.data)
github notadamking / tensortrade / tests / tensortrade / actions / test_injection.py View on Github external
def test_injects_continuous_initialization():

    c = {
        'base_instrument': 'USD',
        'products': ['BTC', 'ETH'],
        'actions': {
            'max_allowed_slippage_percent': 2.0
        }
    }

    with TradingContext(**c):

        action_scheme = ContinuousActions()

        assert action_scheme.max_allowed_slippage_percent == 2.0
github notadamking / tensortrade / tests / tensortrade / base / test_component.py View on Github external
def test_inject_multiple_components_with_context():

    with td.TradingContext(**config):
        name = 'TensorTrade'
        value = 'the time and effort.'
        instance = WorthMessageComponent(name=name, value=value)
        win = WinPlanComponent()
        lose = LosePlanComponent()

        assert instance.context == win.context == lose.context

    assert instance.context == win.context == lose.context
github notadamking / tensortrade / tests / tensortrade / slippage / test_slippage_model.py View on Github external
def test_injects_context_into_slippage_model():

    with TradingContext(**config):
        model = ConcreteSlippageModel()

        assert hasattr(model.context, 'minimum')
        assert hasattr(model.context, 'maximum')
        assert model.context.minimum == 0
        assert model.context.maximum == 100
        assert model.context['minimum'] == 0
        assert model.context['maximum'] == 100
github notadamking / tensortrade / tests / tensortrade / rewards / test_reward_scheme.py View on Github external
def test_injects_reward_scheme_with_context():

    with TradingContext(**config):

        reward_scheme = ConcreteRewardScheme()

        assert hasattr(reward_scheme.context, 'size')
        assert reward_scheme.context.size == 0
        assert reward_scheme.context['size'] == 0
github notadamking / tensortrade / tests / tensortrade / rewards / test_injection.py View on Github external
def test_injects_string_intialized_reward_scheme():

    with TradingContext(**config):

        reward_scheme = get('simple')

        assert reward_scheme.registered_name == "rewards"
        assert hasattr(reward_scheme.context, 'size')
        assert reward_scheme.context.size == 0
        assert reward_scheme.context['size'] == 0
github notadamking / tensortrade / tests / tensortrade / base / test_component.py View on Github external
def test_injects_concrete_tensor_trade_component_with_context():

    with td.TradingContext(**config):

        name = 'TensorTrade'
        value = 'the time and effort.'
        instance = WorthMessageComponent(name=name, value=value)
        assert instance.context == config
        assert instance.message() == 'TensorTrade is worth the time and effort.'
github notadamking / tensortrade / tests / tensortrade / exchanges / test_injection.py View on Github external
def test_injects_string_initialized_action_scheme():

    with TradingContext(**config):

        exchange = get('simulated')

        assert hasattr(exchange.context, 'credentials')
        assert exchange.context.credentials == config['exchanges']['credentials']
        assert exchange.context['credentials'] == config['exchanges']['credentials']
github notadamking / tensortrade / tests / tensortrade / actions / test_injection.py View on Github external
def test_injects_string_initialized_action_scheme():

    with TradingContext(**config) as tc:

        action_scheme = get('discrete')

        assert hasattr(action_scheme.context, 'n_actions')
        assert action_scheme.context.n_actions == 50
        assert action_scheme.context['n_actions'] == 50
github notadamking / tensortrade / tests / tensortrade / actions / test_injection.py View on Github external
def test_injects_strategy():

    with TradingContext(**config) as tc:
        action_scheme = ConcreteActionScheme()

        assert hasattr(action_scheme.context, 'n_actions')
        assert action_scheme.context.n_actions == 50
        assert action_scheme.context['n_actions'] == 50