コード例 #1
0
    def test_force_put_conditional_sell_all_order_cancel_right_market(self, mock_get_balance, mock_is_alive,
                                                                   _, mock_cancel_all_opened_orders):
        mock_is_alive.return_value = True
        mock_get_balance.return_value = {'Balance': "0.54928749238472938472983"}
        test_market = "BTC-EUR"
        force_put_conditional_sell_all_order(test_market, "0.42")

        mock_cancel_all_opened_orders.assert_called_with(test_market)
コード例 #2
0
    def test_force_put_conditional_sell_all_order_cancel_and_sell(self, mock_get_balance, mock_is_alive,
                                                                  mock_put_conditional_sell_limit,
                                                                  mock_cancel_all_opened_orders):
        mock_is_alive.return_value = True
        mock_get_balance.return_value = {'Balance': "0.54928749238472938472983"}

        force_put_conditional_sell_all_order("BTC-EUR", "0.42")

        self.assertTrue(mock_cancel_all_opened_orders.called)
        self.assertTrue(mock_put_conditional_sell_limit.called)
コード例 #3
0
    def test_force_put_conditional_sell_all_order_truncated_values(self, mock_get_balance, mock_is_alive,
                                                                   mock_put_conditional_sell_limit,
                                                                   mock_cancel_all_opened_orders):
        mock_is_alive.return_value = True
        mock_get_balance.return_value = {'Balance': "0.54928749238472938472983"}
        test_rate = "0.1283761287361283761"

        force_put_conditional_sell_all_order("BTC-EUR", test_rate)

        expected_rate = "0.128376128736128"
        expected_balance = "0.549287492384729"
        mock_put_conditional_sell_limit.assert_called_with("BTC-EUR",
                                                           expected_balance, rate=expected_rate, target=expected_rate)
コード例 #4
0
def dynamic_stop_loss_loop(currency, timeframe_hours):
    balance = float(get_balance(currency)['Balance'])
    while balance > 0.0:
        try:
            period = 22
            datapoints = historical_api.get_historical_hour(
                currency, "BTC", limit=100, aggregate=timeframe_hours)
            exit_price = get_long_chandelier_exit(datapoints, period=period)
            print(exit_price)
            market = market_for_currency(currency)
            force_put_conditional_sell_all_order(market=market,
                                                 rate=exit_price)

        except Exception as e:
            print("Temporary failure: %" % str(e))

        time.sleep(60 * 10)  # update every ten minutes
コード例 #5
0
def __place_order(currency, rate, type, percentage_amount=100):
    market = market_for_currency(currency)
    if type == 'stop_loss':
        return force_put_conditional_sell_all_order(
            market=market, rate=rate, percentage_amount=percentage_amount)
    elif type == 'take_profit':
        return force_put_sell_all_limit_order(
            market=market, rate=rate, percentage_amount=percentage_amount)
    else:
        raise ValueError("Invalid order type: %s" % type)
コード例 #6
0
    def test_force_put_conditional_sell_all_order_alive(self, mock_get_balance, mock_is_alive,
                                                        mock_put_conditional_sell_limit, mock_cancel_all_opened_orders):
        mock_is_alive.return_value = True
        mock_get_balance.return_value = {'Balance': 0.5}
        mock_put_conditional_sell_limit.return_value = "test result"

        result = force_put_conditional_sell_all_order("BTC-EUR", "0.3")

        self.assertTrue(mock_cancel_all_opened_orders.called)
        self.assertEquals("test result", result)
コード例 #7
0
    def test_force_put_conditional_sell_all_order_not_alive(self, mock_get_balance, mock_is_alive,
                                                        mock_put_conditional_sell_limit, mock_cancel_all_opened_orders):
        mock_is_alive.return_value = False

        with self.assertRaises(ConnectionError) as _:
            force_put_conditional_sell_all_order("any", "any")