from datetime import datetime
import requests


def get_historical_spreads(instrument: str, since: datetime):
    """
    Get a list of historical spreads for a given forex pair

    Args:
        instrument (str): The instrument to filter the requested orders by
            see InstrumentName in oanda_guide.txt
        since (datetime): A datetime object to retrieve all spread data after
    """
    time_diff = str(int(datetime.now().timestamp() - since.timestamp()))
    headers = {"Content-Type": "application/json"}
    r = requests.get(
        f"https://www.oanda.com/labsds/calendar_and_spreads?period={time_diff}&instrument={instrument}",
        headers=headers,
    )
    return r.json()["spreads"]["avg"]