dukascript 0.0.3__py3-none-any.whl → 0.0.5__py3-none-any.whl

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.
dukascript/__init__.py CHANGED
@@ -31,19 +31,19 @@ INTERVAL_SEC_1 = f"1{TIME_UNIT_SEC}"
31
31
  INTERVAL_TICK = TIME_UNIT_TICK
32
32
 
33
33
  _interval_units = {
34
- INTERVAL_MONTH_1:TIME_UNIT_MONTH,
35
- INTERVAL_WEEK_1:TIME_UNIT_WEEK,
36
- INTERVAL_DAY_1:TIME_UNIT_DAY,
37
- INTERVAL_HOUR_4:TIME_UNIT_HOUR,
38
- INTERVAL_HOUR_1:TIME_UNIT_HOUR,
39
- INTERVAL_MIN_30:TIME_UNIT_MIN,
40
- INTERVAL_MIN_15:TIME_UNIT_MIN,
41
- INTERVAL_MIN_10:TIME_UNIT_MIN,
42
- INTERVAL_MIN_5:TIME_UNIT_MIN,
43
- INTERVAL_MIN_1:TIME_UNIT_MIN,
44
- INTERVAL_SEC_30:TIME_UNIT_SEC,
45
- INTERVAL_SEC_10:TIME_UNIT_SEC,
46
- INTERVAL_SEC_1:TIME_UNIT_SEC,
34
+ INTERVAL_MONTH_1: TIME_UNIT_MONTH,
35
+ INTERVAL_WEEK_1: TIME_UNIT_WEEK,
36
+ INTERVAL_DAY_1: TIME_UNIT_DAY,
37
+ INTERVAL_HOUR_4: TIME_UNIT_HOUR,
38
+ INTERVAL_HOUR_1: TIME_UNIT_HOUR,
39
+ INTERVAL_MIN_30: TIME_UNIT_MIN,
40
+ INTERVAL_MIN_15: TIME_UNIT_MIN,
41
+ INTERVAL_MIN_10: TIME_UNIT_MIN,
42
+ INTERVAL_MIN_5: TIME_UNIT_MIN,
43
+ INTERVAL_MIN_1: TIME_UNIT_MIN,
44
+ INTERVAL_SEC_30: TIME_UNIT_SEC,
45
+ INTERVAL_SEC_10: TIME_UNIT_SEC,
46
+ INTERVAL_SEC_1: TIME_UNIT_SEC,
47
47
  }
48
48
 
49
49
  OFFER_SIDE_BID = "B"
@@ -258,7 +258,7 @@ def fetch(
258
258
  debug=False,
259
259
  ):
260
260
  logger = _get_custom_logger(debug)
261
- time_unit=_interval_units[interval]
261
+ time_unit = _interval_units[interval]
262
262
  columns = _get_dataframe_columns_for_timeunit(time_unit)
263
263
 
264
264
  data = []
@@ -299,6 +299,7 @@ def live_fetch(
299
299
  debug=False,
300
300
  ):
301
301
  logger = _get_custom_logger(debug)
302
+ assert interval_value > 0
302
303
 
303
304
  # validate time unit
304
305
  _resample_to_nearest(
@@ -343,7 +344,9 @@ def live_fetch(
343
344
 
344
345
  yield df
345
346
 
346
- for row in datafeed:
347
+ last_tick_count = 0
348
+
349
+ for tick_count, row in enumerate(datafeed, 0):
347
350
 
348
351
  timestamp = _resample_to_nearest(
349
352
  pd.to_datetime(
@@ -355,19 +358,24 @@ def live_fetch(
355
358
  interval_value,
356
359
  )
357
360
 
358
- if time_unit == TIME_UNIT_TICK:
361
+ if last_timestamp == None:
362
+ last_timestamp = timestamp.timestamp()
363
+
364
+ if time_unit == TIME_UNIT_TICK and interval_value == 1:
359
365
  df.loc[timestamp] = [
360
366
  *row[1:],
361
367
  ]
362
368
  yield df
363
369
  continue
364
370
 
365
- if last_timestamp == None:
366
- last_timestamp = timestamp.timestamp()
371
+ new_tick_count = tick_count // interval_value
367
372
 
368
- if timestamp.timestamp() != last_timestamp:
373
+ if (
374
+ time_unit != TIME_UNIT_TICK
375
+ and timestamp.timestamp() != last_timestamp.timestamp()
376
+ ) or (time_unit == TIME_UNIT_TICK and last_tick_count != new_tick_count):
369
377
  if open is not None:
370
- df.loc[timestamp] = [
378
+ df.loc[last_timestamp] = [
371
379
  open,
372
380
  high,
373
381
  low,
@@ -376,7 +384,8 @@ def live_fetch(
376
384
  ]
377
385
 
378
386
  yield df
379
- last_timestamp = timestamp.timestamp()
387
+ last_timestamp = timestamp
388
+ last_tick_count = new_tick_count
380
389
  open = None
381
390
 
382
391
  if open is None:
@@ -398,4 +407,5 @@ def live_fetch(
398
407
  close,
399
408
  volume,
400
409
  ]
410
+
401
411
  yield df
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: dukascript
3
+ Version: 0.0.5
4
+ Summary: Download tick data from Dukascopy Bank SA to local cache, and simulate time-ordered price streams
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/dukascript
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: pandas
36
+ Requires-Dist: requests
37
+ Provides-Extra: dev
38
+ Requires-Dist: build; extra == "dev"
39
+ Requires-Dist: twine; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ # 🏦 dukascript
43
+
44
+ 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.
45
+
46
+ ---
47
+
48
+ ## 📦 Installation
49
+
50
+ ```bash
51
+ pip install dukascript
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 🛠️ Usage
57
+
58
+ ### Importing
59
+
60
+ ```python
61
+ from datetime import datetime, timedelta
62
+ import dukascript
63
+ from dukascript.instruments import INSTRUMENT_FX_MAJORS_GBP_USD
64
+ ```
65
+
66
+ ---
67
+
68
+ ## 🧠 Key Concepts
69
+
70
+ Both `fetch` and `live_fetch` share similar parameters:
71
+
72
+ | Parameter | Description |
73
+ |----------------|-----------------------------------------------------------------------------|
74
+ | `start` | `datetime`, required. The start time of the data. |
75
+ | `end` | `datetime`, optional. If `None`, fetches data up to "now". |
76
+ | `instrument` | e.g., `INSTRUMENT_FX_MAJORS_GBP_USD`. |
77
+ | `offer_side` | `OFFER_SIDE_BID` or `OFFER_SIDE_ASK`. |
78
+ | `max_retries` | Optional. If `None`, keeps retrying on failure. |
79
+ | `debug` | Optional. If `True`, prints debug logs. |
80
+
81
+ ### 🧊 `fetch()` only:
82
+
83
+ | Parameter | Description |
84
+ |--------------|------------------------------|
85
+ | `interval` | e.g., `INTERVAL_HOUR_1` |
86
+
87
+ ### 🔥 `live_fetch()` only:
88
+
89
+ | Parameter | Description |
90
+ |-------------------|---------------------------------------------|
91
+ | `interval_value` | e.g., `1` |
92
+ | `time_unit` | e.g., `dukascript.TIME_UNIT_HOUR` |
93
+
94
+ ---
95
+
96
+ ## 📝 Notes
97
+
98
+ - **fetch**: Fetches static historical data. Returns **one** `DataFrame`.
99
+ - **live_fetch**: Continuously fetches live updates. Returns a **generator** that yields the **same `DataFrame`** with updated data.
100
+
101
+ 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`.
102
+
103
+ ---
104
+
105
+ ## 📊 DataFrame Columns
106
+
107
+ ### When interval/time_unit is based on tick:
108
+ ie:
109
+
110
+ `interval = INTERVAL_TICK`
111
+
112
+ or
113
+
114
+ `interval_value = 1`
115
+ `time_units = TIME_UNIT_TICK`
116
+
117
+ | Column | Description |
118
+ |-------------|------------------------|
119
+ | `timestamp` | UTC datetime, Dataframe Index |
120
+ | `bidPrice` | Bid price |
121
+ | `askPrice` | Ask price |
122
+ | `bidVolume` | Bid volume |
123
+ | `askVolume` | Ask volume |
124
+
125
+ ### When interval/time_unit is NOT based on tick
126
+ eg: 5 minutes OHLC candle data
127
+
128
+ `interval_value = 5`
129
+ `time_units = TIME_UNIT_MIN`
130
+
131
+ | Column | Description |
132
+ |-------------|------------------------|
133
+ | `timestamp` | UTC datetime, Dataframe Index |
134
+ | `open` | Opening price |
135
+ | `high` | Highest price |
136
+ | `low` | Lowest price |
137
+ | `close` | Closing price |
138
+ | `volume` | Volume (in units) |
139
+
140
+ ---
141
+
142
+ ## 💾 Saving Results
143
+
144
+ Use built-in `pandas` methods to export:
145
+
146
+ ```python
147
+ df.to_csv("data.csv")
148
+ df.to_excel("data.xlsx")
149
+ df.to_json("data.json")
150
+ ```
151
+
152
+ ---
153
+
154
+ ## 🚀 Examples
155
+
156
+ ### Example 1: Fetch Historical Data
157
+
158
+ ```python
159
+ start = datetime(2025, 1, 1)
160
+ end = datetime(2025, 2, 1)
161
+ instrument = INSTRUMENT_FX_MAJORS_GBP_USD
162
+ interval = dukascript.INTERVAL_HOUR_1
163
+ offer_side = dukascript.OFFER_SIDE_BID
164
+
165
+ df = dukascript.fetch(
166
+ instrument,
167
+ interval,
168
+ offer_side,
169
+ start,
170
+ end,
171
+ )
172
+
173
+ df.to_json("output.json")
174
+ ```
175
+
176
+ ---
177
+
178
+ ### Example 2: Live Fetch with End Time
179
+
180
+ ```python
181
+ now = datetime.now()
182
+ start = datetime(now.year, now.month, now.day)
183
+ end = start + timedelta(hours=24)
184
+
185
+ iterator = dukascript.live_fetch(
186
+ instrument,
187
+ 1,
188
+ dukascript.TIME_UNIT_HOUR,
189
+ offer_side,
190
+ start,
191
+ end,
192
+ )
193
+
194
+ for df in iterator:
195
+ pass
196
+
197
+ df.to_csv("output.csv")
198
+ ```
199
+
200
+ ---
201
+
202
+ ### Example 3: Live Fetch Indefinitely (End = None)
203
+
204
+ ```python
205
+ now = datetime.now()
206
+ start = datetime(now.year, now.month, now.day)
207
+ end = None
208
+
209
+ df_iterator = dukascript.live_fetch(
210
+ instrument,
211
+ 1,
212
+ dukascript.TIME_UNIT_HOUR,
213
+ offer_side,
214
+ start,
215
+ end,
216
+ )
217
+
218
+ for df in df_iterator:
219
+ # Do something with latest data
220
+ pass
221
+ ```
222
+
223
+ ---
224
+
225
+ ## 📄 License
226
+
227
+ MIT
228
+
229
+ ---
230
+
231
+ ## 👋 Contributing
232
+
233
+ Pull requests and suggestions are highly welcome!
234
+
@@ -0,0 +1,8 @@
1
+ dukascript/__init__.py,sha256=nxyrT1UGi2gBpRGsUMnZA2koMMnTwq7EZdoY_vq5J6E,11785
2
+ dukascript/_instrument_generator.py,sha256=WDTNS1bLa-J2uI3TmoBTg-WCHdAtkX6d6tq0xhqL4GI,24848
3
+ dukascript/instruments.py,sha256=OxKTWR8zx2sjaHtGtd81FsQwTdAMItjgUSojzuJ1waI,59069
4
+ dukascript-0.0.5.dist-info/licenses/LICENSE,sha256=SA8D35cWkNTiEI71ATLBPTzWgFwjPNZLeloeBJrAJr4,1061
5
+ dukascript-0.0.5.dist-info/METADATA,sha256=5h8k2mjIMRIZ2ARrs3bTod5VDXjT9Qh2DSwZadU8WQM,6484
6
+ dukascript-0.0.5.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
7
+ dukascript-0.0.5.dist-info/top_level.txt,sha256=h7GgEQykn3TuhHU4jJxZQ7oNjP_naNvjUwZAw6KU3VE,11
8
+ dukascript-0.0.5.dist-info/RECORD,,
@@ -1,44 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: dukascript
3
- Version: 0.0.3
4
- Summary: Download tick data from Dukascopy Bank SA to local cache, and simulate time-ordered price streams
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/dukascript
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: pandas
36
- Requires-Dist: requests
37
- Provides-Extra: dev
38
- Requires-Dist: build; extra == "dev"
39
- Requires-Dist: twine; extra == "dev"
40
- Dynamic: license-file
41
-
42
- # dukascript
43
-
44
- Download and stream historical data from Dukascopy Bank SA.
@@ -1,8 +0,0 @@
1
- dukascript/__init__.py,sha256=bPsw_EhL1g35ulDZLWuIZO3ueHncS-7dQ5AFvyT84nw,11412
2
- dukascript/_instrument_generator.py,sha256=WDTNS1bLa-J2uI3TmoBTg-WCHdAtkX6d6tq0xhqL4GI,24848
3
- dukascript/instruments.py,sha256=OxKTWR8zx2sjaHtGtd81FsQwTdAMItjgUSojzuJ1waI,59069
4
- dukascript-0.0.3.dist-info/licenses/LICENSE,sha256=SA8D35cWkNTiEI71ATLBPTzWgFwjPNZLeloeBJrAJr4,1061
5
- dukascript-0.0.3.dist-info/METADATA,sha256=uXCFZcjUOto7W_cJ1hTi28Y81S-jXxcCk5ks9pOfkPY,2040
6
- dukascript-0.0.3.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
7
- dukascript-0.0.3.dist-info/top_level.txt,sha256=h7GgEQykn3TuhHU4jJxZQ7oNjP_naNvjUwZAw6KU3VE,11
8
- dukascript-0.0.3.dist-info/RECORD,,