Last active
August 3, 2017 02:52
-
-
Save amustafa/6d09e56e82ec609a253a9d8a8ac9806c to your computer and use it in GitHub Desktop.
POST 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
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 create_normal_tx(withdrawal_address, input_coin, output_coin, | |
return_address=None, | |
destination_tag=None, | |
rs_address=None, | |
api_key=None): | |
url_path = "shift" | |
payload = { | |
'withdrawal': withdrawal_address, | |
'pair': "{}_{}".format(input_coin, output_coin), | |
'returnAddress': return_address, | |
'destTag': destination_tag, | |
'rsAddress': rs_address, | |
'apiKey': api_key | |
} | |
return _shapeshift_post_request(url_path, payload) | |
def request_email_receipt(email, tx_id): | |
url_path = "mail" | |
payload = { | |
'email': email, | |
'txid': tx_id | |
} | |
return _shapeshift_post_request(url_path, payload) | |
def create_fixed_amount_tx(amount, withdrawal_address, input_coin, output_coin, | |
return_address=None, | |
destination_tag=None, | |
rs_address=None, | |
api_key=None): | |
url_path = "sendamount" | |
payload = { | |
'amount': amount, | |
'withdrawal': withdrawal_address, | |
'pair': "{}_{}".format(input_coin, output_coin), | |
'returnAddress': return_address, | |
'destTag': destination_tag, | |
'rsAddress': rs_address, | |
'apiKey': api_key | |
} | |
return _shapeshift_post_request(url_path, payload) | |
def cancel_tx(address): | |
url_path = "cancelpending" | |
payload = { | |
'address': address, | |
} | |
return _shapeshift_post_request(url_path, payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment