import time
import json
import requests
from nacl.bindings import crypto_sign
PUBLIC_KEY = ""
SECRET_KEY = ""
ROOT_API_URL = "https://api.dmarket.com"
def sign_request(method, path, body=""):
nonce = str(int(time.time()))
string_to_sign = method + path + body + nonce
signature = crypto_sign(string_to_sign.encode(),
bytes.fromhex(SECRET_KEY))[:64].hex()
headers = {
"X-Api-Key": PUBLIC_KEY,
"X-Request-Sign": f"dmar ed25519 {signature}",
"X-Sign-Date": nonce,
"Content-Type": "application/json"
}
return headers
def get_user_orders():
path = "/marketplace-api/v1/user-orders"
headers = sign_request("GET", path)
response = requests.get(ROOT_API_URL + path, headers=headers)
if response.status_code == 200:
return response.json().get("orders", [])
else:
print(
f"[!] Error receiving orders: {response.status_code}, {response.text}")
return []
def delete_order(order_id):
path = f"/marketplace-api/v1/orders/{order_id}"
headers = sign_request("DELETE", path)
response = requests.delete(ROOT_API_URL + path, headers=headers)
if response.status_code == 200:
print(f"[-ORDER] Deleted order: {order_id}")
else:
print(
f"[!] Error deleting orders {order_id}: {response.status_code}, {response.text}")
def main():
print("\n
orders = get_user_orders()
if not orders:
print("No active orders.")
return
for order in orders:
order_id = order.get("orderId")
if order_id:
delete_order(order_id)
if __name__ == "__main__":
main()
Подробнее здесь: https://stackoverflow.com/questions/797 ... enot-found