Created
March 12, 2024 09:49
-
-
Save sourabhxyz/6bbbfc926ff94c319576303acd257ef1 to your computer and use it in GitHub Desktop.
Python Client for `dex-contracts-api`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python client generated using [`servant-py`](https://github.com/erewok/servant-py) for [`dex-contracts-api`](https://github.com/geniusyield/dex-contracts-api). | |
from urllib import parse | |
import requests | |
def get_v0_settings(headerapikey): | |
""" | |
GET "v0/settings" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/settings" | |
headers = {"api-key": headerapikey} | |
resp = requests.get(url, | |
headers=headers) | |
resp.raise_for_status() | |
return resp.json() | |
def post_v0_orders_tx_buildopen(data, headerapikey): | |
""" | |
POST "v0/orders/tx/build-open" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/orders/tx/build-open" | |
headers = {"api-key": headerapikey} | |
resp = requests.post(url, | |
headers=headers, | |
json=data) | |
resp.raise_for_status() | |
return resp.json() | |
def post_v0_orders(data, headerapikey): | |
""" | |
POST "v0/orders" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/orders" | |
headers = {"api-key": headerapikey} | |
resp = requests.post(url, | |
headers=headers, | |
json=data) | |
resp.raise_for_status() | |
return resp.json() | |
def post_v0_orders_tx_buildcancel(data, headerapikey): | |
""" | |
POST "v0/orders/tx/build-cancel" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/orders/tx/build-cancel" | |
headers = {"api-key": headerapikey} | |
resp = requests.post(url, | |
headers=headers, | |
json=data) | |
resp.raise_for_status() | |
return resp.json() | |
def delete_v0_orders(data, headerapikey): | |
""" | |
DELETE "v0/orders" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/orders" | |
headers = {"api-key": headerapikey} | |
resp = requests.delete(url, | |
headers=headers, | |
json=data) | |
resp.raise_for_status() | |
return resp.json() | |
def get_v0_markets(headerapikey): | |
""" | |
GET "v0/markets" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/markets" | |
headers = {"api-key": headerapikey} | |
resp = requests.get(url, | |
headers=headers) | |
resp.raise_for_status() | |
return resp.json() | |
def post_v0_tx_sign(data, headerapikey): | |
""" | |
POST "v0/tx/sign" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/tx/sign" | |
headers = {"api-key": headerapikey} | |
resp = requests.post(url, | |
headers=headers, | |
json=data) | |
resp.raise_for_status() | |
return resp.json() | |
def post_v0_tx_signandsubmit(data, headerapikey): | |
""" | |
POST "v0/tx/sign-and-submit" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/tx/sign-and-submit" | |
headers = {"api-key": headerapikey} | |
resp = requests.post(url, | |
headers=headers, | |
json=data) | |
resp.raise_for_status() | |
return resp.json() | |
def post_v0_tx_submit(data, headerapikey): | |
""" | |
POST "v0/tx/submit" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/tx/submit" | |
headers = {"api-key": headerapikey} | |
resp = requests.post(url, | |
headers=headers, | |
json=data) | |
resp.raise_for_status() | |
return resp.json() | |
def get_v0_tradingfees(headerapikey): | |
""" | |
GET "v0/trading-fees" | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/trading-fees" | |
headers = {"api-key": headerapikey} | |
resp = requests.get(url, | |
headers=headers) | |
resp.raise_for_status() | |
return resp.json() | |
def get_v0_assets_by_asset(asset, headerapikey): | |
""" | |
GET "v0/assets/{asset}" | |
Args: | |
asset | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/assets/{asset}".format( | |
asset=parse.quote(str(asset))) | |
headers = {"api-key": headerapikey} | |
resp = requests.get(url, | |
headers=headers) | |
resp.raise_for_status() | |
return resp.json() | |
def get_v0_orderbook_by_marketid(marketId, address, headerapikey): | |
""" | |
GET "v0/order-book/{market-id}" | |
Args: | |
market-id | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/order-book/{market-id}".format( | |
marketId=parse.quote(str(marketId))) | |
headers = {"api-key": headerapikey} | |
params = {"address": address} | |
resp = requests.get(url, | |
headers=headers, | |
params=params) | |
resp.raise_for_status() | |
return resp.json() | |
def get_v0_historicalprices_maestro_by_marketid_by_dex(marketId, dex, resolution, from_, to, limit, sort, headerapikey): | |
""" | |
GET "v0/historical-prices/maestro/{market-id}/{dex}" | |
Args: | |
market-id | |
dex | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/historical-prices/maestro/{market-id}/{dex}".format( | |
marketId=parse.quote(str(marketId)), | |
dex=parse.quote(str(dex))) | |
headers = {"api-key": headerapikey} | |
params = {"resolution": resolution, | |
"from": from_, | |
"to": to, | |
"limit": limit, | |
"sort": sort} | |
resp = requests.get(url, | |
headers=headers, | |
params=params) | |
resp.raise_for_status() | |
return resp.json() | |
def get_v0_balances_by_address(address, headerapikey): | |
""" | |
GET "v0/balances/{address}" | |
Args: | |
address | |
Returns: | |
JSON response from the endpoint | |
""" | |
url = "http://localhost:8082/v0/balances/{address}".format( | |
address=parse.quote(str(address))) | |
headers = {"api-key": headerapikey} | |
resp = requests.get(url, | |
headers=headers) | |
resp.raise_for_status() | |
return resp.json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment