How to use the tensortrade.wallets.Portfolio 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 / 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 / wallets / test_portfolio.py View on Github external
def test_init_from_wallet_tuples(exchange):

    portfolio = Portfolio(USD, wallets=[
        (exchange, USD, 10000),
        (exchange, BTC, 0)
    ])

    assert portfolio.base_instrument == USD
    assert portfolio.base_balance == 10000 * USD
    assert portfolio.initial_balance == 10000 * USD
    assert len(portfolio.wallets) == 2
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_buy_on_exchange():
    wallets = [
        Wallet(exchange, 10000 * USD),
        Wallet(exchange, 0 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)

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

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

    current_price = 12390.90

    base_wallet -= quantity.size * order.pair.base
    base_wallet += order.quantity
github notadamking / tensortrade / tests / tensortrade / wallets / test_portfolio.py View on Github external
def portfolio(wallet_usd, wallet_btc, wallet_eth, wallet_xrp):

    portfolio = Portfolio(USD, wallets=[
        wallet_usd,
        wallet_btc,
        wallet_eth,
        wallet_xrp
    ])

    return portfolio
github notadamking / tensortrade / tests / tensortrade / wallets / test_portfolio.py View on Github external
def test_init_from_wallets(exchange):

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

    assert portfolio.base_instrument == USD
    assert portfolio.base_balance == 10000 * USD
    assert portfolio.initial_balance == 10000 * USD
    assert len(portfolio.wallets) == 2
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_sell_on_exchange():
    wallets = [
        Wallet(exchange, 0 * USD),
        Wallet(exchange, 10 * BTC)
    ]
    portfolio = Portfolio(base_instrument=USD, wallets=wallets)

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

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

    current_price = 12390.90

    quote_wallet -= quantity.size * order.pair.quote
    quote_wallet += order.quantity
github notadamking / tensortrade / tests / tensortrade / wallets / test_portfolio.py View on Github external
def test_init_empty():

    portfolio = Portfolio(USD)

    assert portfolio.base_instrument == USD
    assert portfolio.base_balance == 0 * USD
    assert portfolio.initial_balance == 0 * USD
    assert len(portfolio.wallets) == 0
github notadamking / tensortrade / tests / tensortrade / orders / test_order.py View on Github external
def test_adding_recipe():
    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)

    order += Recipe(
        side=TradeSide.SELL,
        trade_type=TradeType.MARKET,
        pair=BTC/USD,
        criteria=StopLoss(direction=StopDirection.EITHER, up_percent=0.02, down_percent=0.10),
    )
    assert order.pair
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
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,