Python Forum

Full Version: Python3 List in requests
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Quote:Hello, Id like to know if is possible to pass a list of parameters to the following url: https://api.kraken.com/public/Ticker?pair='ADAUSD'
to replace pair='ADAUSD' to payload

Regards!

import requests

payload = ['ADAUSD','DOGEUSD','LTCUSD']
req = ('https://api.kraken.com/public/Ticker/',
params=payload)
https://docs.kraken.com/rest/#operation/...nformation
It must be a POST Request and the data must be sent as url-form encoded and the use of the param-Keyword does the proper thing. You must concatenate the Symbols with commas. The str.join method does this. The response is json. The response object has the method json to get the answer back as a python dict.


import requests


api_version = 0
method = "Ticker"
url = f"https://api.kraken.com/{api_version}/public/{method}"
symbols = ",".join(["ADAUSD", "DOGEUSD", "LTCUSD"])
response = requests.post(url, params={"pair": symbols})
result = response.json().get("result", {})

for symbol, payload in result.items():
    print(symbol, payload.get("o", "MISSING"))
I've no clue what the data means. You've to look in the docs to understand the different keys from the payload.
Each symbol has different keys where each key has a list of values. One value of them is not a list.
You can investigate the data, which is saved in result.