Skip to main content

🏦 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!

Metadata

Release files for dukascopy-python 4.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dukascopy-python 4.0.1
File Size Uploaded
dukascopy_python-4.0.1.tar.gz 19.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dukascopy-python 4.0.1
File Interpreter ABI Platform
dukascopy_python-4.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 36.3 kB

Release files / dukascopy_python-4.0.1.tar.gz

Download URL dukascopy_python-4.0.1.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5bdcf2c8a72d69ec035a56e59b5534a96ccbbbecdbe4f22d74608d88eaf39b64
BLAKE2b-256 checksum
How to use checksums
347fc054097e4020696ac3c4a9e85ab9a75342e01e593dbe60adc14148924ea1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release files / dukascopy_python-4.0.1-py3-none-any.whl

Download URL dukascopy_python-4.0.1-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb7ccb9b38e43276f08256c41f66ca38fd972d0d5db0081660ee652d14ddf431
BLAKE2b-256 checksum
How to use checksums
e40cbddb653f83f7e721044910e329f4e2b87569e676b58520e91296dc7f7237
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release history Release notifications | RSS feed

This release

4.0.1 This release

2 release files

4.0.0

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page