コード例 #1
0
ファイル: binance.py プロジェクト: zhoudaqing/freqtrade
    def stoploss_limit(self, pair: str, amount: float, stop_price: float,
                       rate: float) -> Dict:
        """
        creates a stoploss limit order.
        this stoploss-limit is binance-specific.
        It may work with a limited number of other exchanges, but this has not been tested yet.

        """
        ordertype = "stop_loss_limit"

        stop_price = self.symbol_price_prec(pair, stop_price)

        # Ensure rate is less than stop price
        if stop_price <= rate:
            raise OperationalException(
                'In stoploss limit order, stop price should be more than limit price'
            )

        if self._config['dry_run']:
            dry_order = self.dry_run_order(pair, ordertype, "sell", amount,
                                           stop_price)
            return dry_order

        try:
            params = self._params.copy()
            params.update({'stopPrice': stop_price})

            amount = self.symbol_amount_prec(pair, amount)

            rate = self.symbol_price_prec(pair, rate)

            order = self._api.create_order(pair, ordertype, 'sell', amount,
                                           rate, params)
            logger.info(
                'stoploss limit order added for %s. '
                'stop price: %s. limit: %s', pair, stop_price, rate)
            return order
        except ccxt.InsufficientFunds as e:
            raise DependencyException(
                f'Insufficient funds to create {ordertype} sell order on market {pair}.'
                f'Tried to sell amount {amount} at rate {rate}. '
                f'Message: {e}') from e
        except ccxt.InvalidOrder as e:
            # Errors:
            # `binance Order would trigger immediately.`
            raise InvalidOrderException(
                f'Could not create {ordertype} sell order on market {pair}. '
                f'Tried to sell amount {amount} at rate {rate}. '
                f'Message: {e}') from e
        except (ccxt.NetworkError, ccxt.ExchangeError) as e:
            raise TemporaryError(
                f'Could not place sell order due to {e.__class__.__name__}. Message: {e}'
            ) from e
        except ccxt.BaseError as e:
            raise OperationalException(e) from e
コード例 #2
0
ファイル: exchange.py プロジェクト: NatanNMB15/tcc-pytradebot
 def get_order(self, order_id: str, pair: str) -> Dict:
     if self._config['dry_run']:
         try:
             order = self._dry_run_open_orders[order_id]
             return order
         except KeyError as e:
             # Gracefully handle errors with dry-run orders.
             raise InvalidOrderException(
                 f'Tried to get an invalid dry-run-order (id: {order_id}). Message: {e}'
             ) from e
     try:
         return self._api.fetch_order(order_id, pair)
     except ccxt.InvalidOrder as e:
         raise InvalidOrderException(
             f'Tried to get an invalid order (id: {order_id}). Message: {e}'
         ) from e
     except (ccxt.NetworkError, ccxt.ExchangeError) as e:
         raise TemporaryError(
             f'Could not get order due to {e.__class__.__name__}. Message: {e}'
         ) from e
     except ccxt.BaseError as e:
         raise OperationalException(e) from e
コード例 #3
0
    def cancel_order(self, order_id: str, pair: str) -> None:
        if self._config['dry_run']:
            return

        try:
            return self._api.cancel_order(order_id, pair)
        except ccxt.InvalidOrder as e:
            raise InvalidOrderException(
                f'Could not cancel order. Message: {e}') from e
        except (ccxt.NetworkError, ccxt.ExchangeError) as e:
            raise TemporaryError(
                f'Could not cancel order due to {e.__class__.__name__}. Message: {e}'
            ) from e
        except ccxt.BaseError as e:
            raise OperationalException(e) from e