import requests
def get_info():
response = requests.get(url='
https://yobit.net/api/3/info')
with open("info.txt", "w") as file:
file.write(response.text)
return response.text
def get_ticker(coin1="btc", coin2="usd"):
response = requests.get(url=f'
https://yobit.net/api/3/ticker/{coin1}_{coin2}?ign...')
with open("ticker.txt", "w") as file:
file.write(response.text)
return response.text
def get_depth(coin1="btc", coin2="usd", limit=150):
response = requests.get(url=f'
https://yobit.net/api/3/depth/{coin1}_{coin2}?limi...')
with open("depth.txt", "w") as file:
file.write(response.text)
bids = response.json()[f"{coin1}_usd"]["bids"]
total_bids_amount = 0
for item in bids:
price = item[0]
coin_amount = item[1]
total_bids_amount += price * coin_amount
return f"Total bids: {total_bids_amount} $"
def get_trades(coin1="btc", coin2="usd", limit=150):
response = requests.get(url=f'
https://yobit.net/api/3/trades/{coin1}_{coin2}?lim...')
with open("trades.txt", "w") as file:
file.write(response.text)
total_trade_ask = 0
total_trade_bid = 0
for item in response.json()[f"{coin1}_{coin2}"]:
if item["type"] == ["ask"]:
total_trade_ask += item["price"] * item["amount"]
else:
total_trade_bid += item["price"] * item["amount"]
info = f"[-] TOTAL {coin1} SELL: {round(total_trade_ask, 2)} $\n[+] TOTAL {coin1} BUY: {round(total_trade_bid, 2)} $"
return info
def main():
#print(get_info())
#print(get_ticker())
#print(get_ticker(coin1="eth"))
#print(get_depth())
#print(get_depth(coin1="doge", limit=2000))
print(get_trades())
if __name__ == '__main__':
main()
Вот сам код при запуске должен выдавать:
[-] TOTAL btc SELL: 0 Тут постоянно ноль, хотя так не должно быть $
[+] TOTAL btc BUY: 5670.6 Тут все верно, но не обновляется $
Списывал ход с канала PythonToday первый ролик на тему парсинга крипты