How to use tensortrade - 10 common examples

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 / orders / test_order.py View on Github external
def test_path_order_runs_though_broker():

    wallets = [
        Wallet(exchange, 10000 * USD),
        Wallet(exchange, 0 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)
    exchange.reset()
    portfolio.reset()
    broker.reset()

    base_wallet = portfolio.get_wallet(exchange.id, USD)

    quantity = (1 / 10) * base_wallet.balance
    order = Order(side=TradeSide.BUY,
                  trade_type=TradeType.MARKET,
                  pair=USD / BTC,
                  quantity=quantity,
                  portfolio=portfolio)

    order = order.add_recipe(
        Recipe(
            side=TradeSide.SELL,
            trade_type=TradeType.MARKET,
            pair=USD/BTC,
            criteria=StopLoss(direction=StopDirection.EITHER, up_percent=0.02, down_percent=0.10)
        )
    )

    broker.submit(order)
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_init():
    wallets = [
        Wallet(exchange, 10000 * USD),
        Wallet(exchange, 0 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)
    base_wallet = portfolio.get_wallet(exchange.id, USD)

    quantity = (1 / 10) * base_wallet.balance
    order = Order(side=TradeSide.BUY,
                  trade_type=TradeType.MARKET,
                  pair=USD/BTC,
                  quantity=quantity,
                  portfolio=portfolio)
    assert order
    assert order.id
    assert order.path_id
    assert order.quantity.instrument == USD
    assert order.filled_size == 0
    assert order.remaining_size == order.quantity
    assert isinstance(order.pair, TradingPair)
    assert order.pair.base == USD
    assert order.pair.quote == BTC
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_init():
    wallets = [
        Wallet(exchange, 10000 * USD),
        Wallet(exchange, 0 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)
    base_wallet = portfolio.get_wallet(exchange.id, USD)

    quantity = (1 / 10) * base_wallet.balance
    order = Order(side=TradeSide.BUY,
                  trade_type=TradeType.MARKET,
                  pair=USD/BTC,
                  quantity=quantity,
                  portfolio=portfolio)
    assert order
    assert order.id
    assert order.path_id
    assert order.quantity.instrument == USD
    assert order.filled_size == 0
    assert order.remaining_size == order.quantity
    assert isinstance(order.pair, TradingPair)
    assert order.pair.base == USD
    assert order.pair.quote == BTC
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_path_order_runs_though_broker():

    wallets = [
        Wallet(exchange, 10000 * USD),
        Wallet(exchange, 0 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)
    exchange.reset()
    portfolio.reset()
    broker.reset()

    base_wallet = portfolio.get_wallet(exchange.id, USD)

    quantity = (1 / 10) * base_wallet.balance
    order = Order(side=TradeSide.BUY,
                  trade_type=TradeType.MARKET,
                  pair=USD / BTC,
                  quantity=quantity,
                  portfolio=portfolio)

    order = order.add_recipe(
        Recipe(
            side=TradeSide.SELL,
            trade_type=TradeType.MARKET,
            pair=USD/BTC,
            criteria=StopLoss(direction=StopDirection.EITHER, up_percent=0.02, down_percent=0.10)
        )
    )

    broker.submit(order)

    while len(broker.unexecuted) > 0:
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_init():
    wallets = [
        Wallet(exchange, 10000 * USD),
        Wallet(exchange, 0 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)
    base_wallet = portfolio.get_wallet(exchange.id, USD)

    quantity = (1 / 10) * base_wallet.balance
    order = Order(side=TradeSide.BUY,
                  trade_type=TradeType.MARKET,
                  pair=USD/BTC,
                  quantity=quantity,
                  portfolio=portfolio)
    assert order
    assert order.id
    assert order.path_id
    assert order.quantity.instrument == USD
    assert order.filled_size == 0
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_order_runs_through_broker():
    wallets = [
        Wallet(exchange, 10000 * USD),
        Wallet(exchange, 0 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)
    exchange.reset()
    portfolio.reset()
    broker.reset()

    base_wallet = portfolio.get_wallet(exchange.id, USD)

    quantity = (1 / 10) * base_wallet.balance
    order = Order(side=TradeSide.BUY,
                  trade_type=TradeType.MARKET,
                  pair=USD / BTC,
                  quantity=quantity,
                  portfolio=portfolio)

    base_wallet -= quantity.size * order.pair.base
    base_wallet += order.quantity

    broker.submit(order)

    broker.update()
    portfolio.update()
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_init():
    wallets = [
        Wallet(exchange, 10000 * USD),
        Wallet(exchange, 0 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)
    base_wallet = portfolio.get_wallet(exchange.id, USD)

    quantity = (1 / 10) * base_wallet.balance
    order = Order(side=TradeSide.BUY,
                  trade_type=TradeType.MARKET,
                  pair=USD/BTC,
                  quantity=quantity,
                  portfolio=portfolio)
    assert order
    assert order.id
    assert order.path_id
    assert order.quantity.instrument == USD
    assert order.filled_size == 0
    assert order.remaining_size == order.quantity
    assert isinstance(order.pair, TradingPair)
    assert order.pair.base == USD
github notadamking / tensortrade / tests / tensortrade / base / test_context.py View on Github external
def test_init():
    c = TradingContext(base_instrument=config['base_instrument'],
                       instruments=config['instruments'])
    assert c.shared.get('base_instrument') == 'EURO'
    assert c.shared.get('instruments') == ['BTC', 'ETH']
github notadamking / tensortrade / tests / tensortrade / orders / criteria / test_limit.py View on Github external
def test_call_with_buy_order(mock_order_class, mock_exchange_class):

    exchange = mock_exchange_class.return_value
    exchange.quote_price = mock.Mock(return_value=7000.00)

    order = mock_order_class.return_value
    order.pair = USD/BTC
    order.side = TradeSide.BUY

    criteria = Limit(limit_price=6800.00)
    assert not criteria(order, exchange)

    criteria = Limit(limit_price=7000.00)
    assert criteria(order, exchange)

    criteria = Limit(limit_price=7200.00)
    assert criteria(order, exchange)
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)