1
tập trung vào
0
Người theo dõi

Làm thế nào để đọc giá giao ngay sau mỗi 15 phút?

Được tạo ra trong: 2023-10-11 02:30:09, cập nhật trên:
comments   3
hits   829

Xin hãy đọc số tiền mặt của bạn mỗi 15 phút và vẽ một bản đồ về sự di chuyển của số tiền này.

Nhập thư viện cần thiết

import time import requests import matplotlib.pyplot as plt

Cài đặt tham số yêu cầu API

api_url = “https://api.binance.com/api/v3/account” headers = {‘X-MBX-APIKEY’: ‘wCDLQUiV6o1EDfDsEFAMDWWGqZ8tzmOaEgAd’}

Danh sách các khoản đầu tư ban đầu

funds = []

def main(): while True: try: #Làm API yêu cầu tài trợ response = requests.get(api_url, headers=headers).json() usdt_balance = float(next(item for item in response[‘balances’] if item[‘asset’] == ‘USDT’)[‘free’])

Ghi lại số tiền và thời gian

funds.append(usdt_balance) #Vẽ đường cong tài chính plt.plot(funds) plt.xlabel(‘Time’) plt.ylabel(‘Funds’) plt.title(‘USDT Funds’) plt.grid(True) plt.savefig(‘funds_plot.png’) plt.close()

Ngủ 15 phút

time.sleep(900) except Exception as e:

Ghi sai thông tin

Log(“Error:”, str(e)) time.sleep(5)