Skip to main content

Download and stream historical price data for variety of financial instruments (Forex, Commodities and Indices) from Dukascopy Bank SA.

Project description

🏦 dukascopy-python

Download and stream historical price data for variety of financial instruments (e.g. Forex, Commodities and Indices) from Dukascopy Bank SA. , including support for tick-level and aggregated intervals.


📦 Installation

pip install dukascopy-python

🛠️ Usage

Importing

from datetime import datetime, timedelta
import dukascopy_python
from dukascopy_python.instruments import INSTRUMENT_FX_MAJORS_GBP_USD

🧠 Key Concepts

Both fetch and live_fetch share similar parameters:

Parameter Description
start datetime, required. The start time of the data.
end datetime, optional. If None, fetches data up to "now".
instrument e.g., INSTRUMENT_FX_MAJORS_GBP_USD.
offer_side OFFER_SIDE_BID or OFFER_SIDE_ASK.
max_retries Optional. If None, keeps retrying on failure.
debug Optional. If True, prints debug logs.

🧊 fetch() only:

Parameter Description
interval e.g., INTERVAL_HOUR_1

🔥 live_fetch() only:

Parameter Description
interval_value e.g., 1
time_unit e.g., dukascopy_python.TIME_UNIT_HOUR

📝 Notes

  • fetch: Fetches static historical data. Returns one DataFrame.
  • live_fetch: Continuously fetches live updates. Returns a generator that yields the same DataFrame with updated data.

When using intervals not based on ticks eg: 1HOUR, fetch() will return delayed data. For up-to-date values, use live_fetch() which fetches tick data under the hood and reshapes it based on the interval_value and time_unit.


📊 DataFrame Columns

When interval/time_unit is based on tick:

ie:

interval = INTERVAL_TICK

or

interval_value = 1 time_units = TIME_UNIT_TICK

Column Description
timestamp UTC datetime, Dataframe Index
bidPrice Bid price
askPrice Ask price
bidVolume Bid volume
askVolume Ask volume

When interval/time_unit is NOT based on tick

eg: 5 minutes OHLC candle data

interval_value = 5 time_units = TIME_UNIT_MIN

Column Description
timestamp UTC datetime, Dataframe Index
open Opening price
high Highest price
low Lowest price
close Closing price
volume Volume (in units)

💾 Saving Results

Use built-in pandas methods to export:

df.to_csv("data.csv")
df.to_excel("data.xlsx")
df.to_json("data.json")

🚀 Examples

Example 1: Fetch Historical Data

start = datetime(2025, 1, 1)
end = datetime(2025, 2, 1)
instrument = INSTRUMENT_FX_MAJORS_GBP_USD
interval = dukascopy_python.INTERVAL_HOUR_1
offer_side = dukascopy_python.OFFER_SIDE_BID

df = dukascopy_python.fetch(
    instrument,
    interval,
    offer_side,
    start,
    end,
)

df.to_json("output.json")

Example 2: Live Fetch with End Time

now = datetime.now()
start = datetime(now.year, now.month, now.day)
end = start + timedelta(hours=24)
instrument = INSTRUMENT_FX_MAJORS_GBP_USD
offer_side = dukascopy_python.OFFER_SIDE_BID

iterator = dukascopy_python.live_fetch(
    instrument,
    1,
    dukascopy_python.TIME_UNIT_HOUR,
    offer_side,
    start,
    end,
)

for df in iterator:
    pass

df.to_csv("output.csv")

Example 3: Live Fetch Indefinitely (End = None)

now = datetime.now()
start = datetime(now.year, now.month, now.day)
end = None
instrument = INSTRUMENT_FX_MAJORS_GBP_USD
offer_side = dukascopy_python.OFFER_SIDE_BID

df_iterator = dukascopy_python.live_fetch(
    instrument,
    1,
    dukascopy_python.TIME_UNIT_HOUR,
    offer_side,
    start,
    end,
)

for df in df_iterator:
    # Do something with latest data
    pass

📄 License

MIT


👋 Contributing

Pull requests and suggestions are highly welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dukascopy_python-4.0.1.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dukascopy_python-4.0.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file dukascopy_python-4.0.1.tar.gz.

File metadata

  • Download URL: dukascopy_python-4.0.1.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for dukascopy_python-4.0.1.tar.gz
Algorithm Hash digest
SHA256 5bdcf2c8a72d69ec035a56e59b5534a96ccbbbecdbe4f22d74608d88eaf39b64
MD5 01e91a05666df73560e9277dfed1b4b8
BLAKE2b-256 347fc054097e4020696ac3c4a9e85ab9a75342e01e593dbe60adc14148924ea1

See more details on using hashes here.

File details

Details for the file dukascopy_python-4.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dukascopy_python-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb7ccb9b38e43276f08256c41f66ca38fd972d0d5db0081660ee652d14ddf431
MD5 19955377cc575890bc7d43b45e363359
BLAKE2b-256 e40cbddb653f83f7e721044910e329f4e2b87569e676b58520e91296dc7f7237

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page