diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd20fdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +*.pyc diff --git a/shapeshiftio/shapeshiftio.py b/shapeshiftio/shapeshiftio.py index b46e0ba..19d4033 100644 --- a/shapeshiftio/shapeshiftio.py +++ b/shapeshiftio/shapeshiftio.py @@ -1,9 +1,9 @@ #!/usr/bin/python - -import urllib -import urllib2 +from future.standard_library import install_aliases +from urllib.parse import urlencode +from urllib.request import urlopen, Request import json - +install_aliases() class ShapeShiftIO: @@ -11,16 +11,16 @@ def __init__(self): """ https://shapeshift.io/api """ - self.baseurl = "https://shapeshift.io" + self.base_url = "https://shapeshift.io" def get_request(self, url): - ret = urllib2.urlopen(urllib2.Request(url)) + ret = urlopen(Request(url)) return json.loads(ret.read()) def post_request(self, url, postdata): - ret = urllib2.urlopen(urllib2.Request(url, urllib.urlencode(postdata))) + ret = urlopen(Request(url, urlencode(postdata))) return json.loads(ret.read()) @@ -37,7 +37,7 @@ def rate(self, pair): "rate" : "70.1234" } """ - self.url = self.baseurl + "/rate/" + pair + self.url = self.base_url + "/rate/" + pair return self.get_request(self.url) def limit(self, pair): @@ -52,7 +52,7 @@ def limit(self, pair): "limit" : "1.2345" } """ - self.url = self.baseurl + "/limit/" + pair + self.url = self.base_url + "/limit/" + pair return self.get_request(self.url) def market_info(self, pair): @@ -63,16 +63,16 @@ def market_info(self, pair): The pair is not required and if not specified will return an array of all market infos. Success Output: - { - "pair" : "btc_ltc", + { + "pair" : "btc_ltc", "rate" : 130.12345678, "limit" : 1.2345, - "min" : 0.02621232, + "min" : 0.02621232, "minerFee" : 0.0001 } """ - self.url = self.baseurl + "/marketinfo/" + pair + self.url = self.base_url + "/marketinfo/" + pair return self.get_request(self.url) def recent_tx(self, max_results=5): @@ -93,7 +93,7 @@ def recent_tx(self, max_results=5): ... ] """ - self.url = self.baseurl + "/recenttx/" + str(max_results) + self.url = self.base_url + "/recenttx/" + str(max_results) return self.get_request(self.url) def tx_status(self, address): @@ -133,7 +133,7 @@ def tx_status(self, address): error: [Text describing failure] } """ - self.url = self.baseurl + "/txStat/" + address + self.url = self.base_url + "/txStat/" + address return self.get_request(self.url) def time_remaining(self, address): @@ -151,7 +151,7 @@ def time_remaining(self, address): The status can be either "pending" or "expired". If the status is expired then seconds_remaining will show 0. """ - self.url = self.baseurl + "/timeremaining/" + address + self.url = self.base_url + "/timeremaining/" + address return self.get_request(self.url) def coin_list(self): @@ -172,35 +172,35 @@ def coin_list(self): The status can be either "available" or "unavailable". Sometimes coins become temporarily unavailable during updates or unexpected service issues. """ - self.url = self.baseurl + "/getcoins" + self.url = self.base_url + "/getcoins" return self.get_request(self.url) def tx_by_apikey(self, apiKey): - """ - Allows vendors to get a list of all transactions that have ever been done using a specific API key. Transactions are created with an affilliate PUBLIC KEY, but they are looked up using the linked PRIVATE KEY, to protect the privacy of our affiliates' account details. - - [apiKey] is the affiliate's PRIVATE api key. - - [ - { - inputTXID: [Transaction ID of the input coin going into shapeshift], - inputAddress: [Address that the input coin was paid to for this shift], - inputCurrency: [Currency type of the input coin], - inputAmount: [Amount of input coin that was paid in on this shift], - outputTXID: [Transaction ID of the output coin going out to user], - outputAddress: [Address that the output coin was sent to for this shift], - outputCurrency: [Currency type of the output coin], - outputAmount: [Amount of output coin that was paid out on this shift], - shiftRate: [The effective rate the user got on this shift.], - status: [status of the shift] - } - (one listing per transaction returned) - ] - - The status can be "received", "pending", "verifying_send", "sent_exact", "exchanged". "sent_exact" is the same as - "exchanged", for all intensive purposes, meaning the shift completed, funds were sent in and out and there was no error. - """ - self.url = self.baseurl + "/txbyapikey/" + apiKey + """ + Allows vendors to get a list of all transactions that have ever been done using a specific API key. Transactions are created with an affilliate PUBLIC KEY, but they are looked up using the linked PRIVATE KEY, to protect the privacy of our affiliates' account details. + + [apiKey] is the affiliate's PRIVATE api key. + + [ + { + inputTXID: [Transaction ID of the input coin going into shapeshift], + inputAddress: [Address that the input coin was paid to for this shift], + inputCurrency: [Currency type of the input coin], + inputAmount: [Amount of input coin that was paid in on this shift], + outputTXID: [Transaction ID of the output coin going out to user], + outputAddress: [Address that the output coin was sent to for this shift], + outputCurrency: [Currency type of the output coin], + outputAmount: [Amount of output coin that was paid out on this shift], + shiftRate: [The effective rate the user got on this shift.], + status: [status of the shift] + } + (one listing per transaction returned) + ] + + The status can be "received", "pending", "verifying_send", "sent_exact", "exchanged". "sent_exact" is the same as + "exchanged", for all intensive purposes, meaning the shift completed, funds were sent in and out and there was no error. + """ + self.url = self.base_url + "/txbyapikey/" + apiKey return self.get_request(self.url) def tx_by_address(self, apiKey, address): @@ -231,7 +231,7 @@ def tx_by_address(self, apiKey, address): The status can be "received", "pending", "verifying_send", "sent_exact", "exchanged". "sent_exact" is the same as "exchanged", for all intensive purposes, meaning the shift completed, funds were sent in and out and there was no error. """ - self.url = self.baseurl + "/txbyaddress/" + address + "/" + apiKey + self.url = self.base_url + "/txbyaddress/" + address + "/" + apiKey return self.get_request(self.url) def validate_address(self, address, coin): @@ -250,12 +250,12 @@ def validate_address(self, address, coin): isValid will either be true or false. If isvalid returns false, an error parameter will be present and will contain a descriptive error message. """ - self.url = self.baseurl + "/validateAddress/" + address + "/" + coin + self.url = self.base_url + "/validateAddress/" + address + "/" + coin return self.get_request(self.url) def shift(self, postdata): - """ - This is the primary data input into ShapeShift. + """ + This is the primary data input into ShapeShift. data required: withdrawal = the address for resulting coin to be sent to @@ -278,12 +278,12 @@ def shift(self, postdata): apiPubKey: [public API attached to this shift, if one was given] } """ - self.url = self.baseurl + "/shift" + self.url = self.base_url + "/shift" return self.post_request(self.url, postdata) def set_mail(self, postdata): - """ - This call requests a receipt for a transaction. The email address will be added to the conduit associated with that transaction as well. (Soon it will also send receipts to subsequent transactions on that conduit) + """ + This call requests a receipt for a transaction. The email address will be added to the conduit associated with that transaction as well. (Soon it will also send receipts to subsequent transactions on that conduit) data required: email = the address for receipt email to be sent to @@ -298,13 +298,13 @@ def set_mail(self, postdata): } } """ - self.url = self.baseurl + "/mail" + self.url = self.base_url + "/mail" return self.post_request(self.url, postdata) def send_amount(self, postdata): - """ - This call allows you to request a fixed amount to be sent to the withdrawal address. You provide a withdrawal address and the amount you want sent to it. We return the amount to deposit and the address to deposit to. This allows you to use shapeshift as a payment mechanism. This call also allows you to request a quoted price on the amount of a transaction without a withdrawal address. - //1. Send amount request + """ + This call allows you to request a fixed amount to be sent to the withdrawal address. You provide a withdrawal address and the amount you want sent to it. We return the amount to deposit and the address to deposit to. This allows you to use shapeshift as a payment mechanism. This call also allows you to request a quoted price on the amount of a transaction without a withdrawal address. + //1. Send amount request Data required: @@ -367,12 +367,12 @@ def send_amount(self, postdata): } } """ - self.url = self.baseurl + "/sendamount" + self.url = self.base_url + "/sendamount" return self.post_request(self.url, postdata) def cancel_pending(self, postdata): - """ - This call allows you to request for canceling a pending transaction by the deposit address. If there is fund sent to the deposit address, this pending transaction cannot be canceled. + """ + This call allows you to request for canceling a pending transaction by the deposit address. If there is fund sent to the deposit address, this pending transaction cannot be canceled. data required: address = The deposit address associated with the pending transaction @@ -386,5 +386,5 @@ def cancel_pending(self, postdata): { error : {errorMessage} } """ - self.url = self.baseurl + "/cancelpending" + self.url = self.base_url + "/cancelpending" return self.post_request(self.url, postdata)