Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hmac
- import hashlib
- import time
- import requests
- import json
- def save_response_to_file(response_text, file_name="mexc_wallets.json"):
- with open(file_name, 'w', encoding='utf-8') as file:
- file.write(response_text)
- def make_api_request(api_key, secret_key):
- # Generate timestamp
- timestamp = int(time.time() * 1000)
- # Set a larger recvWindow if necessary (up to 60000)
- recvWindow = 59998
- # Prepare the query string including the recvWindow
- total_params = f'timestamp={timestamp}&recvWindow={recvWindow}'
- # Generate the signature
- signature = hmac.new(bytes(secret_key, 'utf-8'), msg=bytes(total_params, 'utf-8'), digestmod=hashlib.sha256).hexdigest()
- # Make the request
- url = 'https://api.mexc.com/api/v3/capital/config/getall'
- headers = {
- "X-MEXC-APIKEY": api_key,
- "Content-Type": "application/json"
- }
- params = {
- "timestamp": timestamp,
- "recvWindow": recvWindow,
- "signature": signature
- }
- response = requests.get(url, headers=headers, params=params)
- # Save the response to a file (default: mexc_wallets.json)
- save_response_to_file(response.text)
- # Replace 'your_api_key_here' and 'your_secret_key_here' with your actual MEXC API key and secret key
- api_key = 'your_api_key_here'
- secret_key = 'your_secret_key_here'
- # Call the function to make the request and save the response
- make_api_request(api_key, secret_key)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement