import requests
import uuid
symbol = "AAPL"
url = "https://public-api.etoro.com/api/v1/market-data/search"
# Use internalSymbolFull to filter specifically for the symbol
params = {
"internalSymbolFull": symbol
}
headers = {
"x-api-key": "<YOUR_PUBLIC_KEY>",
"x-user-key": "<YOUR_USER_KEY>",
"x-request-id": str(uuid.uuid4())
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
# Find the exact match in the returned items list
instrument = next((item for item in data['items'] if item['internalSymbolFull'] == symbol), None)
if instrument:
print(f"Instrument ID: {instrument['instrumentId']}")
else:
print("Instrument not found")
else:
print(f"Error: {response.status_code}")