[Python] Coinbase Advance Trading API returns "Error: account not available" when placing...

Discussão em 'Python' iniciado por Stack, Abril 27, 2025.

  1. Stack

    Stack Membro Participativo

    For the past while I have been trying to get this crypto trading bot to work. The problem is that while I can get/list accounts when I place an order I get a 400 error.

    The code:

    def place_order(symbol, side, amount, price=None):
    url = 'https://api.coinbase.com/api/v3/brokerage/orders'
    headers = {
    'Authorization': 'Bearer '+encryption_build.build_jwt(
    'POST api.coinbase.com/api/v3/brokerage/orders',
    api_key,
    api_secret),
    'Content-Type': 'application/json'
    }
    client_order_id = uuid.uuid4()
    try:
    # Order details
    order_data = {
    "client_order_id": str(client_order_id),
    "product_id": symbol,
    "side": side,
    "order_configuration": {
    "market_market_ioc": {
    "base_size": str(amount)
    }
    },
    "retail_portfolio_id": "41864a16-1fd4-50bb-a633-278d9c39f846"
    }
    res = requests.post(url=url, headers=headers, data=json.dumps(order_data))
    except Exception as e:
    print(f"An error occurred: {e}")

    place_order('BTC-USD', 'SELL', amount=0.01)


    The response:

    {
    "error":"INVALID_ARGUMENT",
    "error_details":"account is not available",
    "message":"account is not available"
    }


    The API key has view/trade permissions. The List Accounts endpoint returns my accounts on Coinbase. A BTC and fiat account in CAD are present. Both are active. Specifying the retail portfolio, or using other libraries to do this didn't make a difference.

    I expect a 200 status code with the order pending or filled on Coinbase's end.

    EDIT: Running it through Postman produced the same error.

    POST https://api.coinbase.com/api/v3/brokerage/orders
    400
    111 ms
    POST /api/v3/brokerage/orders HTTP/1.1
    Content-Type: application/json
    Authorization: Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6Im9yZ2FuaXphdGlvbnMvNjUwYjZhYjEtMTk2My00ZTQ1LThhYWMtNmUyYTdkNGU0MmQxL2FwaUtleXMvOTg0ZTE4ZjMtZDEzZi00NjllLTk3ZDItNTNkZDEzYzM1NDJhIiwibm9uY2UiOiJlODE3MmZmZDZjMzQ3ZDdhNzRjZDk3YWFlNmJkZTEzZTYyZWY5ZTk3ZjEyZTBlOTU4NTgwNzMyMzUwZTBlMmFiIiwidHlwIjoiSldUIn0.eyJzdWIiOiJvcmdhbml6YXRpb25zLzY1MGI2YWIxLTE5NjMtNGU0NS04YWFjLTZlMmE3ZDRlNDJkMS9hcGlLZXlzLzk4NGUxOGYzLWQxM2YtNDY5ZS05N2QyLTUzZGQxM2MzNTQyYSIsImlzcyI6ImNkcCIsIm5iZiI6MTcyMDU2MTE2MSwiZXhwIjoxNzIwNTYxMjgxLCJ1cmkiOiJQT1NUIGFwaS5jb2luYmFzZS5jb20vYXBpL3YzL2Jyb2tlcmFnZS9vcmRlcnMifQ.0ECu5nM8XTTLv7caGPxSBmoVUDoqW-z07z4Jz8wDljjIf2rreGjZ-L-ZAzMcDMU8FafSEQeo81FExUkUe2TVww
    User-Agent: PostmanRuntime/7.39.0
    Accept: */*
    Postman-Token: 9506a059-e326-402b-8a4f-7aefcba39eaf
    Host: api.coinbase.com
    Accept-Encoding: gzip, deflate, br
    Connection: keep-alive
    Content-Length: 231
    Cookie: __cf_bm=wG1twa3RotRq8PB5plk5UPsC8Luskeyddh9famNqHE4-1720561189-1.0.1.1-lWThs07H99ZxAB78K2ZUdY.4aDP0LEg49rLxEqPyrbL2ivpjLLQFKbsSMcieMCZ.eVdyusgBCyVspRfrdP.5LQ; cb_dm=16c8bf71-6e14-4c79-8c05-83251661ce3b

    {"client_order_id": "b372a61a-7585-4dd1-bb6c-f5990967412b", "product_id": "BTC-USD", "side": "BUY", "order_configuration": {"market_market_ioc": {"base_size": "0.01"}}, "retail_portfolio_id": "d641518f-dd81-49fc-96d1-ce1e782f697f"}

    HTTP/1.1 400 Bad Request
    Date: Tue, 09 Jul 2024 21:40:17 GMT
    Content-Type: application/json; charset=utf-8
    Content-Length: 108
    Connection: keep-alive
    access-control-allow-headers: Content-Type, Accept, Second-Factor-Proof-Token, Client-Id, Access-Token, X-Cb-Project-Name, X-Cb-Is-Logged-In, X-Cb-Platform, X-Cb-Session-Uuid, X-Cb-Pagekey, X-Cb-Ujs, Fingerprint-Tokens, X-Cb-Device-Id, X-Cb-Version-Name
    access-control-allow-methods: GET,POST,DELETE,PUT
    access-control-allow-private-network: true
    access-control-expose-headers:
    access-control-max-age: 7200
    Cache-Control: no-store
    strict-transport-security: max-age=31536000; includeSubDomains; preload
    trace-id: 7311873497407553797
    trace-id: 7311873497407553797
    vary: Origin
    x-content-type-options: nosniff
    x-dns-prefetch-control: off
    x-download-options: noopen
    x-frame-options: SAMEORIGIN
    x-xss-protection: 1; mode=block
    x-envoy-upstream-service-time: 51
    CF-Cache-Status: DYNAMIC
    Server: cloudflare
    CF-RAY: 8a0b78b7bf7caca0-YYZ

    {"error":"INVALID_ARGUMENT","error_details":"account is not available","message":"account is not available"}


    There is very little on this on the internet. Any help would be appreciated. Thank you.

    Continue reading...

Compartilhe esta Página