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_not_equals():
BTC1 = Instrument("BTC", 8, "Bitcoin")
BTC2 = Instrument("BTC", 8, "Bitcoin")
assert not BTC1 != BTC2
BTC2 = Instrument("ETH", 8, "Bitcoin")
assert BTC1 != BTC2
BTC2 = Instrument("BTC", 5, "Bitcoin")
assert BTC1 != BTC2
BTC2 = Instrument("BTC", 8, "Etheruem")
assert BTC1 != BTC2def test_invalid_rmul():
BTC = Instrument("BTC", 8, "Bitcoin")
# int
with pytest.raises(TypeError):
q = BTC*8
# float
with pytest.raises(TypeError):
q = BTC*8.0def test_not_equals():
BTC1 = Instrument("BTC", 8, "Bitcoin")
BTC2 = Instrument("BTC", 8, "Bitcoin")
assert not BTC1 != BTC2
BTC2 = Instrument("ETH", 8, "Bitcoin")
assert BTC1 != BTC2
BTC2 = Instrument("BTC", 5, "Bitcoin")
assert BTC1 != BTC2
BTC2 = Instrument("BTC", 8, "Etheruem")
assert BTC1 != BTC2def test_invalid_truediv():
BTC = Instrument("BTC", 8, "Bitcoin")
with pytest.raises(InvalidTradingPair):
pair = BTC / BTCdef test_valid_equals():
BTC1 = Instrument("BTC", 8, "Bitcoin")
BTC2 = Instrument("BTC", 8, "Bitcoin")
assert BTC1 == BTC2
BTC2 = Instrument("ETH", 8, "Bitcoin")
assert not BTC1 == BTC2
BTC2 = Instrument("BTC", 5, "Bitcoin")
assert not BTC1 == BTC2
BTC2 = Instrument("BTC", 8, "Etheruem")
assert not BTC1 == BTC2def test_valid_equals():
BTC1 = Instrument("BTC", 8, "Bitcoin")
BTC2 = Instrument("BTC", 8, "Bitcoin")
assert BTC1 == BTC2
BTC2 = Instrument("ETH", 8, "Bitcoin")
assert not BTC1 == BTC2
BTC2 = Instrument("BTC", 5, "Bitcoin")
assert not BTC1 == BTC2
BTC2 = Instrument("BTC", 8, "Etheruem")
assert not BTC1 == BTC2def test_valid_rmul():
BTC = Instrument("BTC", 8, "Bitcoin")
# int
q = 8*BTC
assert isinstance(q, Quantity)
assert q.size == 8
assert q.instrument == BTC
# float
q = 8.0*BTC
assert isinstance(q, Quantity)
assert q.size == 8.0
assert q.instrument == BTCdef test_not_equals():
BTC1 = Instrument("BTC", 8, "Bitcoin")
BTC2 = Instrument("BTC", 8, "Bitcoin")
assert not BTC1 != BTC2
BTC2 = Instrument("ETH", 8, "Bitcoin")
assert BTC1 != BTC2
BTC2 = Instrument("BTC", 5, "Bitcoin")
assert BTC1 != BTC2
BTC2 = Instrument("BTC", 8, "Etheruem")
assert BTC1 != BTC2def test_valid_equals():
BTC1 = Instrument("BTC", 8, "Bitcoin")
BTC2 = Instrument("BTC", 8, "Bitcoin")
assert BTC1 == BTC2
BTC2 = Instrument("ETH", 8, "Bitcoin")
assert not BTC1 == BTC2
BTC2 = Instrument("BTC", 5, "Bitcoin")
assert not BTC1 == BTC2
BTC2 = Instrument("BTC", 8, "Etheruem")
assert not BTC1 == BTC2import pandas as pd
import numpy as np
from typing import Callable, Tuple, Union, List, Dict, NewType
from tensortrade import Component, TimedIdentifiable
from tensortrade.instruments import Instrument, Quantity, TradingPair
from .wallet import Wallet
WalletType = Union['Wallet', Tuple['Exchange', Instrument, float]]
class Portfolio(Component, TimedIdentifiable):
"""A portfolio of wallets on exchanges."""
registered_name = "portfolio"
def __init__(self,
base_instrument: Instrument,
wallets: List[WalletType] = None,
order_listener: 'OrderListener' = None,
performance_listener: Callable[[pd.DataFrame], None] = None):
wallets = wallets or []
self._base_instrument = self.default('base_instrument', base_instrument)
self._order_listener = self.default('order_listener', order_listener)