blob: d360477ecc8a7b270f4081030a34eda609c4ec1c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import cachetools
import requests
@cachetools.cached(cachetools.TTLCache(32, 600))
def get_exchange_rate(currency='PLN'):
# Returns current exchange rate for selected currency
return requests.get('https://blockchain.info/pl/ticker').json()[currency]['last']
def to_local_currency(sat):
# Returns satoshi in local lowest denomination currency (grosze)
rate = get_exchange_rate()
return int(sat / 1000000.0 * rate)
def from_local_currency(val):
# Returns satoshi value from local currency
rate = get_exchange_rate()
return int(val / rate * 1000000)
def sat_to_btc(amount):
# Converts satoshi to BTC
return amount / 100000000.0
def format_btc(amount):
# Formats satoshi to human-readable format
return (u'฿%.8f' % (sat_to_btc(amount),)).rstrip('0').rstrip('.')
|