Create order advanced trade api, Error 502 bad gateway

I changed my code to this:

import requests
import sys
import platform
import time
import base64
import hashlib
import hmac
import json
import time
import urllib.request as urllib2
import os
import urllib.parse
import jwt
import uuid
from urllib.parse import urlencode, unquote, urljoin
import http.client

conn = http.client.HTTPSConnection("api.coinbase.com")
    payload = "{\"side\":\"BUY\",\"client_order_id\": \"default\",\"product_id\":\"BTC-USD\",\"order_configuration\": {\"market_market_ioc\": {\"quote_size\": \"1000\"}}}"
    timestamp = str(int(time.time())) 
    secretKey = "mysecret"
    message = timestamp + "POST" + "/api/v3/brokerage/orders" + payload
    signature = hmac.new(secretKey.encode('utf-8'), message.encode('utf-8'), digestmod=hashlib.sha256).digest()
    headers = {
        'accept': 'application/json',
        'CB-ACCESS-KEY': 'mykey',
        'CB-ACCESS-SIGN': signature.hex(),
        'CB-ACCESS-TIMESTAMP': timestamp,
        "content-type": "application/json"
    }
    conn.request("POST", "/api/v3/brokerage/orders", payload, headers)
    res = conn.getresponse()
    data = res.read()
    print(data.decode("utf-8"))

EDIT:

Added the side but now i get the same error:

<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>  
</body>
</html>
2 Likes