Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
crypto-chat/logic/coin.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
77 lines (65 sloc)
3 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
class Coin: | |
def __init__(self): | |
self.coinId = None | |
self.headers = { | |
"X-RapidAPI-Key": "eeb1cf1684msh83985ef0f081d92p1754ddjsn6941f32fe3d1", | |
"X-RapidAPI-Host": "coinranking1.p.rapidapi.com" | |
} | |
def apiAllCoin(self): | |
# we're getting all the coins | |
url = 'https://coinranking1.p.rapidapi.com/coins' | |
querystring = {"referenceCurrencyUuid": "yhjMzLPhuIDl", "timePeriod": "24h", | |
"tiers[0]": "1", "orderBy": "marketCap", "orderDirection": "desc", "limit": "50", "offset": "0"} | |
val = requests.get(url, headers=self.headers, params=querystring) | |
data = json.loads(val.text) | |
return data | |
def apiCoin(self): | |
# we're getting all the coins | |
url = 'https://coinranking1.p.rapidapi.com/coin/' + self.coinId | |
querystring = { | |
"referenceCurrencyUuid": "yhjMzLPhuIDl", "timePeriod": "24h"} | |
val = requests.get(url, headers=self.headers, params=querystring) | |
data = json.loads(val.text) | |
return data | |
def getAllCoin(self): | |
data = self.apiAllCoin() | |
# print(val.text) | |
print("\n") | |
print("Total Coins: ", data["data"]["stats"]["totalCoins"]) | |
for coin in data["data"]["coins"]: | |
print("-----------------------------------------------------------------------------------------\n") | |
print("\033[1;3mRanking:\033[0m ", coin["rank"]) | |
print("\033[1;3mSymbol:\033[0m ", coin["symbol"]) | |
print("\033[1;3mCoin name:\033[0m ", coin["name"]) | |
print("\033[1;3mBTC Price:\033[0m ", coin["btcPrice"]) | |
print("\033[1;3mMarket Cap:\033[0m ", coin["marketCap"]) | |
print("\033[1;3mPrice:\033[0m ", coin["price"]) | |
print("\033[1;3mImage Link:\033[0m ", coin["iconUrl"]) | |
return True | |
def getCoin(self, coinName): | |
data = self.apiAllCoin() | |
for x in data["data"]["coins"]: | |
if x["symbol"].lower() == coinName: | |
self.coinId = x["uuid"] | |
val = self.apiCoin() | |
coin = val["data"]["coin"] | |
print("-----------------------------------------------------------------------------------------\n") | |
print("\033[1;3mUUID:\033[0m ", coin["uuid"]) | |
print("\033[1;3mRanking:\033[0m ", coin["rank"]) | |
print("\033[1;3mSymbol:\033[0m ", coin["symbol"]) | |
print("\033[1;3mCoin name:\033[0m ", coin["name"]) | |
print("\033[1;3mBTC Price:\033[0m ", coin["btcPrice"]) | |
print("\033[1;3mMarket Cap:\033[0m ", coin["marketCap"]) | |
print("\033[1;3mPrice:\033[0m ", coin["price"]) | |
print("\033[1;3mImage Link:\033[0m ", coin["iconUrl"]) | |
print("\033[1;3mNumber Of Exchanges:\033[0m ", coin["numberOfExchanges"]) | |
print("\033[1;3mWebsite:\033[0m ", coin["websiteUrl"]) | |
print("\033[1;3mNumber Of Markets:\033[0m ", coin["numberOfMarkets"]) | |
print("\033[1;3mPrice At:\033[0m ", coin["priceAt"]) | |
print("\033[1;3m24hVolume:\033[0m ", coin["24hVolume"]) | |
print("\033[1;3mFully Diluted Market Cap:\033[0m ", coin["fullyDilutedMarketCap"]) | |
print("\033[1;3mCoin Ranking Url:\033[0m ", coin["coinrankingUrl"]) | |
print("\033[1;3mChange:\033[0m ", coin["change"]) | |
return True | |