Hello,
I am having trouble formulating a list of dictionaries which incorporate information from an API call which will set the KEY:VALUE pairs.
I am trying to get this result:
Kind Regards,
Andrew
I am having trouble formulating a list of dictionaries which incorporate information from an API call which will set the KEY:VALUE pairs.
I am trying to get this result:
Output:MainList[
{'Asset_ID': 012334, 'AAPL': 238.75},
{'Asset_ID': 567890, 'FB': 28.50},
{'Asset_ID': 123345, 'BT': 203.55},
{'Asset_ID': 678901, 'C': 38.25}
etc.............]and this is my current code:import requests
import json
BASE_URL = 'https://paper-api.alpaca.markets'
HEADERS = {'APCA-API-KEY-ID': "", 'APCA-API-SECRET-KEY': ""}
ACCOUNT_URL = '{}/v2/account'.format(BASE_URL)
ASSETS_URL = '{}/v2/assets'.format(BASE_URL)
POSITIONS_URL = '{}/v2/positions'.format(BASE_URL)
#asset API provides the stock symbol(AAPL,FB etc.)& the associated asset ID's.
assets_r = requests.get(ASSETS_URL, headers=HEADERS)
get_assets = json.loads(assets_r.content)
#positions API provides the Current_value
positions_r = requests.get(POSITIONS_URL, headers=HEADERS)
get_position = json.loads(positions_r.content)
dictionary = dict
Symbol_items = dictionary(get_assets)['symbol', range(1)]
Asset_ID_items = dictionary(get_assets)['id', range(1)]
price_items = dictionary(get_position)['current_price', range(1)]
dictionary = {'Asset_ID' : Asset_ID_items, Symbol_items: price_items}
print(dictionary)--- when it runs I get this message,Error:Traceback (most recent call last):
File "C:/Users/engli/PycharmProjects/tester01/rambo/first_Test.py", line 24, in <module>
Symbol_items = dictionary(get_assets)['symbol', range(1)]
ValueError: dictionary update sequence element #0 has length 10; 2 is requiredAny help will be greatly appreciated! Kind Regards,
Andrew
