Advertisement
Guest User

Untitled

a guest
Mar 6th, 2024
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import hmac
  2. import hashlib
  3. import time
  4. import requests
  5. import json
  6.  
  7. def save_response_to_file(response_text, file_name="mexc_wallets.json"):
  8. with open(file_name, 'w', encoding='utf-8') as file:
  9. file.write(response_text)
  10.  
  11. def make_api_request(api_key, secret_key):
  12. # Generate timestamp
  13. timestamp = int(time.time() * 1000)
  14.  
  15. # Set a larger recvWindow if necessary (up to 60000)
  16. recvWindow = 59998
  17.  
  18. # Prepare the query string including the recvWindow
  19. total_params = f'timestamp={timestamp}&recvWindow={recvWindow}'
  20.  
  21. # Generate the signature
  22. signature = hmac.new(bytes(secret_key, 'utf-8'), msg=bytes(total_params, 'utf-8'), digestmod=hashlib.sha256).hexdigest()
  23.  
  24. # Make the request
  25. url = 'https://api.mexc.com/api/v3/capital/config/getall'
  26. headers = {
  27. "X-MEXC-APIKEY": api_key,
  28. "Content-Type": "application/json"
  29. }
  30. params = {
  31. "timestamp": timestamp,
  32. "recvWindow": recvWindow,
  33. "signature": signature
  34. }
  35.  
  36. response = requests.get(url, headers=headers, params=params)
  37.  
  38. # Save the response to a file (default: mexc_wallets.json)
  39. save_response_to_file(response.text)
  40. # Replace 'your_api_key_here' and 'your_secret_key_here' with your actual MEXC API key and secret key
  41. api_key = 'your_api_key_here'
  42. secret_key = 'your_secret_key_here'
  43.  
  44. # Call the function to make the request and save the response
  45. make_api_request(api_key, secret_key)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement