https://realpython.com/blog/python/asynchronous-tasks-with-django-and-celery/
$ pip install celery
$ sudo apt-get install rabbitmq-server
| import requests | |
| BA_API_KEY = 'your api key here' | |
| def get_dogecoin_price(): | |
| price_url = 'https://apiv2.bitcoinaverage.com/indices/crypto/ticker/DOGEUSD' | |
| response = requests.get(price_url, headers={'x-ba-key': BA_API_KEY}) | |
| return response.json() | |
| result = get_dogecoin_price() |
| def calc_relative_diff(history_price, latest_price): | |
| price_diff = latest_price - history_price | |
| return round(price_diff / history_price, 2) | |
| def calc_volume_diff(history_volume, latest_volume): | |
| return latest_volume - history_volume | |
| def calc_market_cap_diff(market_cap, history_price, latest_price): |
| from datetime import datetime | |
| from random import randint | |
| class MovAvgCalculator: | |
| def __init__(self, starting_list=None, window_duration=3600): | |
| self.moving_average = None | |
| if starting_list: | |
| self.my_list = starting_list | |
| self.sum = sum(starting_list) |
| /** | |
| * npm install -g crypto-js | |
| * npm install -g request | |
| */ | |
| var crypto = require('crypto-js'); | |
| var public_key = 'enter your public key'; | |
| var secret_key = 'enter your secret key'; | |
| var timestamp = Math.floor(Date.now() / 1000); |
| import hashlib | |
| import hmac | |
| import requests | |
| import time | |
| secret_key = 'enter your secret key' | |
| public_key = 'enter your public key' | |
| timestamp = int(time.time()) | |
| payload = '{}.{}'.format(timestamp, public_key) | |
| hex_hash = hmac.new(secret_key.encode(), msg=payload.encode(), digestmod=hashlib.sha256).hexdigest() |
| # Install with > pip install bitcoinaverage | |
| from bitcoinaverage import TickerWebsocketClientV2 | |
| class MyWebsocketClient(TickerWebsocketClientV2): | |
| def received_message(self, message): | |
| print("Received price update") | |
| print(message) |
| // Install with: > npm install bitcoinaverage | |
| const ba = require('bitcoinaverage'); | |
| var pub = '<your public key>'; | |
| var secret = '<your secret key>'; | |
| var wsClient = ba.websocketClient(pub, secret); | |
| wsClient.connectToTickerWebsocketV2('global', ['ETHUSD', 'BCHUSD', 'LTCUSD', 'ETCUSD'], function(response) { | |
| console.log(response.data.global); |
https://realpython.com/blog/python/asynchronous-tasks-with-django-and-celery/
$ pip install celery
$ sudo apt-get install rabbitmq-server