How to use the tensortrade.trades.TradeSide 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 / tensortrade / actions / pair_criteria_size_actions.py View on Github external
def reset(self):
        self._actions = [None]

        for trading_pair, criteria, size in product(self._pairs, self._criteria, self._trade_sizes):
            self._actions += [(TradeSide.BUY, trading_pair, criteria, size)]
            self._actions += [(TradeSide.SELL, trading_pair, criteria, size)]
github notadamking / tensortrade / tensortrade / actions / dynamic_orders.py View on Github external
def get_order(self, action: int, exchange: 'Exchange', portfolio: 'Portfolio') -> Order:
        if action == 0:
            return None

        (side, pair, criteria, size) = self._actions[action]

        instrument = pair.base if side == TradeSide.BUY else pair.quote
        wallet = portfolio.get_wallet(exchange.id, instrument=instrument)
        price = exchange.quote_price(instrument)
        size = min(wallet.balance.size, (wallet.balance.size * size))

        if size < 10 ** -instrument.precision:
            return None

        quantity = size * instrument

        wallet -= quantity

        order = Order(side=side,
                      trade_type=self._trade_type,
                      pair=pair,
                      price=price,
                      quantity=quantity,
github notadamking / tensortrade / tensortrade / exchanges / simulated / simulated_exchange.py View on Github external
def _execute_sell_order(self, order: 'Order', base_wallet: 'Wallet', quote_wallet: 'Wallet', current_price: float) -> Trade:
        price = self._contain_price(current_price)

        if order.type == TradeType.LIMIT and order.price > current_price:
            return None

        commission = Quantity(order.pair.base, order.size * self._commission, order.path_id)
        size = self._contain_size(order.size - commission.size)
        quantity = Quantity(order.pair.base, size, order.path_id)

        trade = Trade(order_id=order.id,
                      exchange_id=self.id,
                      step=self.clock.step,
                      pair=order.pair,
                      side=TradeSide.SELL,
                      trade_type=order.type,
                      quantity=quantity,
                      price=price,
                      commission=commission)

        # self._slippage_model.adjust_trade(trade)

        quote_size = trade.size / trade.price * (trade.price / order.price)

        quote_wallet -= Quantity(order.pair.quote, quote_size, order.path_id)
        base_wallet += quantity
        base_wallet -= commission

        return trade
github notadamking / tensortrade / tensortrade / actions / pair_criteria_size_actions.py View on Github external
def get_order(self, action: int, exchange: 'Exchange', portfolio: 'Portfolio') -> Order:
        if action == 0:
            return None

        (side, pair, criteria, size) = self._actions[action]

        instrument = pair.base if side == TradeSide.BUY else pair.quote
        wallet = portfolio.get_wallet(exchange.id, instrument=instrument)
        price = exchange.quote_price(instrument)
        amount = min(wallet.balance.amount, (wallet.balance.amount * size))

        if amount < 10 ** -instrument.precision:
            return None

        quantity = amount * instrument

        wallet -= quantity

        order = Order(side=side,
                      trade_type=self._trade_type,
                      pair=pair,
                      price=price,
                      quantity=quantity,
github notadamking / tensortrade / tensortrade / actions / dynamic_orders.py View on Github external
def reset(self):
        self._actions = [None]

        for trading_pair, criteria, size in product(self._pairs, self._criteria, self._trade_sizes):
            self._actions += [(TradeSide.BUY, trading_pair, criteria, size)]
            self._actions += [(TradeSide.SELL, trading_pair, criteria, size)]