From 088458d5a0105c9c7ede50bfce3d8ea0dc59f3cd Mon Sep 17 00:00:00 2001 From: Anatoly Date: Tue, 21 Jan 2025 02:14:22 +0700 Subject: [PATCH] Add price history method --- examples/get_price_history.py | 17 +++++++++++++++++ py_clob_client/client.py | 14 ++++++++++++++ py_clob_client/endpoints.py | 1 + 3 files changed, 32 insertions(+) create mode 100644 examples/get_price_history.py diff --git a/examples/get_price_history.py b/examples/get_price_history.py new file mode 100644 index 0000000..86ffd3e --- /dev/null +++ b/examples/get_price_history.py @@ -0,0 +1,17 @@ +from py_clob_client.client import ClobClient + + +def main(): + host = "http://localhost:8080" + client = ClobClient(host) + + resp = client.get_price_history_with_interval( + "5114173491195416254365602929074381343823182276653657249022440867189120977342", + "1d", + 60, + ) + print(resp) + print("Done!") + + +main() diff --git a/py_clob_client/client.py b/py_clob_client/client.py index 7b97d21..9037071 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -45,6 +45,7 @@ GET_PRICES, GET_SPREAD, GET_SPREADS, + GET_PRICE_HISTORY, ) from .clob_types import ( ApiCreds, @@ -745,3 +746,16 @@ def calculate_market_price(self, token_id: str, side: str, amount: float) -> flo if book.bids is None: raise Exception("no match") return self.builder.calculate_sell_market_price(book.bids, amount) + + def get_price_history_with_interval(self, token_id: str, interval: str, fidelity: str): + """ + Get the price history for a given token_id with interval. + startTs/endTs are mutually exclusive to interval. + """ + return get("{}{}?market={}&interval={}&fidelity={}".format(self.host, GET_PRICE_HISTORY, token_id, interval, fidelity)) + + def get_price_history_with_timestamps(self, token_id: str, startTs: int, endTs: int, fidelity: str): + """ + Get the price history for a given token_id with timestamps + """ + return get("{}{}?market={}&startTs={}&endTs={}&fidelity={}".format(self.host, GET_PRICE_HISTORY, token_id, startTs, endTs, fidelity)) diff --git a/py_clob_client/endpoints.py b/py_clob_client/endpoints.py index 071c064..491e02f 100644 --- a/py_clob_client/endpoints.py +++ b/py_clob_client/endpoints.py @@ -36,3 +36,4 @@ GET_MARKETS = "/markets" GET_MARKET = "/markets/" GET_MARKET_TRADES_EVENTS = "/live-activity/events/" +GET_PRICE_HISTORY = "/prices-history"