3333
3434__author__ = 'gsibble'
3535
36- from oauth2client .client import AccessTokenRefreshError , OAuth2Credentials , AccessTokenCredentialsError
36+ from oauth2client .client import AccessTokenRefreshError , OAuth2Credentials , \
37+ AccessTokenCredentialsError
3738
3839import requests
3940import httplib2
@@ -59,8 +60,8 @@ def __init__(self,
5960 oauth2_credentials = None ,
6061 api_key = None ):
6162 """
62-
63- :param oauth2_credentials: JSON representation of Coinbase oauth2 credentials
63+ :param oauth2_credentials: JSON representation of Coinbase oauth2
64+ credentials
6465 :param api_key: Coinbase API key
6566 """
6667
@@ -81,7 +82,8 @@ def __init__(self,
8182 self .http = httplib2 .Http (ca_certs = ca_path )
8283
8384 #Create our credentials from the JSON sent
84- self .oauth2_credentials = OAuth2Credentials .from_json (oauth2_credentials )
85+ self .oauth2_credentials = \
86+ OAuth2Credentials .from_json (oauth2_credentials )
8587
8688 #Check our token
8789 self .token_expired = False
@@ -115,7 +117,7 @@ def _check_oauth_expired(self):
115117 """
116118
117119 #Check if they are expired
118- if self .oauth2_credentials .access_token_expired == True :
120+ if self .oauth2_credentials .access_token_expired :
119121
120122 #Print an notification message if they are
121123 print 'oAuth2 Token Expired'
@@ -127,7 +129,8 @@ def refresh_oauth(self):
127129 """
128130 Refresh our oauth2 token
129131 :return: JSON representation of oauth token
130- :raise: AccessTokenRefreshError if there was an error refreshing the token
132+ :raise: AccessTokenRefreshError if there was an error refreshing the
133+ token
131134 """
132135
133136 #See if we can refresh the token
@@ -136,7 +139,6 @@ def refresh_oauth(self):
136139 self .oauth2_credentials .refresh (http = self .http )
137140
138141 #We were successful
139- #print 'Your token was refreshed with the following response...'
140142
141143 #Return the token for storage
142144 return self .oauth2_credentials
@@ -223,28 +225,24 @@ def sell_price(self, qty=1):
223225 results = response .json ()
224226 return CoinbaseAmount (results ['amount' ], results ['currency' ])
225227
226- # @property
227- # def user(self):
228- # url = COINBASE_ENDPOINT + '/account/receive_address'
229- # response = self.session.get(url)
230- # return response.json()
231-
232-
233228 def buy_btc (self , qty , pricevaries = False ):
234229 """
235230 Buy BitCoin from Coinbase for USD
236231 :param qty: BitCoin quantity to be bought
237- :param pricevaries: Boolean value that indicates whether or not the transaction should
238- be processed if Coinbase cannot gaurentee the current price.
239- :return: CoinbaseTransfer with all transfer details on success or
240- CoinbaseError with the error list received from Coinbase on failure
232+ :param pricevaries: Boolean value that indicates whether or not the
233+ transaction should be processed if Coinbase cannot guarantee
234+ the current price.
235+ :return: CoinbaseTransfer with all transfer details on success or
236+ CoinbaseError with the error list received from Coinbase on
237+ failure
241238 """
242239 url = COINBASE_ENDPOINT + '/buys'
243240 request_data = {
244241 "qty" : qty ,
245242 "agree_btc_amount_varies" : pricevaries
246243 }
247- response = self .session .post (url = url , data = json .dumps (request_data ), params = self .global_request_params )
244+ response = self .session .post (url = url , data = json .dumps (request_data ),
245+ params = self .global_request_params )
248246 response_parsed = response .json ()
249247 if response_parsed ['success' ] == False :
250248 return CoinbaseError (response_parsed ['errors' ])
@@ -257,13 +255,15 @@ def sell_btc(self, qty):
257255 Sell BitCoin to Coinbase for USD
258256 :param qty: BitCoin quantity to be sold
259257 :return: CoinbaseTransfer with all transfer details on success or
260- CoinbaseError with the error list received from Coinbase on failure
258+ CoinbaseError with the error list received from Coinbase
259+ on failure
261260 """
262261 url = COINBASE_ENDPOINT + '/sells'
263262 request_data = {
264263 "qty" : qty ,
265264 }
266- response = self .session .post (url = url , data = json .dumps (request_data ), params = self .global_request_params )
265+ response = self .session .post (url = url , data = json .dumps (request_data ),
266+ params = self .global_request_params )
267267 response_parsed = response .json ()
268268 if response_parsed ['success' ] == False :
269269 return CoinbaseError (response_parsed ['errors' ])
@@ -310,7 +310,8 @@ def request(self, from_email, amount, notes='', currency='BTC'):
310310
311311 def send (self , to_address , amount , notes = '' , currency = 'BTC' ):
312312 """
313- Send BitCoin from this account to either an email address or a BTC address
313+ Send BitCoin from this account to either an email address or a BTC
314+ address
314315 :param to_address: Email or BTC address to where coin should be sent
315316 :param amount: Amount of currency to send
316317 :param notes: Notes to be included with transaction
@@ -338,7 +339,8 @@ def send(self, to_address, amount, notes='', currency='BTC'):
338339 }
339340 }
340341
341- response = self .session .post (url = url , data = json .dumps (request_data ), params = self .global_request_params )
342+ response = self .session .post (url = url , data = json .dumps (request_data ),
343+ params = self .global_request_params )
342344 response_parsed = response .json ()
343345
344346 if response_parsed ['success' ] == False :
@@ -413,7 +415,7 @@ def get_transaction(self, transaction_id):
413415 response = self .session .get (url , params = self .global_request_params )
414416 results = response .json ()
415417
416- if results .get ('success' , True ) == False :
418+ if not results .get ('success' , True ):
417419 pass
418420 #TODO: Add error handling
419421
@@ -461,7 +463,8 @@ def generate_receive_address(self, callback_url=None):
461463 "callback_url" : callback_url
462464 }
463465 }
464- response = self .session .post (url = url , data = json .dumps (request_data ), params = self .global_request_params )
466+ response = self .session .post (url = url , data = json .dumps (request_data ),
467+ params = self .global_request_params )
465468 return response .json ()['address' ]
466469
467470
0 commit comments