From 2bb63f56a40728565f1d38e7cdd86020ea164045 Mon Sep 17 00:00:00 2001 From: gpsanant Date: Sat, 20 Jul 2024 18:38:05 -0700 Subject: [PATCH] add price history endpoint --- py_clob_client/client.py | 13 +++++++++++++ py_clob_client/endpoints.py | 1 + 2 files changed, 14 insertions(+) diff --git a/py_clob_client/client.py b/py_clob_client/client.py index a63958f..86b6372 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -44,6 +44,7 @@ GET_PRICES, GET_SPREAD, GET_SPREADS, + GET_PRICE_HISTORY ) from .clob_types import ( ApiCreds, @@ -717,6 +718,18 @@ def get_market_trades_events(self, condition_id): Get the market's trades events by condition id """ return get("{}{}{}".format(self.host, GET_MARKET_TRADES_EVENTS, condition_id)) + + def get_price_history_between_timestamps(self, token_id, start_ts, end_ts, fidelity): + """ + Get the price history for a market between two timestamps + """ + return get("{}{}?market={}&startTs={}&endTs={}&fidelity={}".format(self.host, GET_PRICE_HISTORY, token_id, start_ts, end_ts, fidelity)) + + def get_price_history_for_interval(self, token_id, interval, fidelity): + """ + Get the price history for a market for a certain interval ending at the current time + """ + return get("{}{}?market={}&interval={}&fidelity={}".format(self.host, GET_PRICE_HISTORY, token_id, interval, fidelity)) def calculate_market_price(self, token_id: str, side: str, amount: float) -> float: """ diff --git a/py_clob_client/endpoints.py b/py_clob_client/endpoints.py index 32eed93..955cc8f 100644 --- a/py_clob_client/endpoints.py +++ b/py_clob_client/endpoints.py @@ -35,3 +35,4 @@ GET_MARKETS = "/markets" GET_MARKET = "/markets/" GET_MARKET_TRADES_EVENTS = "/live-activity/events/" +GET_PRICE_HISTORY = "/prices-history" \ No newline at end of file