dukascopy-python 4.0.1__tar.gz → 5.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dukascopy_python-5.0.0/PKG-INFO +301 -0
- dukascopy_python-5.0.0/README.md +261 -0
- dukascopy_python-5.0.0/dukascopy_python/__init__.py +182 -0
- {dukascopy_python-4.0.1/dukascopy_python → dukascopy_python-5.0.0/dukascopy_python/compat}/__init__.py +17 -1
- {dukascopy_python-4.0.1/dukascopy_python → dukascopy_python-5.0.0/dukascopy_python/compat}/instruments.py +1510 -0
- dukascopy_python-5.0.0/dukascopy_python/core/__init__.py +22 -0
- dukascopy_python-5.0.0/dukascopy_python/core/http.py +34 -0
- dukascopy_python-5.0.0/dukascopy_python/core/interfaces.py +72 -0
- dukascopy_python-5.0.0/dukascopy_python/core/logger.py +54 -0
- dukascopy_python-5.0.0/dukascopy_python/core/utils.py +175 -0
- dukascopy_python-5.0.0/dukascopy_python/impl/v1/__init__.py +332 -0
- dukascopy_python-5.0.0/dukascopy_python/impl/v2/__init__.py +545 -0
- dukascopy_python-5.0.0/dukascopy_python/instruments/__init__.py +6 -0
- dukascopy_python-5.0.0/dukascopy_python/instruments/generator.py +98 -0
- dukascopy_python-5.0.0/dukascopy_python/instruments/instruments.py +21074 -0
- dukascopy_python-5.0.0/dukascopy_python.egg-info/PKG-INFO +301 -0
- dukascopy_python-5.0.0/dukascopy_python.egg-info/SOURCES.txt +21 -0
- {dukascopy_python-4.0.1 → dukascopy_python-5.0.0}/dukascopy_python.egg-info/requires.txt +0 -1
- {dukascopy_python-4.0.1 → dukascopy_python-5.0.0}/pyproject.toml +1 -2
- dukascopy_python-4.0.1/PKG-INFO +0 -238
- dukascopy_python-4.0.1/README.md +0 -197
- dukascopy_python-4.0.1/dukascopy_python.egg-info/PKG-INFO +0 -238
- dukascopy_python-4.0.1/dukascopy_python.egg-info/SOURCES.txt +0 -10
- {dukascopy_python-4.0.1 → dukascopy_python-5.0.0}/LICENSE +0 -0
- {dukascopy_python-4.0.1 → dukascopy_python-5.0.0}/dukascopy_python.egg-info/dependency_links.txt +0 -0
- {dukascopy_python-4.0.1 → dukascopy_python-5.0.0}/dukascopy_python.egg-info/top_level.txt +0 -0
- {dukascopy_python-4.0.1 → dukascopy_python-5.0.0}/setup.cfg +0 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dukascopy-python
|
|
3
|
+
Version: 5.0.0
|
|
4
|
+
Summary: Download and stream historical price data for variety of financial instruments (Forex, Commodities and Indices) from Dukascopy Bank SA.
|
|
5
|
+
Author-email: Eghosa Osayande <osayandeeghosam@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 drui9
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Project-URL: Homepage, https://github.com/Eghosa-Osayande/dukascopy
|
|
28
|
+
Keywords: tick-data,forex-data,tick-api,ticks,dukascopy
|
|
29
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
30
|
+
Classifier: Programming Language :: Python
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Requires-Python: >=3.10
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: requests
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Requires-Dist: build; extra == "dev"
|
|
38
|
+
Requires-Dist: twine; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# dukascopy-python
|
|
42
|
+
|
|
43
|
+
Download historical financial market data from [Dukascopy Bank SA](https://www.dukascopy.com), including tick-level prices and OHLCV candles for Forex, commodities, indices, and other financial instruments.
|
|
44
|
+
|
|
45
|
+
Supports multiple data feed versions, configurable HTTP sessions, optional logging, and Pandas integration.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install dukascopy-python
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Backward Compatibility
|
|
54
|
+
|
|
55
|
+
The previous API remains available through `dukascopy_python.compat`, which uses data feed version 1 internally.
|
|
56
|
+
|
|
57
|
+
Existing applications can continue using `fetch()`, `live_fetch()`, and legacy constants by updating their imports.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from datetime import datetime, timezone
|
|
61
|
+
|
|
62
|
+
import dukascopy_python.compat as duka
|
|
63
|
+
from dukascopy_python.compat.instruments import (
|
|
64
|
+
INSTRUMENT_FX_MAJORS_EUR_USD,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
df = duka.fetch(
|
|
68
|
+
INSTRUMENT_FX_MAJORS_EUR_USD,
|
|
69
|
+
duka.INTERVAL_MIN_1,
|
|
70
|
+
duka.OFFER_SIDE_BID,
|
|
71
|
+
datetime(2025, 1, 1, tzinfo=timezone.utc),
|
|
72
|
+
datetime(2025, 1, 2, tzinfo=timezone.utc),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
df.to_csv("output.csv")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## New API
|
|
79
|
+
|
|
80
|
+
The new API provides two functions:
|
|
81
|
+
|
|
82
|
+
- `fetch_candles()` — Retrieve historical OHLCV candles.
|
|
83
|
+
- `fetch_ticks()` — Retrieve historical bid/ask tick data.
|
|
84
|
+
|
|
85
|
+
### Fetch Candles
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from datetime import datetime, timezone
|
|
89
|
+
|
|
90
|
+
import dukascopy_python as duka
|
|
91
|
+
from dukascopy_python.instruments import I_EUR_USD
|
|
92
|
+
|
|
93
|
+
candles = duka.fetch_candles(
|
|
94
|
+
instrument=I_EUR_USD,
|
|
95
|
+
interval=1,
|
|
96
|
+
time_unit=duka.TimeUnit.HOUR,
|
|
97
|
+
offer_side=duka.OfferSide.BID,
|
|
98
|
+
start=datetime(2025, 1, 1, tzinfo=timezone.utc),
|
|
99
|
+
end=datetime(2025, 2, 1, tzinfo=timezone.utc),
|
|
100
|
+
version=2,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
for candle in candles:
|
|
104
|
+
print(candle)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Fetch Ticks
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
ticks = duka.fetch_ticks(
|
|
111
|
+
instrument=I_EUR_USD,
|
|
112
|
+
start=datetime(2025, 1, 1, tzinfo=timezone.utc),
|
|
113
|
+
end=datetime(2025, 1, 2, tzinfo=timezone.utc),
|
|
114
|
+
version=2,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
for tick in ticks:
|
|
118
|
+
print(tick)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Both functions return iterable model objects.
|
|
122
|
+
|
|
123
|
+
### Parameters
|
|
124
|
+
|
|
125
|
+
| Parameter | Description |
|
|
126
|
+
|---|---|
|
|
127
|
+
| `instrument` | Instrument code, e.g. `I_EUR_USD` |
|
|
128
|
+
| `start` | Start datetime (inclusive range boundary, subject to feed behaviour) |
|
|
129
|
+
| `end` | End datetime; must be later than `start` |
|
|
130
|
+
| `version` | `1` or `2`; defaults to the globally configured version |
|
|
131
|
+
| `validate_instrument_name` | Validate and convert the instrument identifier; default `True` |
|
|
132
|
+
| `create_session` | Optional callable returning an HTTP session |
|
|
133
|
+
| `logger` | Optional `logging.Logger` instance |
|
|
134
|
+
|
|
135
|
+
Additional parameters for `fetch_candles()`:
|
|
136
|
+
|
|
137
|
+
| Parameter | Description |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `interval` | Positive integer specifying the candle interval |
|
|
140
|
+
| `time_unit` | `TimeUnit` enum, e.g. `TimeUnit.MINUTE` |
|
|
141
|
+
| `offer_side` | `OfferSide.BID` or `OfferSide.ASK` |
|
|
142
|
+
|
|
143
|
+
`start` and `end` must both be timezone-aware or both timezone-naive. UTC-aware datetimes are recommended.
|
|
144
|
+
|
|
145
|
+
## Data Feed Versions
|
|
146
|
+
|
|
147
|
+
Two data feed implementations are available.
|
|
148
|
+
|
|
149
|
+
| Version | Implementation |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `1` | `DataFeedV1` (default) |
|
|
152
|
+
| `2` | `DataFeedV2` |
|
|
153
|
+
|
|
154
|
+
### Set the Default Version
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
duka.set_default_version(2)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
All subsequent fetch operations use version 2 unless explicitly overridden.
|
|
161
|
+
|
|
162
|
+
### Override Version Per Request
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
candles = duka.fetch_candles(
|
|
166
|
+
instrument=I_EUR_USD,
|
|
167
|
+
interval=5,
|
|
168
|
+
time_unit=duka.TimeUnit.MINUTE,
|
|
169
|
+
offer_side=duka.OfferSide.BID,
|
|
170
|
+
start=start,
|
|
171
|
+
end=end,
|
|
172
|
+
version=1,
|
|
173
|
+
)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The `version` argument overrides the default for that request without changing the global setting.
|
|
177
|
+
|
|
178
|
+
## Data Models
|
|
179
|
+
|
|
180
|
+
### Candle
|
|
181
|
+
|
|
182
|
+
| Field | Description |
|
|
183
|
+
|---|---|
|
|
184
|
+
| `timestamp` | Candle timestamp |
|
|
185
|
+
| `open`, `high`, `low`, `close` | OHLC prices |
|
|
186
|
+
| `volume` | Trading volume |
|
|
187
|
+
| `time_unit` | Candle time unit |
|
|
188
|
+
| `interval` | Candle interval |
|
|
189
|
+
|
|
190
|
+
### Tick
|
|
191
|
+
|
|
192
|
+
| Field | Description |
|
|
193
|
+
|---|---|
|
|
194
|
+
| `timestamp` | Tick timestamp |
|
|
195
|
+
| `bid`, `ask` | Bid and ask prices |
|
|
196
|
+
| `bid_volume`, `ask_volume` | Bid and ask volumes |
|
|
197
|
+
| `volume` | Tick volume |
|
|
198
|
+
|
|
199
|
+
## Pandas Integration
|
|
200
|
+
|
|
201
|
+
Convert retrieved candles or ticks into a Pandas DataFrame.
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
candles = list(duka.fetch_candles(
|
|
205
|
+
instrument=I_EUR_USD,
|
|
206
|
+
interval=1,
|
|
207
|
+
time_unit=duka.TimeUnit.HOUR,
|
|
208
|
+
offer_side=duka.OfferSide.BID,
|
|
209
|
+
start=start,
|
|
210
|
+
end=end,
|
|
211
|
+
))
|
|
212
|
+
|
|
213
|
+
df = duka.to_dataframe(candles)
|
|
214
|
+
|
|
215
|
+
df.to_csv("candles.csv")
|
|
216
|
+
df.to_json("candles.json")
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Pandas is an optional dependency. Install it with:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
pip install pandas
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Advanced Configuration
|
|
226
|
+
|
|
227
|
+
### Custom HTTP Session
|
|
228
|
+
|
|
229
|
+
Use the `create_session` argument to provide a session factory.
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
candles = duka.fetch_candles(
|
|
233
|
+
instrument=I_EUR_USD,
|
|
234
|
+
interval=1,
|
|
235
|
+
time_unit=duka.TimeUnit.HOUR,
|
|
236
|
+
offer_side=duka.OfferSide.BID,
|
|
237
|
+
start=start,
|
|
238
|
+
end=end,
|
|
239
|
+
create_session=lambda: duka.create_session(retries=7),
|
|
240
|
+
)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The library manages the returned session using a context manager.
|
|
244
|
+
|
|
245
|
+
### Custom Logging
|
|
246
|
+
|
|
247
|
+
Provide a configured Python logger:
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
import logging
|
|
251
|
+
|
|
252
|
+
logger = duka.create_logger(
|
|
253
|
+
name="dukascopy",
|
|
254
|
+
level=logging.DEBUG,
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
ticks = duka.fetch_ticks(
|
|
258
|
+
instrument=I_EUR_USD,
|
|
259
|
+
start=start,
|
|
260
|
+
end=end,
|
|
261
|
+
logger=logger,
|
|
262
|
+
)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Instrument Validation
|
|
266
|
+
|
|
267
|
+
Instrument validation and identifier conversion are enabled by default.
|
|
268
|
+
|
|
269
|
+
To bypass them:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
ticks = duka.fetch_ticks(
|
|
273
|
+
instrument="EUR/USD",
|
|
274
|
+
start=start,
|
|
275
|
+
end=end,
|
|
276
|
+
version=2,
|
|
277
|
+
validate_instrument_name=False,
|
|
278
|
+
)
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
When validation is disabled, the instrument identifier is passed directly to the selected data feed.
|
|
282
|
+
|
|
283
|
+
## Migration Reference
|
|
284
|
+
|
|
285
|
+
| Previous API | New API |
|
|
286
|
+
|---|---|
|
|
287
|
+
| `dukascopy_python.compat` | `dukascopy_python` |
|
|
288
|
+
| `fetch()` | `fetch_candles()` / `fetch_ticks()` |
|
|
289
|
+
| `live_fetch()` | Available through `compat` |
|
|
290
|
+
| `INTERVAL_MIN_1` | `interval=1, time_unit=TimeUnit.MINUTE` |
|
|
291
|
+
| `OFFER_SIDE_BID` | `OfferSide.BID` |
|
|
292
|
+
| `INSTRUMENT_FX_MAJORS_EUR_USD` | `I_EUR_USD` |
|
|
293
|
+
| Pandas DataFrame | Iterable `Candle` / `Tick` objects |
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
MIT
|
|
298
|
+
|
|
299
|
+
## Contributing
|
|
300
|
+
|
|
301
|
+
Contributions, bug reports, and pull requests are welcome.
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# dukascopy-python
|
|
2
|
+
|
|
3
|
+
Download historical financial market data from [Dukascopy Bank SA](https://www.dukascopy.com), including tick-level prices and OHLCV candles for Forex, commodities, indices, and other financial instruments.
|
|
4
|
+
|
|
5
|
+
Supports multiple data feed versions, configurable HTTP sessions, optional logging, and Pandas integration.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install dukascopy-python
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Backward Compatibility
|
|
14
|
+
|
|
15
|
+
The previous API remains available through `dukascopy_python.compat`, which uses data feed version 1 internally.
|
|
16
|
+
|
|
17
|
+
Existing applications can continue using `fetch()`, `live_fetch()`, and legacy constants by updating their imports.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from datetime import datetime, timezone
|
|
21
|
+
|
|
22
|
+
import dukascopy_python.compat as duka
|
|
23
|
+
from dukascopy_python.compat.instruments import (
|
|
24
|
+
INSTRUMENT_FX_MAJORS_EUR_USD,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
df = duka.fetch(
|
|
28
|
+
INSTRUMENT_FX_MAJORS_EUR_USD,
|
|
29
|
+
duka.INTERVAL_MIN_1,
|
|
30
|
+
duka.OFFER_SIDE_BID,
|
|
31
|
+
datetime(2025, 1, 1, tzinfo=timezone.utc),
|
|
32
|
+
datetime(2025, 1, 2, tzinfo=timezone.utc),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
df.to_csv("output.csv")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## New API
|
|
39
|
+
|
|
40
|
+
The new API provides two functions:
|
|
41
|
+
|
|
42
|
+
- `fetch_candles()` — Retrieve historical OHLCV candles.
|
|
43
|
+
- `fetch_ticks()` — Retrieve historical bid/ask tick data.
|
|
44
|
+
|
|
45
|
+
### Fetch Candles
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from datetime import datetime, timezone
|
|
49
|
+
|
|
50
|
+
import dukascopy_python as duka
|
|
51
|
+
from dukascopy_python.instruments import I_EUR_USD
|
|
52
|
+
|
|
53
|
+
candles = duka.fetch_candles(
|
|
54
|
+
instrument=I_EUR_USD,
|
|
55
|
+
interval=1,
|
|
56
|
+
time_unit=duka.TimeUnit.HOUR,
|
|
57
|
+
offer_side=duka.OfferSide.BID,
|
|
58
|
+
start=datetime(2025, 1, 1, tzinfo=timezone.utc),
|
|
59
|
+
end=datetime(2025, 2, 1, tzinfo=timezone.utc),
|
|
60
|
+
version=2,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
for candle in candles:
|
|
64
|
+
print(candle)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Fetch Ticks
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
ticks = duka.fetch_ticks(
|
|
71
|
+
instrument=I_EUR_USD,
|
|
72
|
+
start=datetime(2025, 1, 1, tzinfo=timezone.utc),
|
|
73
|
+
end=datetime(2025, 1, 2, tzinfo=timezone.utc),
|
|
74
|
+
version=2,
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
for tick in ticks:
|
|
78
|
+
print(tick)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Both functions return iterable model objects.
|
|
82
|
+
|
|
83
|
+
### Parameters
|
|
84
|
+
|
|
85
|
+
| Parameter | Description |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `instrument` | Instrument code, e.g. `I_EUR_USD` |
|
|
88
|
+
| `start` | Start datetime (inclusive range boundary, subject to feed behaviour) |
|
|
89
|
+
| `end` | End datetime; must be later than `start` |
|
|
90
|
+
| `version` | `1` or `2`; defaults to the globally configured version |
|
|
91
|
+
| `validate_instrument_name` | Validate and convert the instrument identifier; default `True` |
|
|
92
|
+
| `create_session` | Optional callable returning an HTTP session |
|
|
93
|
+
| `logger` | Optional `logging.Logger` instance |
|
|
94
|
+
|
|
95
|
+
Additional parameters for `fetch_candles()`:
|
|
96
|
+
|
|
97
|
+
| Parameter | Description |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `interval` | Positive integer specifying the candle interval |
|
|
100
|
+
| `time_unit` | `TimeUnit` enum, e.g. `TimeUnit.MINUTE` |
|
|
101
|
+
| `offer_side` | `OfferSide.BID` or `OfferSide.ASK` |
|
|
102
|
+
|
|
103
|
+
`start` and `end` must both be timezone-aware or both timezone-naive. UTC-aware datetimes are recommended.
|
|
104
|
+
|
|
105
|
+
## Data Feed Versions
|
|
106
|
+
|
|
107
|
+
Two data feed implementations are available.
|
|
108
|
+
|
|
109
|
+
| Version | Implementation |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `1` | `DataFeedV1` (default) |
|
|
112
|
+
| `2` | `DataFeedV2` |
|
|
113
|
+
|
|
114
|
+
### Set the Default Version
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
duka.set_default_version(2)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
All subsequent fetch operations use version 2 unless explicitly overridden.
|
|
121
|
+
|
|
122
|
+
### Override Version Per Request
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
candles = duka.fetch_candles(
|
|
126
|
+
instrument=I_EUR_USD,
|
|
127
|
+
interval=5,
|
|
128
|
+
time_unit=duka.TimeUnit.MINUTE,
|
|
129
|
+
offer_side=duka.OfferSide.BID,
|
|
130
|
+
start=start,
|
|
131
|
+
end=end,
|
|
132
|
+
version=1,
|
|
133
|
+
)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The `version` argument overrides the default for that request without changing the global setting.
|
|
137
|
+
|
|
138
|
+
## Data Models
|
|
139
|
+
|
|
140
|
+
### Candle
|
|
141
|
+
|
|
142
|
+
| Field | Description |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `timestamp` | Candle timestamp |
|
|
145
|
+
| `open`, `high`, `low`, `close` | OHLC prices |
|
|
146
|
+
| `volume` | Trading volume |
|
|
147
|
+
| `time_unit` | Candle time unit |
|
|
148
|
+
| `interval` | Candle interval |
|
|
149
|
+
|
|
150
|
+
### Tick
|
|
151
|
+
|
|
152
|
+
| Field | Description |
|
|
153
|
+
|---|---|
|
|
154
|
+
| `timestamp` | Tick timestamp |
|
|
155
|
+
| `bid`, `ask` | Bid and ask prices |
|
|
156
|
+
| `bid_volume`, `ask_volume` | Bid and ask volumes |
|
|
157
|
+
| `volume` | Tick volume |
|
|
158
|
+
|
|
159
|
+
## Pandas Integration
|
|
160
|
+
|
|
161
|
+
Convert retrieved candles or ticks into a Pandas DataFrame.
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
candles = list(duka.fetch_candles(
|
|
165
|
+
instrument=I_EUR_USD,
|
|
166
|
+
interval=1,
|
|
167
|
+
time_unit=duka.TimeUnit.HOUR,
|
|
168
|
+
offer_side=duka.OfferSide.BID,
|
|
169
|
+
start=start,
|
|
170
|
+
end=end,
|
|
171
|
+
))
|
|
172
|
+
|
|
173
|
+
df = duka.to_dataframe(candles)
|
|
174
|
+
|
|
175
|
+
df.to_csv("candles.csv")
|
|
176
|
+
df.to_json("candles.json")
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Pandas is an optional dependency. Install it with:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
pip install pandas
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Advanced Configuration
|
|
186
|
+
|
|
187
|
+
### Custom HTTP Session
|
|
188
|
+
|
|
189
|
+
Use the `create_session` argument to provide a session factory.
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
candles = duka.fetch_candles(
|
|
193
|
+
instrument=I_EUR_USD,
|
|
194
|
+
interval=1,
|
|
195
|
+
time_unit=duka.TimeUnit.HOUR,
|
|
196
|
+
offer_side=duka.OfferSide.BID,
|
|
197
|
+
start=start,
|
|
198
|
+
end=end,
|
|
199
|
+
create_session=lambda: duka.create_session(retries=7),
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
The library manages the returned session using a context manager.
|
|
204
|
+
|
|
205
|
+
### Custom Logging
|
|
206
|
+
|
|
207
|
+
Provide a configured Python logger:
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
import logging
|
|
211
|
+
|
|
212
|
+
logger = duka.create_logger(
|
|
213
|
+
name="dukascopy",
|
|
214
|
+
level=logging.DEBUG,
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
ticks = duka.fetch_ticks(
|
|
218
|
+
instrument=I_EUR_USD,
|
|
219
|
+
start=start,
|
|
220
|
+
end=end,
|
|
221
|
+
logger=logger,
|
|
222
|
+
)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Instrument Validation
|
|
226
|
+
|
|
227
|
+
Instrument validation and identifier conversion are enabled by default.
|
|
228
|
+
|
|
229
|
+
To bypass them:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
ticks = duka.fetch_ticks(
|
|
233
|
+
instrument="EUR/USD",
|
|
234
|
+
start=start,
|
|
235
|
+
end=end,
|
|
236
|
+
version=2,
|
|
237
|
+
validate_instrument_name=False,
|
|
238
|
+
)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
When validation is disabled, the instrument identifier is passed directly to the selected data feed.
|
|
242
|
+
|
|
243
|
+
## Migration Reference
|
|
244
|
+
|
|
245
|
+
| Previous API | New API |
|
|
246
|
+
|---|---|
|
|
247
|
+
| `dukascopy_python.compat` | `dukascopy_python` |
|
|
248
|
+
| `fetch()` | `fetch_candles()` / `fetch_ticks()` |
|
|
249
|
+
| `live_fetch()` | Available through `compat` |
|
|
250
|
+
| `INTERVAL_MIN_1` | `interval=1, time_unit=TimeUnit.MINUTE` |
|
|
251
|
+
| `OFFER_SIDE_BID` | `OfferSide.BID` |
|
|
252
|
+
| `INSTRUMENT_FX_MAJORS_EUR_USD` | `I_EUR_USD` |
|
|
253
|
+
| Pandas DataFrame | Iterable `Candle` / `Tick` objects |
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT
|
|
258
|
+
|
|
259
|
+
## Contributing
|
|
260
|
+
|
|
261
|
+
Contributions, bug reports, and pull requests are welcome.
|