Visitar URL original
Integrate Impressive Changes by sibblegp · Pull Request #9 · sibblegp/coinbase_python · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implemented from_cents method, fixed possible bug in transfer
  • Loading branch information
sdobz committed Jan 5, 2014
commit 10e169545b94b94ad7f27ea41d4a886ce60ff858
10 changes: 9 additions & 1 deletion coinbase/models/amount.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__author__ = 'gsibble'

from decimal import Decimal
from coinbase.config import CENTS_PER_BITCOIN, CENTS_PER_OTHER

class CoinbaseAmount(Decimal):

Expand All @@ -14,4 +15,11 @@ def __init__(self, amount, currency):
def __eq__(self, other, *args, **kwargs):
if isinstance(other, self.__class__) and self.currency != other.currency:
return False
return super(CoinbaseAmount, self).__eq__(other, *args, **kwargs)
return super(CoinbaseAmount, self).__eq__(other, *args, **kwargs)

@classmethod
def from_cents(cls, cents, currency):
if currency == 'BTC':
return cls(Decimal(cents)/CENTS_PER_BITCOIN, currency)
else:
return cls(Decimal(cents)/CENTS_PER_OTHER, currency)
10 changes: 2 additions & 8 deletions coinbase/models/button.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
__author__ = 'vkhougaz'

from amount import CoinbaseAmount
from decimal import Decimal
from coinbase.config import CENTS_PER_BITCOIN, CENTS_PER_OTHER

class CoinbaseButton(object):

Expand All @@ -17,13 +15,9 @@ def __init__(self, button):

self.name = button['name']
if 'price' in button:
price = Decimal(button['price']['cents'])
price_cents = button['price']['cents']
price_currency_iso = button['price']['currency_iso']
if price_currency_iso == 'BTC':
price /= CENTS_PER_BITCOIN
else:
price /= CENTS_PER_OTHER
self.price = CoinbaseAmount(price, price_currency_iso)
self.price = CoinbaseAmount.from_cents(price_cents, price_currency_iso)
else:
self.price = None
self.type = button.get('type', None)
Expand Down
16 changes: 3 additions & 13 deletions coinbase/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from amount import CoinbaseAmount
from button import CoinbaseButton
from transaction import CoinbaseTransaction
from decimal import Decimal
from coinbase.config import CENTS_PER_BITCOIN, CENTS_PER_OTHER
# from datetime import datetime

class CoinbaseOrder(object):
Expand All @@ -16,21 +14,13 @@ def __init__(self, order):
self.status = order['status']
self.custom = order['custom']

btc_cents = Decimal(order['total_btc']['cents'])
btc_cents = order['total_btc']['cents']
btc_currency_iso = order['total_btc']['currency_iso']
if btc_currency_iso == 'BTC':
btc_cents /= CENTS_PER_BITCOIN
else:
btc_cents /= CENTS_PER_OTHER
self.total_btc = CoinbaseAmount(btc_cents, btc_currency_iso)
self.total_btc = CoinbaseAmount.from_cents(btc_cents, btc_currency_iso)

native_cents = order['total_native']['cents']
native_currency_iso = order['total_native']['currency_iso']
if native_currency_iso == 'BTC':
native_cents /= CENTS_PER_BITCOIN
else:
native_cents /= CENTS_PER_OTHER
self.total_native = CoinbaseAmount(native_cents, native_currency_iso)
self.total_native = CoinbaseAmount.from_cents(native_cents, native_currency_iso)

self.button = CoinbaseButton(order['button'])
if 'transaction' in order and order['transaction'] is not None:
Expand Down
8 changes: 4 additions & 4 deletions coinbase/models/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def __init__(self, transfer):

fees_coinbase_cents = transfer['fees']['coinbase']['cents']
fees_coinbase_currency_iso = transfer['fees']['coinbase']['currency_iso']
self.fees_coinbase = CoinbaseAmount(fees_coinbase_cents, fees_coinbase_currency_iso)
self.fees_coinbase = CoinbaseAmount.from_cents(fees_coinbase_cents, fees_coinbase_currency_iso)

fees_bank_cents = transfer['fees']['bank']['cents']
fees_bank_currency_iso = transfer['fees']['bank']['currency_iso']
self.fees_bank = CoinbaseAmount(fees_bank_cents, fees_bank_currency_iso)
self.fees_bank = CoinbaseAmount.from_cents(fees_bank_cents, fees_bank_currency_iso)

self.payout_date = transfer['payout_date']
self.transaction_id = transfer.get('transaction_id','')
self.transaction_id = transfer.get('transaction_id', '')
self.status = transfer['status']

btc_amount = transfer['btc']['amount']
Expand All @@ -33,7 +33,7 @@ def __init__(self, transfer):
total_currency = transfer['total']['currency']
self.total_amount = CoinbaseAmount(total_amount, total_currency)

self.description = transfer.get('description','')
self.description = transfer.get('description', '')

def refresh(self):
pass
Expand Down