示例#1
0
 def test_1_exec_sell_order(self):
     with patch('main.exchange.sell',
                side_effect='mocked_order_id') as api_mock:
         trade = Trade(pair='BTC_ETH',
                       btc_amount=1.00,
                       open_rate=0.50,
                       amount=10.00,
                       exchange=Exchange.BITTREX,
                       open_order_id='mocked')
         profit = trade.exec_sell_order(1.00, 10.00)
         api_mock.assert_called_once_with('BTC_ETH', 1.0, 10.0)
         self.assertEqual(profit, 100.0)
         self.assertEqual(trade.close_rate, 1.0)
         self.assertEqual(trade.close_profit, profit)
         self.assertIsNotNone(trade.close_date)
示例#2
0
def execute_sell(trade: Trade, current_rate: float) -> None:
    # Get available balance
    currency = trade.pair.split('_')[1]
    balance = api_wrapper.get_balance(currency)

    profit = trade.exec_sell_order(current_rate, balance)
    message = '*{}:* Selling [{}]({}) at rate `{:f} (profit: {}%)`'.format(
        trade.exchange.name,
        trade.pair.replace('_', '/'),
        api_wrapper.get_pair_detail_url(trade.pair),
        trade.close_rate,
        round(profit, 2)
    )
    logger.info(message)
    TelegramHandler.send_msg(message)
示例#3
0
def execute_sell(trade: Trade, current_rate: float) -> None:
    """
    Executes a sell for the given trade and current rate
    :param trade: Trade instance
    :param current_rate: current rate
    :return: None
    """
    # Get available balance
    currency = trade.pair.split('_')[1]
    balance = exchange.get_balance(currency)

    profit = trade.exec_sell_order(current_rate, balance)
    message = '*{}:* Make It Rain!!!! with [{}]({}) for `{:f} (profit: {}%)`'.format(
        trade.exchange.name, trade.pair.replace('_', '/'),
        exchange.get_pair_detail_url(trade.pair), trade.close_rate,
        round(profit, 2))
    logger.info(message)
    telegram.send_msg(message)
示例#4
0
def handle_trade(trade: Trade) -> None:
    """
    Sells the current pair if the threshold is reached and updates the trade record.
    :return: None
    """
    try:
        if not trade.is_open:
            raise ValueError(
                'attempt to handle closed trade: {}'.format(trade))

        logger.debug('Handling open trade %s ...', trade)
        # Get current rate
        current_rate = api_wrapper.get_ticker(trade.pair)['bid']
        current_profit = 100 * (
            (current_rate - trade.open_rate) / trade.open_rate)

        # Get available balance
        currency = trade.pair.split('_')[1]
        balance = api_wrapper.get_balance(currency)

        for duration, threshold in sorted(CONFIG['minimal_roi'].items()):
            duration, threshold = float(duration), float(threshold)
            # Check if time matches and current rate is above threshold
            time_diff = (datetime.utcnow() -
                         trade.open_date).total_seconds() / 60
            if time_diff > duration and current_rate > (
                    1 + threshold) * trade.open_rate:
                # Execute sell
                profit = trade.exec_sell_order(current_rate, balance)
                message = '*{}:* Selling [{}]({}) at rate `{:f} (profit: {}%)`'.format(
                    trade.exchange.name, trade.pair.replace('_', '/'),
                    api_wrapper.get_pair_detail_url(trade.pair),
                    trade.close_rate, round(profit, 2))
                logger.info(message)
                TelegramHandler.send_msg(message)
                return
        else:
            logger.debug('Threshold not reached. (cur_profit: %1.2f%%)',
                         current_profit)
    except ValueError:
        logger.exception('Unable to handle open order')
示例#5
0
def execute_sell(trade: Trade, current_rate: float) -> None:
    """
    Executes a sell for the given trade and current rate
    :param trade: Trade instance
    :param current_rate: current rate
    :return: None
    """
    # Get available balance
    currency = trade.pair.split('_')[1]
    balance = exchange.get_balance(currency)
    whitelist = _CONF[trade.exchange.name.lower()]['pair_whitelist']

    profit = trade.exec_sell_order(current_rate, balance)
    whitelist.append(trade.pair)
    message = '*{}:* Selling [{}]({}) at rate `{:f} (profit: {}%)`'.format(
        trade.exchange.name,
        trade.pair.replace('_', '/'),
        exchange.get_pair_detail_url(trade.pair),
        trade.close_rate,
        round(profit, 2)
    )
    logger.info(message)
    telegram.send_msg(message)