Skip to content

Commit

Permalink
Version 0.2.4: Add ability to get fiat price in most currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNaif2018 committed Aug 5, 2019
1 parent f5323df commit 1a88338
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
32 changes: 27 additions & 5 deletions bitcart/coins/btc.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,42 @@ def pay_to(self: 'BTC', address: str, amount: float) -> str:
tx_data = self.server.payto(address, amount)
return self.server.broadcast(tx_data) # type: ignore

def rate(self: 'BTC') -> float:
"""Get bitcoin price in USD
def rate(self: 'BTC', currency: str = "USD") -> float:
"""Get bitcoin price in selected fiat currency
It uses the same method as electrum wallet gets exchange rate-via different payment providers
Example:
Examples:
>>> c.rate()
9878.527
>>> c.rate("RUB")
757108.226
Args:
self (BTC): self
currency (str, optional): [description]. Defaults to "USD".
Returns:
float: price of 1 bitcoin in selected fiat currency
"""
return self.server.exchange_rate(currency) # type: ignore

def list_fiat(self: 'BTC') -> Iterable[str]:
"""List of all available fiat currencies to get price for
This list is list of only valid currencies that could be passed to rate() function
Example:
>>> c.list_fiat()
['AED', 'ARS', 'AUD', 'BCH', 'BDT', 'BHD', 'BMD', 'BNB', 'BRL', 'BTC', ...]
Args:
self (BTC): self
Returns:
float: price of 1 bitcoin in USD
Iterable[str]: list of available fiat currencies
"""
return self.server.exchange_rate() # type: ignore
return self.server.list_currencies() # type: ignore
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
setup(
name='bitcart',
packages=find_packages(),
version='0.2.3',
version='0.2.4',
license='MIT',
description='Bitcart coins support library',
long_description=open("README.md").read(),
Expand Down

0 comments on commit 1a88338

Please sign in to comment.