52 lines
1.6 KiB
Python

#!/usr/bin/env python
from flask import Flask
import json
from pricing.exchanges.coinbase import coinbasePublicTicker
import logging as logger
logger.basicConfig(
level=logger.INFO,
format="%(asctime)s: %(levelname)s -- %(message)s",
datefmt='%Y-%m-%d %H:%M:%S'
)
app = Flask(__name__)
@app.route('/health')
def health():
return json.dumps({'status': 'UP'}), 200, {'ContentType':'application/json'}
@app.route('/readiness')
def readiness():
# Can it make a call to an exchange?
price = coinbasePublicTicker('btc_usd', logger)
if price != 0 :
return json.dumps({
'status': 'UP',
'app': {
'name': 'CryptoSky Price Collector',
'description': 'Projects Price Collector service that collects the: High, Low, Open, Close prices, Volume and calculates average price for the hour.',
'check_status': 'Success - Call to coinbase exchange',
'price': price
}
}), 200, {'ContentType': 'application/json'}
else:
return json.dumps({
'status': 'DOWN',
'app': {
'name': 'CryptoSky Price Collector',
'description': 'Projects Price Collector service that collects the: High, Low, Open, Close prices, Volume and calculates average price for the hour.',
'check_status': 'Failed - Call to coinbase exchange',
'price': price
}
}), 503, {'ContentType': 'application/json'}
def runFlaskProbes():
app.run(port=9090, host="0.0.0.0")
if __name__ == '__main__':
runFlaskProbes()