Skip to content

PolyApiException[status_code=None, error_message=Request exception!] - 5s timeout but matched/filled. #273

@basvandorst

Description

@basvandorst

Have seen it a couple of times lately, from time to time i receive multiple: Request exception! without any error code.

My assumption here is: exception = retry because i did not expect this order is in the books.
But all initial and retried orders are matched without proper response.

Timelines:

17:48:14 | [Poly] ORDER REQUEST: {"token_id": "99258577478211602511334769156801132421571371614708399872000923947126441901284", "amount": 2.0, "side": "BUY", "price": 0.99, "type": "FOK"}
17:48:19 | [Poly] Order error: PolyApiException[status_code=None, error_message=Request exception!]
....
17:48:20 | [Poly] ORDER REQUEST: {"token_id": "99258577478211602511334769156801132421571371614708399872000923947126441901284", "amount": 2.0, "side": "BUY", "price": 0.99, "type": "FOK"}
17:48:25 | [Poly] Order error: PolyApiException[status_code=None, error_message=Request exception!]
...
17:48:27 | [Poly] ORDER REQUEST: {"token_id": "99258577478211602511334769156801132421571371614708399872000923947126441901284", "amount": 2.0, "side": "BUY", "price": 0.99, "type": "FOK"}
17:48:32 | [Poly] Order error: PolyApiException[status_code=None, error_message=Request exception!]

Expected: no orders filled/matches. Reality: 3 orders are matched:

Bought 3.28 Down  at 61¢ ($2.00)
Bought 3.33 Down  at 60¢ ($2.00)
Bought 3.39 Down  at 59¢ ($2.00)
Bought 3.57 Down  at 56¢ ($2.00)
Bought 3.57 Down  at 56¢ ($2.00)
Bought 3.57 Down  at 56¢ ($2.00)

The exception pops up somewhere in this part of the library:

def request(endpoint: str, method: str, headers=None, data=None):
    try:
        resp = requests.request(
            method=method, url=endpoint, headers=headers, json=data if data else None
        )
        if resp.status_code != 200:
            raise Exception(resp)

        try:
            return resp.json()
        except requests.JSONDecodeError:
            return resp.text

    except requests.RequestException:
        raise Exception(error_msg="Request exception!")

or here:


def request(endpoint: str, method: str, headers=None, data=None):
    try:
        headers = overloadHeaders(method, headers)
        if isinstance(data, str):
            # Pre-serialized body: send exact bytes
            resp = _http_client.request(
                method=method,
                url=endpoint,
                headers=headers,
                content=data.encode("utf-8"),
            )
        else:
            resp = _http_client.request(
                method=method,
                url=endpoint,
                headers=headers,
                json=data,
            )

        if resp.status_code != 200:
            raise PolyApiException(resp)

        try:
            return resp.json()
        except ValueError:
            return resp.text

    except httpx.RequestError:
        raise PolyApiException(error_msg="Request exception!")

Looking at the datetime in the logs it is always ~5s after the request was posted, so probably a timeout setting, but i couldnt find any configuration/variable for a setting like this?!

Any suggestions on how to deal with timeouts in this situation? I could check for open orders but then it will be some fuzzy matching, which i dont like. Preferably i want to trust on the library output (exception === failure === no filled order).

Server is co-located, few hops away from poly servers and the network is really stable...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions