from requests import Request, Session
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
import json
SALE_FEE = 6
API_KEY = '<ご自身の CoinMarketCap API KEYを入力>'
# APIを叩く関数
def request(url, parameters, headers):
session = Session()
session.headers.update(headers)
try:
response = session.get(url, params=parameters)
data = json.loads(response.text)
except (ConnectionError, Timeout, TooManyRedirects) as e:
print(e)
return data
# メイン処理を行う関数
def main():
if API_KEY == '<ご自身の CoinMarketCap API KEYを入力>':
print('API_KEYにAPIキーを代入してください')
return
# Mint2回、Lv5スニーカーの現在のフロア価格をコンソール入力
msl5_flor_price_sol = float(input("M2L5スニーカーのフロア価格(SOL)を入力してください。 >>\n"))
# 計算に必要な仮想通貨のレートを取得
url = 'https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest'
parameters = {
'id':'5426,16352,18069',
'convert':'USD'
}
headers = {
'Accepts': 'application/json',
'X-CMC_PRO_API_KEY': API_KEY,
}
data = request(url, parameters, headers)
# SOL, GST, GMT (USD)
sol_usd = data['data']['5426']['quote']['USD']['price']
gst_usd = data['data']['16352']['quote']['USD']['price']
gmt_usd = data['data']['18069']['quote']['USD']['price']
# USD → JPYのレートを知るために再度APIを実行
url = 'https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest'
parameters = {
'id':'5426',
'convert':'JPY'
}
data = request(url, parameters, headers)
# SOL, GST, GMT (JPY)
sol_jpy = data['data']['5426']['quote']['JPY']['price']
usd_to_jpy = sol_jpy/sol_usd
sol_jpy = sol_usd*usd_to_jpy
gst_jpy = gst_usd*usd_to_jpy
gmt_jpy = gmt_usd*usd_to_jpy
print(f'USD → JPYレート: {usd_to_jpy}\n')
print(f'SOL: {sol_jpy}円')
print(f'GST: {gst_jpy}円')
print(f'GMT: {gmt_jpy}円\n')
# MINTに必要なGST, GMT対応表
if (gst_usd < 2):
mint_take_gst = 200
mint_take_gmt = 0
elif (gst_usd < 3):
mint_take_gst = 160
mint_take_gmt = 40
elif (gst_usd < 4):
mint_take_gst = 120
mint_take_gmt = 80
elif (gst_usd < 8):
mint_take_gst = 100
mint_take_gmt = 100
elif (gst_usd < 10):
mint_take_gst = 80
mint_take_gmt = 120
else:
mint_take_gst = 40
mint_take_gmt = 160
# レベルアップに必要なGST, GMT
level_up_take_gst = 20
level_up_take_gmt = 10
# MINTループ(1回分)に必要なコストを算出
level_up_cost = level_up_take_gst*gst_jpy+level_up_take_gmt*gmt_jpy
mint_cost = mint_take_gst*gst_jpy+mint_take_gmt*gmt_jpy
m2l5_selling_price = msl5_flor_price_sol*sol_jpy*((100-SALE_FEE)*0.01)
mint_roop_cost = level_up_cost+mint_cost
mint_income_jpy = m2l5_selling_price-mint_roop_cost
print(f'm2l5売値: {m2l5_selling_price}円')
print(f'ミントまでにかかる費用(ミント費用+lv1→lv5費用): {mint_roop_cost}円')
print(f'ミント1回分の収益: {mint_income_jpy}円')
# メイン処理実行
main()