Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New endpoint: price history #114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/get_price_history.py
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 14 additions & 0 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
GET_PRICES,
GET_SPREAD,
GET_SPREADS,
GET_PRICE_HISTORY,
)
from .clob_types import (
ApiCreds,
Expand Down Expand Up @@ -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))
1 change: 1 addition & 0 deletions py_clob_client/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
GET_MARKETS = "/markets"
GET_MARKET = "/markets/"
GET_MARKET_TRADES_EVENTS = "/live-activity/events/"
GET_PRICE_HISTORY = "/prices-history"