Binance API Keys

前端 未结 6 1542
名媛妹妹
名媛妹妹 2021-02-16 00:20

I have set up a read-only API key on Binance to access account information like currency balances but I can\'t see the JSON data. The string query I put into the URL returns th

6条回答
  •  你的背包
    2021-02-16 00:40

    Binance's websocket API kinda tricky to use. Also there is no way to use a secret key.

    Common usage

    1. Send HTTP POST request with your secret API key as a X-MBX-APIKEY header to https://api.binance.com/api/v1/userDataStream
    2. You will get listen key which should be used for websocket connection. It will be available 1 hour.

      {"listenKey": "your listen key here"}

    3. Use it when connecting to Binance's websocket

    wss://stream.binance.com:9443/ws/{your listen key here}

    Python example

    import ssl
    from websocket import create_connection
    
    import requests
    
    KEY = 'your-secret-key'
    url = 'https://api.binance.com/api/v1/userDataStream'
    listen_key = requests.post(url, headers={'X-MBX-APIKEY': KEY})['listenKey']
    connection = create_connection('wss://stream.binance.com:9443/ws/{}'.format(KEY), 
                                   sslopt={'cert_reqs': ssl.CERT_NONE})
    

提交回复
热议问题