Exemplo n.º 1
0
def test_delete_raise_status():
    uri = "https://google.com/"
    with requests_mock.Mocker() as m:
        m.register_uri("DELETE", uri, status_code=400)
        with pytest.raises(requests.exceptions.HTTPError):
            res = HttpClient.delete(uri)
            assert res.status_code == 400
Exemplo n.º 2
0
def test_put_raise_status():
    uri = "https://google.com/"
    with requests_mock.Mocker() as m:
        m.register_uri("POST", uri, status_code=403)
        with pytest.raises(requests.exceptions.HTTPError):
            res = HttpClient.post(uri)
            assert res.status_code == 403
Exemplo n.º 3
0
    def cancel_all(cls) -> Dict:
        """Delete all outstanding orders associated with your MPID (the whole organization)

        https://docs.ledgerx.com/reference#cancel-all

        Returns:
            Dict: [description]
        """
        include_api_key = True
        url = gen_legacy_url("/orders")
        res = HttpClient.delete(url, {}, include_api_key)
        return res.json()
Exemplo n.º 4
0
    def list(cls, params: Dict = {}) -> List[Dict]:
        """Get bitvol data

        Args:
            params (Dict, optional): [description]. Defaults to {}.

        Returns:
            List[Dict]: bitvol objects
        """
        include_api_key = True
        url = gen_url("/trading/bitvol")
        res = HttpClient.get(url, params, include_api_key)
        return res.json()
Exemplo n.º 5
0
    def list_trades(cls, contract_id: int) -> Dict:
        """Returns a list of your trades for a given position.

        Args:
            contract_id (int): LedgerX contract ID.

        Returns:
            Dict: [description]
        """
        include_api_key = True
        url = gen_url(f"/trading/positions/{contract_id}/trades")
        res = HttpClient.get(url, {}, include_api_key)
        return res.json()
Exemplo n.º 6
0
    def list_traded(cls, params: Dict = {}) -> List[Dict]:
        """List traded contracts

        Args:
            params (Dict, optional): [description]. Defaults to {}.

        Returns:
            List[Dict]: [description]
        """
        include_api_key = True
        url = gen_url("/trading/contracts/traded")
        qps = {**cls.default_list_traded, **params}
        res = HttpClient.get(url, qps, include_api_key)
        return res.json()
Exemplo n.º 7
0
    def open(cls, params: Dict = {}) -> Dict:
        """Get all resting limit orders directly from the exchange

        https://docs.ledgerx.com/reference#open-orders

        Args:
            params (Dict, optional): [description]. Defaults to {}.

        Returns:
            Dict: [description]
        """
        include_api_key = True
        url = gen_legacy_url("/open-orders")
        res = HttpClient.get(url, {}, include_api_key)
        return res.json()
Exemplo n.º 8
0
    def retrieve_position(cls, contract_id: int) -> Dict:
        """Returns contract details for a a single contract ID.

        https://docs.ledgerx.com/reference#positioncontract

        Args:
            contract_id (int): LedgerX contract ID

        Returns:
            Dict: [description]
        """
        include_api_key = True
        url = gen_url(f"/trading/contracts/{contract_id}/position")
        res = HttpClient.get(url, {}, include_api_key)
        return res.json()
Exemplo n.º 9
0
    def retrieve(cls, contract_id: int) -> Dict:
        """Returns your position for a given contract.

        https://docs.ledgerx.com/reference#retrievecontract

        Args:
            contract_id (int): [description]

        Returns:
            Dict: [description]
        """
        include_api_key = True
        url = gen_url(f"/trading/contracts/{contract_id}")
        res = HttpClient.get(url, {}, include_api_key)
        return res.json()
Exemplo n.º 10
0
    def cancel_single(cls, mid: str, contract_id: int) -> Dict:
        """Cancel a single resting limit order

        https://docs.ledgerx.com/reference#cancel-single

        Args:
            mid (str): [description]

        Returns:
            Dict: [description]
        """
        include_api_key = True
        url = gen_legacy_url(f"/orders/{mid}")
        qps = dict(contract_id=contract_id)
        res = HttpClient.delete(url, qps, include_api_key)
        return res.json()
Exemplo n.º 11
0
    def list(cls, params: Dict = {}) -> List[Dict]:
        """Returns a list of all debits and credits to your accounts.

        https://docs.ledgerx.com/reference#gettransactions

        Args:
            params (Dict, optional): [description]. Defaults to {}.

        Returns:
            List[Dict]: [description]
        """
        include_api_key = True
        url = gen_url("/funds/transactions")
        qps = {**cls.default_list_params, **params}
        res = HttpClient.get(url, qps, include_api_key)
        return res.json()
Exemplo n.º 12
0
    def list(cls, params: Dict = {}) -> List[Dict]:
        """Returns all your positions.

        https://docs.ledgerx.com/reference#listpositions

        Args:
            params (Dict, optional): [description]. Defaults to {}.

        Returns:
            List[Dict]: [description]
        """
        include_api_key = True
        url = gen_url("/trading/positions")
        qps = {**cls.default_list_params, **params}
        res = HttpClient.get(url, qps, include_api_key)
        return res.json()
Exemplo n.º 13
0
    def cancel_replace(cls, mid: str, contract_id: int, price: int, size: int) -> Dict:
        """Atomically swap an existing resting limit order with a new resting limit order. Price, side and size may be changed.

        Rate Limit Notice: This endpoint has a rate limit of 500 requests per 10 seconds.

        https://docs.ledgerx.com/reference#cancel-replace

        Args:
            mid (str): [description]
            contract_id (int): [description]
            price (int): [description]
            size (int): [description]

        Returns:
            Dict: [description]
        """
        include_api_key = True
        url = gen_legacy_url(f"/orders/{mid}")
        qps = dict(contract_id=contract_id, price=price, size=size)
        res = HttpClient.post(url, qps, include_api_key)
        return res.json()
Exemplo n.º 14
0
 def next(cls, next_url: str) -> Dict:
     res = HttpClient.get(next_url)
     return res.json()
 def list(cls, url: str, params: Dict, include_api_key: bool = False):
     res = HttpClient.get(url, params, include_api_key)
     return res.json()