Last active
August 3, 2017 02:51
-
-
Save amustafa/d16042c66490bc8bfd82b7e08847bfcc to your computer and use it in GitHub Desktop.
Python API of GET functions for Shapeshift.io
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
import requests | |
BASE_URL = 'https://shapeshift.io/%s' | |
def _shapeshift_get_request(url_path): | |
""" | |
Combines the provided url_path with Shapeshift's base url and performs a get request. | |
""" | |
url = BASE_URL % url_path | |
response = requests.get(url) | |
return response.json() | |
def _shapeshift_post_request(url_path, payload): | |
""" | |
Combines the provided url_path with Shapeshift's base url and performs | |
a post request with the provided payoad | |
""" | |
url = BASE_URL % url_path | |
# Filter out any values that are None | |
payload = {k: v for k, v in payload.items() if v is not None} | |
response = requests.post(url, data=payload) | |
return response.json() | |
def get_coins(): | |
url_path = 'getcoins' | |
return _shapeshift_get_request(url_path) | |
def get_rate(input_coin, output_coin): | |
url_path = "rate/{}_{}".format(input_coin, output_coin) | |
return _shapeshift_get_request(url_path) | |
def get_deposit_limit(input_coin, output_coin): | |
url_path = "limit/{}_{}".format(input_coin, output_coin) | |
return _shapeshift_get_request(url_path) | |
def get_market_info(input_coin, output_coin): | |
url_path = "marketinfo/{}_{}".format(input_coin, output_coin) | |
return _shapeshift_get_request(url_path) | |
def get_recent_tx_list(max_transactions): | |
# Condition from shapeshift documentation. | |
assert 1 <= max_transactions <= 50 | |
url_path = "recenttx/{}".format(max_transactions) | |
return _shapeshift_get_request(url_path) | |
def get_tx_status(address): | |
url_path = "txStat/{}".format(address) | |
return _shapeshift_get_request(url_path) | |
def get_time_remaining_on_fixed_tx(address): | |
url_path = "timeremaining/{}".format(address) | |
return _shapeshift_get_request(url_path) | |
def get_tx_by_api_key(api_key): | |
url_path = "txbyapikey/{}".format(api_key) | |
return _shapeshift_get_request(url_path) | |
def get_tx_by_address(address, api_key): | |
url_path = "txbyapikey/{}/{}".format(address, api_key) | |
return _shapeshift_get_request(url_path) | |
def validate_address(address, coin_symbol): | |
url_path = "validateAddress/{}/{}".format(address, coin_symbol) | |
return _shapeshift_get_request(url_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment