Skip to content

jmwalletd.routers.obwatch

jmwalletd.routers.obwatch

Orderbook proxy endpoints.

Proxies JAM's /obwatch/ requests to the orderbook_watcher HTTP server. The orderbook_watcher runs independently on its own port (default 8000) and provides the live orderbook data from directory servers.

Set OBWATCH_URL to override the connect-to URL (e.g. in Docker where the watcher runs in a separate container).

Attributes

router = APIRouter() module-attribute

Classes

Functions:

get_orderbook(state: DaemonState = Depends(get_daemon_state)) -> JSONResponse async

Proxy orderbook data from the orderbook_watcher service.

Source code in jmwalletd/src/jmwalletd/routers/obwatch.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@router.get("/obwatch/orderbook.json")
async def get_orderbook(
    state: DaemonState = Depends(get_daemon_state),
) -> JSONResponse:
    """Proxy orderbook data from the orderbook_watcher service."""
    url = f"{_get_obwatch_url(state)}/orderbook.json"
    try:
        async with (
            aiohttp.ClientSession() as session,
            session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as resp,
        ):
            if resp.status == 200:
                data = await resp.json()
                return JSONResponse(content=data)
            logger.warning("Orderbook watcher returned status {}", resp.status)
            return JSONResponse(
                content={"offers": [], "fidelitybonds": []},
                status_code=502,
            )
    except Exception:
        logger.warning("Could not reach orderbook watcher at {}", url)
        return JSONResponse(
            content={"offers": [], "fidelitybonds": []},
            status_code=502,
        )

refresh_orderbook_get(state: DaemonState = Depends(get_daemon_state)) -> JSONResponse async

GET compatibility endpoint for orderbook refresh.

Source code in jmwalletd/src/jmwalletd/routers/obwatch.py
106
107
108
109
110
111
@router.get("/obwatch/refreshorderbook")
async def refresh_orderbook_get(
    state: DaemonState = Depends(get_daemon_state),
) -> JSONResponse:
    """GET compatibility endpoint for orderbook refresh."""
    return await _refresh_orderbook_response(state)

refresh_orderbook_post(state: DaemonState = Depends(get_daemon_state)) -> JSONResponse async

POST compatibility endpoint for JAM frontend refresh calls.

Source code in jmwalletd/src/jmwalletd/routers/obwatch.py
114
115
116
117
118
119
@router.post("/obwatch/refreshorderbook")
async def refresh_orderbook_post(
    state: DaemonState = Depends(get_daemon_state),
) -> JSONResponse:
    """POST compatibility endpoint for JAM frontend refresh calls."""
    return await _refresh_orderbook_response(state)