0% found this document useful (0 votes)
49 views

Eodhd Api

This document provides an overview of the EODHD Python API for accessing end of day and real-time financial market data. It covers installing the API client library, configuring API keys, retrieving exchange and symbol listings, downloading end of day price data and converting it to a Pandas DataFrame, connecting to real-time market data via WebSocket, and accessing options data including implied volatility.

Uploaded by

nicolas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Eodhd Api

This document provides an overview of the EODHD Python API for accessing end of day and real-time financial market data. It covers installing the API client library, configuring API keys, retrieving exchange and symbol listings, downloading end of day price data and converting it to a Pandas DataFrame, connecting to real-time market data via WebSocket, and accessing options data including implied volatility.

Uploaded by

nicolas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EODHD API

March 30, 2024

1 EHODHD Python API


1.0.1 1/ Installation des packages Python

[ ]: pip install eod websocket-client -U

1.0.2 2/ Configuration de l’API

[1]: from eod import EodHistoricalData


import numpy as np
import pandas as pd
import requests
import datetime
import calendar
import scipy.stats as stats
import matplotlib.pyplot as plt

# clé API
api_key = '6607d38ae1ab29.46698939'
# création de l'instance client
client = EodHistoricalData(api_key)

1.0.3 3/ Aperçu des Exchange et Symbols

[ ]: # chargement de la liste des exchange


resp = client.get_exchanges()
df = pd.DataFrame(resp)
pd.set_option('display.max_rows', len(df))
print(df)
pd.reset_option('display.max_rows')

# pour trouver la liste des symbols - Exemple : Bombay Exchange symbols


resp = client.get_exchange_symbols(exchange='FOREX')
df = pd.DataFrame(resp)
pd.set_option('display.max_rows', len(df))
print(df)
pd.reset_option('display.max_rows')

1
1.0.4 4/ Données End Of Day

[15]: # récupération des prix eur/usd à la fin de journée


eurusd = 'EURUSD.FOREX'
eurusd_prices = client.get_prices_eod(eurusd, period='d', order='a')

# conversion en dataframe pandas


eurusd_prices = pd.DataFrame(eurusd_prices)
eurusd_prices.set_index('date', inplace=True)

# création d'un graphique


eurusd_prices.close.plot(figsize=(10,5))
plt.title('EURUSD')
plt.ylabel('EURUSD')
plt.show()

1.0.5 5/ Temps Réel avec Websocket

[ ]: import websocket
import threading
import time
import json

stop_event = threading.Event()

def collect_data():

2
uri = "wss://ws.eodhistoricaldata.com/ws/crypto?api_token=6607d38ae1ab29.
↪46698939"

ws = websocket.create_connection(uri)

payload = {
"action": "subscribe",
"symbols": "BTC-USD",
}
ws.send(json.dumps(payload))

while not stop_event.is_set():


message = ws.recv()
print(message)
time.sleep(0.25)

ws.close()

t = threading.Thread(target=collect_data)
t.start()

# délai avant fermeture des connexions


time.sleep(15)

stop_event.set()
t.join()

1.0.6 6/ Données Options

[7]: resp = client.get_stock_options('AAPL.US')

iv = {}

for i in resp['data']:
iv[i['expirationDate']] = {}
iv[i['expirationDate']]['x'] = [name['strike'] for name in␣
↪i['options']['CALL']]

iv[i['expirationDate']]['y'] = [name['impliedVolatility'] for name in␣


↪i['options']['CALL']]

#print("Expiration Date: ", i['expirationDate'])


#print("IV vs Strikes: ", [name['impliedVolatility'] for name in␣
↪i['options']['CALL']])

plt.scatter(iv['2024-04-05']['x'],iv['2024-04-05']['y'])

3
plt.title('AAPL Implied Volatility of Contracts with 2024-04-05 Expiry')
plt.ylabel('Implied Volatility (%)')
plt.xlabel('Strike ($)')
plt.show()

[ ]:

You might also like