Created
July 25, 2023 15:44
-
-
Save IperGiove/4add3ce30622cdb1ce21d1766c695f87 to your computer and use it in GitHub Desktop.
Test the rate limit of MEXC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hmac | |
import hashlib | |
import time | |
import httpx | |
import pprint | |
import datetime | |
pp = pprint.PrettyPrinter(indent=4) | |
def create_message() -> str: | |
symbol = "WBTCUSDT" | |
side = "BUY" | |
order_type = "FILL_OR_KILL" | |
quantity = "1" | |
price = "11" | |
recv_window = "10000" | |
timestamp = int(time.time() * 1000) | |
message = f"symbol={symbol}&side={side}&type={order_type}&quantity={quantity}&price={price}&recvWindow={recv_window}×tamp={timestamp}" | |
return message | |
def sign_message(message: str, secret_key: str) -> str: | |
signature = hmac.new(secret_key.encode(), message.encode(), hashlib.sha256).hexdigest() | |
return signature | |
def add_signature_to_message(message: str, signature: str) -> str: | |
message += f"&signature={signature}" | |
return message | |
def main(): | |
api_key = "api_key" | |
secret_key = "secret_key" | |
for i in range(2): | |
message = create_message() | |
signature = sign_message(message, secret_key) | |
signed_message = add_signature_to_message(message, signature) | |
url = f'https://api.mexc.com/api/v3/order?{signed_message}' | |
headers = {"X-MEXC-APIKEY": api_key} | |
pp.pprint(f"Sending request N.{i} at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')}") | |
response = httpx.post(url, headers=headers) | |
pp.pprint(f"Receiving request N.{i} at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')}") | |
pp.pprint("Response") | |
pp.pprint(response.json()) | |
print("\n") | |
time.sleep(10) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment