Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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
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
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
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
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
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.'
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']
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
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