コード例 #1
0
ファイル: bithumb_trader_test.py プロジェクト: msaltnet/smtm
    def test_bithumb_api_call_should_send_http_request_correctly(
            self, mock_post):
        dummy_query = {
            "order_currency": "apple",
            "payment_currency": "KRW",
        }
        trader = BithumbTrader()
        expected_url = trader.SERVER_URL + "get/apple"
        expected_data = "endpoint=get%2Fapple&order_currency=apple&payment_currency=KRW"
        mock_response = MagicMock()
        mock_response.json = MagicMock(return_value="apple_result")
        mock_post.return_value = mock_response

        self.assertEqual(trader.bithumb_api_call("get/apple", dummy_query),
                         "apple_result")
        mock_response.raise_for_status.assert_called_once()
        mock_post.assert_called_once_with(expected_url,
                                          headers=ANY,
                                          data=expected_data)
        called_headers = mock_post.call_args[1]["headers"]
        self.assertEqual(called_headers["Api-Key"], trader.ACCESS_KEY)
        self.assertIsNotNone(called_headers["Api-Sign"])
        self.assertIsNotNone(called_headers["Api-Nonce"])
        self.assertEqual(called_headers["Content-Type"],
                         "application/x-www-form-urlencoded")
コード例 #2
0
ファイル: bithumb_trader_test.py プロジェクト: msaltnet/smtm
    def test__query_order_should_call_bithumb_api_call_with_correct_query(
            self):
        trader = BithumbTrader("BTC")
        expected_query = {
            "order_currency": trader.market,
            "payment_currency": trader.market_currency,
            "order_id": "apple-007",
        }
        trader.bithumb_api_call = MagicMock()
        trader._query_order()
        trader.bithumb_api_call.assert_not_called()

        trader.bithumb_api_call = MagicMock()
        trader._query_order("apple-007")
        trader.bithumb_api_call.assert_called_once_with(
            "/info/order_detail", expected_query)
コード例 #3
0
ファイル: bithumb_trader_test.py プロジェクト: msaltnet/smtm
 def test__query_balance_should_call_bithumb_api_call_with_correct_query(
         self):
     trader = BithumbTrader()
     expected_query = {
         "order_currency": "apple",
         "payment_currency": "KRW",
     }
     trader.bithumb_api_call = MagicMock()
     trader._query_balance("apple")
     trader.bithumb_api_call.assert_called_once_with(
         "/info/balance", expected_query)
コード例 #4
0
ファイル: bithumb_trader_test.py プロジェクト: msaltnet/smtm
    def test__cancel_order_should_call_bithumb_api_call_correctly(self):
        trader = BithumbTrader("BTC")
        trader.bithumb_api_call = MagicMock()
        expected_query = {
            "order_currency": trader.market,
            "payment_currency": trader.market_currency,
            "order_id": "mango_id",
        }

        trader._cancel_order("mango_id")

        trader.bithumb_api_call.assert_called_once_with(
            "/trade/cancel", expected_query)
コード例 #5
0
ファイル: bithumb_trader_test.py プロジェクト: msaltnet/smtm
 def test__send_limit_order_should_call_bithumb_api_call_with_correct_query(
         self):
     trader = BithumbTrader("BTC")
     expected_query = {
         "order_currency": trader.market,
         "payment_currency": trader.market_currency,
         "type": "bid",
         "units": "0.0051",
         "price": "500",
     }
     trader.bithumb_api_call = MagicMock()
     trader._send_limit_order(True, 500, 0.00512)
     trader.bithumb_api_call.assert_called_once_with(
         "/trade/place", expected_query)
コード例 #6
0
ファイル: bithumb_trader_test.py プロジェクト: msaltnet/smtm
    def test_bithumb_api_call_return_None_when_invalid_data_received_from_server(
            self, mock_post):
        def raise_exception():
            raise ValueError("RequestException dummy exception")

        class DummyResponse:
            pass

        mock_response = DummyResponse()
        mock_response.raise_for_status = raise_exception
        mock_response.json = MagicMock(return_value="apple_result")
        mock_post.return_value = mock_response

        dummy_query = {
            "order_currency": "apple",
            "payment_currency": "KRW",
        }
        trader = BithumbTrader()
        expected_url = trader.SERVER_URL + "get/apple"
        expected_data = "endpoint=get%2Fapple&order_currency=apple&payment_currency=KRW"

        self.assertEqual(trader.bithumb_api_call("get/apple", dummy_query),
                         None)