Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python3 List in requests
#1
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)
Reply
#2
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.
ogautier likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 requests.models.Response ogautier 4 5,222 Feb-17-2022, 04:46 PM
Last Post: ogautier
  python3: iterating through list not working wardancer84 3 2,303 Jul-08-2020, 04:30 PM
Last Post: DPaul
  How to make each thread send multiple requests in python3? Contra_Boy 0 1,757 Apr-29-2020, 02:42 PM
Last Post: Contra_Boy
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,823 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  python3 List to array or string to extract data batchenr 4 3,190 May-28-2019, 01:44 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020