fyers-apiv3 3.0.2__tar.gz → 3.0.3__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.
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/PKG-INFO +1 -1
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3/FyersWebsocket/data_ws.py +62 -21
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3/FyersWebsocket/map.json +1 -1
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3/FyersWebsocket/order_ws.py +3 -3
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3.egg-info/PKG-INFO +1 -1
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/setup.py +2 -2
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/LICENSE.txt +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/README.md +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3/FyersWebsocket/__init__.py +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3/FyersWebsocket/defines.py +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3/__init__.py +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3/fyersModel.py +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3/fyers_logger.py +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3.egg-info/SOURCES.txt +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3.egg-info/dependency_links.txt +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3.egg-info/requires.txt +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/fyers_apiv3.egg-info/top_level.txt +0 -0
- {fyers_apiv3-3.0.2 → fyers_apiv3-3.0.3}/setup.cfg +0 -0
|
@@ -87,6 +87,8 @@ class SymbolConversion:
|
|
|
87
87
|
values["fyToken"] = data["v"]["fyToken"]
|
|
88
88
|
values["symbol"] = data["v"]["symbol"]
|
|
89
89
|
key = values["fyToken"][:4]
|
|
90
|
+
if key not in exch_seg_dict:
|
|
91
|
+
continue
|
|
90
92
|
values["segment"] = exch_seg_dict[key]
|
|
91
93
|
data = values["symbol"].split("-")
|
|
92
94
|
update_dict = True
|
|
@@ -120,7 +122,8 @@ class SymbolConversion:
|
|
|
120
122
|
elif data["s"] == "error":
|
|
121
123
|
wrong_symbol.append(data["n"])
|
|
122
124
|
return (datadict, wrong_symbol, dp_index_flag)
|
|
123
|
-
|
|
125
|
+
|
|
126
|
+
return ({}, [],dp_index_flag)
|
|
124
127
|
except Exception as e:
|
|
125
128
|
self.data_logger.exception(e)
|
|
126
129
|
|
|
@@ -196,6 +199,8 @@ class FyersDataSocket:
|
|
|
196
199
|
self.scrips_per_channel = {}
|
|
197
200
|
self.restart_flag = reconnect
|
|
198
201
|
self.websocket_lock = threading.Lock()
|
|
202
|
+
self.message_lock = threading.Lock()
|
|
203
|
+
self.message_condition = threading.Condition(lock=self.message_lock)
|
|
199
204
|
self.unsub_symbol = []
|
|
200
205
|
for i in range(1, 31):
|
|
201
206
|
self.scrips_per_channel[i] = []
|
|
@@ -251,8 +256,9 @@ class FyersDataSocket:
|
|
|
251
256
|
bool: True if the token is valid and not expired, False otherwise.
|
|
252
257
|
"""
|
|
253
258
|
try:
|
|
254
|
-
|
|
259
|
+
header_token , payload_b64, _ = self.__access_token.split(".")
|
|
255
260
|
# Decode the base64 encoded payload
|
|
261
|
+
decoded_header = base64.urlsafe_b64decode(header_token + "===")
|
|
256
262
|
decoded_payload = base64.urlsafe_b64decode(payload_b64 + "===")
|
|
257
263
|
# Convert the decoded payload to a string (assuming it's in JSON format)
|
|
258
264
|
decode_token = json.loads(decoded_payload.decode())
|
|
@@ -271,7 +277,7 @@ class FyersDataSocket:
|
|
|
271
277
|
self.__hsm_token = decode_token["hsm_key"]
|
|
272
278
|
return True
|
|
273
279
|
|
|
274
|
-
except
|
|
280
|
+
except:
|
|
275
281
|
self.On_error(
|
|
276
282
|
{ "type": defines.AUTH_TYPE,
|
|
277
283
|
"code": defines.INVALID_CODE,
|
|
@@ -279,7 +285,7 @@ class FyersDataSocket:
|
|
|
279
285
|
"s": defines.ERROR,
|
|
280
286
|
}
|
|
281
287
|
)
|
|
282
|
-
self.data_logger.error(e)
|
|
288
|
+
# self.data_logger.error(e)
|
|
283
289
|
return False
|
|
284
290
|
|
|
285
291
|
|
|
@@ -308,10 +314,10 @@ class FyersDataSocket:
|
|
|
308
314
|
|
|
309
315
|
# Field-1: AuthToken
|
|
310
316
|
field1_id = 1
|
|
311
|
-
field1_size = len(self.
|
|
317
|
+
field1_size = len(self.__hsm_token)
|
|
312
318
|
byte_buffer.extend(bytes([field1_id]))
|
|
313
319
|
byte_buffer.extend(struct.pack("!H", field1_size))
|
|
314
|
-
byte_buffer.extend(self.
|
|
320
|
+
byte_buffer.extend(self.__hsm_token.encode())
|
|
315
321
|
|
|
316
322
|
# Field-2
|
|
317
323
|
field2_id = 2
|
|
@@ -995,7 +1001,10 @@ class FyersDataSocket:
|
|
|
995
1001
|
message_num = struct.unpack(">I", data[3:7])[0]
|
|
996
1002
|
if self.update_count == self.ack_count:
|
|
997
1003
|
self.ack_msg = self.__ackowledgement_msg(message_num)
|
|
998
|
-
self.message.append(self.ack_msg)
|
|
1004
|
+
# self.message.append(self.ack_msg)
|
|
1005
|
+
self.add_message(self.ack_msg)
|
|
1006
|
+
|
|
1007
|
+
|
|
999
1008
|
self.update_count = 0
|
|
1000
1009
|
scrip_count = struct.unpack("!H", data[7:9])[0]
|
|
1001
1010
|
offset = 9
|
|
@@ -1368,11 +1377,15 @@ class FyersDataSocket:
|
|
|
1368
1377
|
and self.active_channel != self.channel_num
|
|
1369
1378
|
):
|
|
1370
1379
|
message = self.__channel_pause_msg(self.active_channel)
|
|
1371
|
-
self.message.append(message)
|
|
1380
|
+
# self.message.append(message)
|
|
1381
|
+
self.add_message(message)
|
|
1382
|
+
|
|
1372
1383
|
|
|
1373
1384
|
if self.channel_num in self.running_channels:
|
|
1374
1385
|
message = self.__channel_resume_msg(self.channel_num)
|
|
1375
|
-
self.message.append(message)
|
|
1386
|
+
# self.message.append(message)
|
|
1387
|
+
self.add_message(message)
|
|
1388
|
+
|
|
1376
1389
|
self.running_channels.add(self.channel_num)
|
|
1377
1390
|
self.active_channel = self.channel_num
|
|
1378
1391
|
|
|
@@ -1421,18 +1434,35 @@ class FyersDataSocket:
|
|
|
1421
1434
|
|
|
1422
1435
|
self.__ws_object.send(message, opcode=websocket.ABNF.OPCODE_BINARY)
|
|
1423
1436
|
|
|
1437
|
+
|
|
1438
|
+
def add_message(self, message):
|
|
1439
|
+
"""
|
|
1440
|
+
Add a message to the list of messages and notify waiting threads.
|
|
1441
|
+
|
|
1442
|
+
Args:
|
|
1443
|
+
message (str): The message to add to the list.
|
|
1444
|
+
"""
|
|
1445
|
+
with self.message_lock:
|
|
1446
|
+
self.message.append(message)
|
|
1447
|
+
self.message_condition.notify()
|
|
1448
|
+
|
|
1449
|
+
|
|
1424
1450
|
def __process_message_queue(self) -> None:
|
|
1425
1451
|
"""
|
|
1426
1452
|
Processes the message queue by sending messages sequentially.
|
|
1427
1453
|
"""
|
|
1428
1454
|
|
|
1429
1455
|
while not self.message_thread_stop_event.is_set():
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1456
|
+
with self.message_lock:
|
|
1457
|
+
while not self.message: # Use a loop to handle spurious wake-ups
|
|
1458
|
+
self.message_condition.wait()
|
|
1459
|
+
|
|
1460
|
+
# Once a message is available, pop it from the queue
|
|
1461
|
+
message = self.message.pop(0)
|
|
1462
|
+
|
|
1463
|
+
# Send the message outside the lock to avoid blocking other threads
|
|
1464
|
+
self.__send_message(message)
|
|
1465
|
+
|
|
1436
1466
|
|
|
1437
1467
|
def On_error(self, message: dict) -> None:
|
|
1438
1468
|
"""
|
|
@@ -1501,13 +1531,17 @@ class FyersDataSocket:
|
|
|
1501
1531
|
self.message_thread.start()
|
|
1502
1532
|
self.ping_thread.start()
|
|
1503
1533
|
message = self.__access_token_msg()
|
|
1504
|
-
self.message.append(message)
|
|
1534
|
+
# self.message.append(message)
|
|
1535
|
+
self.add_message(message)
|
|
1505
1536
|
if self.lite:
|
|
1506
1537
|
message = self.__lite_mode_msg()
|
|
1507
|
-
self.message.append(message)
|
|
1538
|
+
# self.message.append(message)
|
|
1539
|
+
self.add_message(message)
|
|
1508
1540
|
else:
|
|
1509
1541
|
message = self.__full_mode_msg()
|
|
1510
|
-
self.message.append(message)
|
|
1542
|
+
# self.message.append(message)
|
|
1543
|
+
self.add_message(message)
|
|
1544
|
+
|
|
1511
1545
|
|
|
1512
1546
|
def __on_close(self, ws, close_code, close_reason):
|
|
1513
1547
|
"""
|
|
@@ -1536,6 +1570,8 @@ class FyersDataSocket:
|
|
|
1536
1570
|
|
|
1537
1571
|
time.sleep(self.reconnect_delay)
|
|
1538
1572
|
self.__ws_object = None
|
|
1573
|
+
self.scrips_per_channel[self.channel_num] = []
|
|
1574
|
+
|
|
1539
1575
|
self.connect()
|
|
1540
1576
|
else:
|
|
1541
1577
|
if self.write_to_file:
|
|
@@ -1607,6 +1643,7 @@ class FyersDataSocket:
|
|
|
1607
1643
|
self.message_thread.join()
|
|
1608
1644
|
self.ping_thread.join()
|
|
1609
1645
|
self.__ws_run = False
|
|
1646
|
+
self.scrips_per_channel[self.channel_num] = []
|
|
1610
1647
|
|
|
1611
1648
|
|
|
1612
1649
|
def keep_running(self):
|
|
@@ -1620,7 +1657,7 @@ class FyersDataSocket:
|
|
|
1620
1657
|
|
|
1621
1658
|
def infinite_loop(self):
|
|
1622
1659
|
while self.__ws_run:
|
|
1623
|
-
|
|
1660
|
+
time.sleep(0.5)
|
|
1624
1661
|
|
|
1625
1662
|
|
|
1626
1663
|
def is_connected(self):
|
|
@@ -1665,7 +1702,9 @@ class FyersDataSocket:
|
|
|
1665
1702
|
]
|
|
1666
1703
|
for symbols in symbol_chunks:
|
|
1667
1704
|
message = self.__unsubscription_msg(symbols)
|
|
1668
|
-
self.message.append(message)
|
|
1705
|
+
# self.message.append(message)
|
|
1706
|
+
self.add_message(message)
|
|
1707
|
+
|
|
1669
1708
|
else:
|
|
1670
1709
|
self.On_error(
|
|
1671
1710
|
{
|
|
@@ -1716,7 +1755,9 @@ class FyersDataSocket:
|
|
|
1716
1755
|
]
|
|
1717
1756
|
for symbols in symbol_chunks:
|
|
1718
1757
|
message = self.__subscription_msg(symbols)
|
|
1719
|
-
self.message.append(message)
|
|
1758
|
+
# self.message.append(message)
|
|
1759
|
+
self.add_message(message)
|
|
1760
|
+
|
|
1720
1761
|
|
|
1721
1762
|
except Exception as e:
|
|
1722
1763
|
self.data_logger.exception(e)
|
|
@@ -392,7 +392,7 @@ class FyersOrderSocket:
|
|
|
392
392
|
|
|
393
393
|
def infinite_loop(self):
|
|
394
394
|
while self.__ws_run:
|
|
395
|
-
|
|
395
|
+
time.sleep(0.5)
|
|
396
396
|
|
|
397
397
|
def connect(self) -> None:
|
|
398
398
|
"""
|
|
@@ -430,8 +430,8 @@ class FyersOrderSocket:
|
|
|
430
430
|
"""
|
|
431
431
|
|
|
432
432
|
try:
|
|
433
|
-
self.__init_connection()
|
|
434
|
-
time.sleep(1)
|
|
433
|
+
# self.__init_connection()
|
|
434
|
+
# time.sleep(1)
|
|
435
435
|
if self.__ws_object is not None:
|
|
436
436
|
self.data_type = []
|
|
437
437
|
for elem in data_type.split(","):
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
7
|
name='fyers_apiv3',
|
|
8
|
-
version='3.0.
|
|
8
|
+
version='3.0.3',
|
|
9
9
|
author="Fyers-Tech",
|
|
10
10
|
author_email="support@fyers.in",
|
|
11
11
|
description="Fyers trading APIs.",
|
|
@@ -14,7 +14,7 @@ setuptools.setup(
|
|
|
14
14
|
url="https://github.com/FyersDev/fyers-api-py",
|
|
15
15
|
packages=setuptools.find_packages(),
|
|
16
16
|
package_data={
|
|
17
|
-
'fyers_apiv3': ['/home/vinay/Documents/API-V3/
|
|
17
|
+
'fyers_apiv3': ['/home/vinay/Documents/API-V3/APIv3r3/fyers-api-py/fyers_apiv3/FyersWebsocket/map.json']
|
|
18
18
|
},
|
|
19
19
|
include_package_data=True,
|
|
20
20
|
install_requires=[
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|