Environment
Python
Alpaca SDK Version
V2
Problem
Not able to add ticker symbol to Watchlist.
I invoke funttion - add_ticker_symbol_to_my_watchlist, and that fails, and i get response as “request format is invalid”, don’t know where is the problem,
Paper or Live Tradng?
Paper
Example Code
APCA_API_BASE_URL = “https://paper-api.alpaca.markets”;
WATCHLIST_URL = “{}/v2/watchlists”.format(APCA_API_BASE_URL);
def get_specific_watchlist(watchlist_name):
r =requests.get(WATCHLIST_URL, headers=HEADERS);
data = json.loads(r.content);
for obj in data:
if obj[“name”] == watchlist_name:
return obj
return null;
def add_ticker_symbol_to_my_watchlist(watchlist_name, ticket_symbol):
watch_list_2 = get_specific_watchlist(watchlist_name);
wl_id = watch_list_2[“id”];
data = {
“symbol”:ticket_symbol
};
print(WATCHLIST_URL);
wl_url = WATCHLIST_URL + "/" +wl_id + "";
#wl_url = WATCHLIST_URL + "/{" +wl_id + "}";
r =requests.post(wl_url , data, headers = HEADERS);
json_data = json.loads(r.content);
print(json_data);
return json_data ;
OUTPUT:
https://paper-api.alpaca.markets/v2/watchlists
{‘code’: 40010000, ‘message’: ‘request body format is invalid’}