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

add price history endpoint #88

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
13 changes: 13 additions & 0 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
GET_PRICES,
GET_SPREAD,
GET_SPREADS,
GET_PRICE_HISTORY
)
from .clob_types import (
ApiCreds,
Expand Down Expand Up @@ -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:
"""
Expand Down
1 change: 1 addition & 0 deletions py_clob_client/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
GET_MARKETS = "/markets"
GET_MARKET = "/markets/"
GET_MARKET_TRADES_EVENTS = "/live-activity/events/"
GET_PRICE_HISTORY = "/prices-history"