Fix API error
- Replace the old API bitcoinaverage.com by bitaps.com - Add bistamp as default exchange - remove and replace some fields to adapt the new API - Replace Bitcoin symbol by \uF15A
This commit is contained in:
parent
29a4cb74d8
commit
211ece568c
@ -28,8 +28,8 @@ class Bitcoin(IntervalModule):
|
|||||||
"""
|
"""
|
||||||
This module fetches and displays current Bitcoin market prices and
|
This module fetches and displays current Bitcoin market prices and
|
||||||
optionally monitors transactions to and from a list of user-specified
|
optionally monitors transactions to and from a list of user-specified
|
||||||
wallet addresses. Market data is pulled from the BitcoinAverage Price
|
wallet addresses. Market data is pulled from the Bitaps Market
|
||||||
Index API <https://bitcoinaverage.com> and it is possible to specify
|
API <https://bitaps.com> and it is possible to specify
|
||||||
the exchange to be monitored.
|
the exchange to be monitored.
|
||||||
Transaction data is pulled from blockchain.info
|
Transaction data is pulled from blockchain.info
|
||||||
<https://blockchain.info/api/blockchain_api>.
|
<https://blockchain.info/api/blockchain_api>.
|
||||||
@ -39,7 +39,7 @@ class Bitcoin(IntervalModule):
|
|||||||
* {last_price}
|
* {last_price}
|
||||||
* {ask_price}
|
* {ask_price}
|
||||||
* {bid_price}
|
* {bid_price}
|
||||||
* {daily_average}
|
* {open_price}
|
||||||
* {volume}
|
* {volume}
|
||||||
* {volume_thousand}
|
* {volume_thousand}
|
||||||
* {volume_percent}
|
* {volume_percent}
|
||||||
@ -69,8 +69,8 @@ class Bitcoin(IntervalModule):
|
|||||||
)
|
)
|
||||||
format = "{symbol} {status}{last_price}"
|
format = "{symbol} {status}{last_price}"
|
||||||
currency = "USD"
|
currency = "USD"
|
||||||
exchange = None
|
exchange = "bitstamp"
|
||||||
symbol = "฿"
|
symbol = "\uF15A"
|
||||||
wallet_addresses = ""
|
wallet_addresses = ""
|
||||||
color = "#FFFFFF"
|
color = "#FFFFFF"
|
||||||
colorize = False
|
colorize = False
|
||||||
@ -83,7 +83,7 @@ class Bitcoin(IntervalModule):
|
|||||||
}
|
}
|
||||||
|
|
||||||
on_leftclick = "electrum"
|
on_leftclick = "electrum"
|
||||||
on_rightclick = ["open_something", "https://bitcoinaverage.com/"]
|
on_rightclick = ["open_something", "https://bitaps.com/"]
|
||||||
|
|
||||||
_price_prev = 0
|
_price_prev = 0
|
||||||
|
|
||||||
@ -95,25 +95,17 @@ class Bitcoin(IntervalModule):
|
|||||||
return int(diff.total_seconds())
|
return int(diff.total_seconds())
|
||||||
|
|
||||||
def _query_api(self, api_url):
|
def _query_api(self, api_url):
|
||||||
url = "{}BTC{}".format(api_url, self.currency.upper())
|
url = "{}/{}".format(api_url, self.exchange.upper())
|
||||||
response = urllib.request.urlopen(url).read().decode("utf-8")
|
response = urllib.request.urlopen(url).read().decode("utf-8")
|
||||||
return json.loads(response)
|
return json.loads(response)
|
||||||
|
|
||||||
def _fetch_price_data(self):
|
def _fetch_price_data(self):
|
||||||
if self.exchange is None:
|
api_url = "https://api.bitaps.com/market/v1/tickers"
|
||||||
api_url = "https://apiv2.bitcoinaverage.com/indices/global/ticker/"
|
ret = self._query_api(api_url)["data"]
|
||||||
return self._query_api(api_url)
|
exchange = ret[self.exchange.upper()]["pairs"]["BTC{}".format(self.currency.upper())]
|
||||||
else:
|
# Adapt values to global ticker format
|
||||||
api_url = "https://api.bitcoinaverage.com/exchanges/"
|
exchange['24h_avg'] = None
|
||||||
ret = self._query_api(api_url)
|
return exchange
|
||||||
exchange = ret[self.exchange.lower()]
|
|
||||||
# Adapt values to global ticker format
|
|
||||||
exchange['ask'] = exchange['rates']['ask']
|
|
||||||
exchange['bid'] = exchange['rates']['bid']
|
|
||||||
exchange['last'] = exchange['rates']['last']
|
|
||||||
exchange['24h_avg'] = None
|
|
||||||
exchange['timestamp'] = ret['timestamp']
|
|
||||||
return exchange
|
|
||||||
|
|
||||||
def _fetch_blockchain_data(self):
|
def _fetch_blockchain_data(self):
|
||||||
api = "https://blockchain.info/multiaddr?active="
|
api = "https://blockchain.info/multiaddr?active="
|
||||||
@ -127,13 +119,12 @@ class Bitcoin(IntervalModule):
|
|||||||
|
|
||||||
fdict = {
|
fdict = {
|
||||||
"symbol": self.symbol,
|
"symbol": self.symbol,
|
||||||
"daily_average": price_data["averages"]["day"],
|
"open": price_data["open"],
|
||||||
"ask_price": price_data["ask"],
|
"ask_price": price_data["ask"],
|
||||||
"bid_price": price_data["bid"],
|
"bid_price": price_data["bid"],
|
||||||
"last_price": price_data["last"],
|
"last_price": price_data["last"],
|
||||||
"volume": price_data["volume"],
|
"volume": price_data["volume"],
|
||||||
"volume_thousand": float(price_data["volume"]) / 1000,
|
"volume_thousand": float(price_data["volume"]) / 1000,
|
||||||
"volume_percent": price_data["volume_percent"],
|
|
||||||
"age": self._get_age(price_data['timestamp'])
|
"age": self._get_age(price_data['timestamp'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user