tradingapi 0.5.3__tar.gz → 0.5.5__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.
- {tradingapi-0.5.3 → tradingapi-0.5.5}/PKG-INFO +1 -1
- {tradingapi-0.5.3 → tradingapi-0.5.5}/pyproject.toml +1 -1
- tradingapi-0.5.5/tests/test_fivepaisa_available_capital.py +34 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_flattrade_symbology.py +25 -1
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/dhan.py +86 -18
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/fivepaisa.py +36 -20
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/flattrade.py +54 -11
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi.egg-info/PKG-INFO +1 -1
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi.egg-info/SOURCES.txt +1 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/README.md +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/setup.cfg +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_broker_side_terminal_order.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_calculate_delta_realtime_quotes.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_calculate_mtm.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_dhan_historical_diagnostics.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_find_option_with_delta.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_fivepaisa_historical_recovery.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_fivepaisa_stream_reconnect.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_market_hours_config.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_place_combo_order_price_broker.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_symbol_matches_order.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tests/test_unfilled_eod_pnl.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/__init__.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/allocation.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/attribution.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/broker_base.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/config/commissions_20241216.yaml +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/config/config_sample.yaml +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/config.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/error_handling.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/exceptions.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/globals.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/ib.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/icicidirect.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/icicidirect_generate_session.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/market_data_exchanges.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/market_hours.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/proxy_utils.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/shoonya.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/span.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi/utils.py +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi.egg-info/dependency_links.txt +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi.egg-info/entry_points.txt +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi.egg-info/requires.txt +0 -0
- {tradingapi-0.5.3 → tradingapi-0.5.5}/tradingapi.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
sys.path.insert(0, "/home/psharma/onedrive/code/tradingapi2")
|
|
4
|
+
|
|
5
|
+
from tradingapi.fivepaisa import _cash_and_collateral_from_margin
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_total_collateral_when_stock_field_is_zero():
|
|
9
|
+
cash, collateral = _cash_and_collateral_from_margin(
|
|
10
|
+
{
|
|
11
|
+
"Ledgerbalance": 353996.5,
|
|
12
|
+
"FundsPayln": 0,
|
|
13
|
+
"MFCollateralValueAfterHaircut": 8613729.14,
|
|
14
|
+
"CollateralValueAfterHairCut": 0,
|
|
15
|
+
"TotalCollateralValue": 14131237.12,
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
assert cash == 353996.5
|
|
19
|
+
assert collateral == 14131237.12
|
|
20
|
+
assert round(cash + collateral, 2) == 14485233.62
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_split_collateral_when_it_is_larger_than_total():
|
|
24
|
+
cash, collateral = _cash_and_collateral_from_margin(
|
|
25
|
+
{
|
|
26
|
+
"Ledgerbalance": 100.0,
|
|
27
|
+
"FundsPayln": 20.0,
|
|
28
|
+
"MFCollateralValueAfterHaircut": 50.0,
|
|
29
|
+
"CollateralValueAfterHairCut": 80.0,
|
|
30
|
+
"TotalCollateralValue": 100.0,
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
assert cash == 120.0
|
|
34
|
+
assert collateral == 130.0
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import datetime as dt
|
|
2
|
+
import json
|
|
2
3
|
import sys
|
|
3
4
|
import tempfile
|
|
4
5
|
import unittest
|
|
5
6
|
from pathlib import Path
|
|
6
|
-
from unittest.mock import patch
|
|
7
|
+
from unittest.mock import Mock, patch
|
|
7
8
|
|
|
8
9
|
sys.path.insert(0, "/home/psharma/onedrive/code/tradingapi2")
|
|
9
10
|
|
|
@@ -11,6 +12,29 @@ from tradingapi import flattrade
|
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class FlatTradeSymbologyTest(unittest.TestCase):
|
|
15
|
+
def test_time_price_series_retries_json_decode_errors(self):
|
|
16
|
+
broker = object.__new__(flattrade.FlatTrade)
|
|
17
|
+
broker.api = Mock()
|
|
18
|
+
broker.api.get_time_price_series.side_effect = [
|
|
19
|
+
json.JSONDecodeError("empty", "", 0),
|
|
20
|
+
json.JSONDecodeError("empty", "", 0),
|
|
21
|
+
[{"time": "21-10-2026 09:15:00"}],
|
|
22
|
+
]
|
|
23
|
+
broker._wait_for_historical_rate_limit = Mock()
|
|
24
|
+
|
|
25
|
+
with patch.object(flattrade.time, "sleep"):
|
|
26
|
+
result = broker._get_time_price_series_with_retry(
|
|
27
|
+
exchange="NSE",
|
|
28
|
+
token="26000",
|
|
29
|
+
starttime=1.0,
|
|
30
|
+
endtime=2.0,
|
|
31
|
+
interval=1,
|
|
32
|
+
symbol="NIFTY_IND___",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
self.assertEqual(result, [{"time": "21-10-2026 09:15:00"}])
|
|
36
|
+
self.assertEqual(broker.api.get_time_price_series.call_count, 3)
|
|
37
|
+
|
|
14
38
|
def test_update_uses_bod_filename(self):
|
|
15
39
|
with tempfile.TemporaryDirectory() as folder:
|
|
16
40
|
symbols_path = Path(folder) / "20260902_symbols.csv"
|
|
@@ -609,6 +609,17 @@ class Dhan(BrokerBase):
|
|
|
609
609
|
context = create_error_context(redis_db=redis_db, broker_name=self.account_key, error=str(e))
|
|
610
610
|
raise BrokerConnectionError(f"Unexpected error connecting to Dhan: {str(e)}", context)
|
|
611
611
|
|
|
612
|
+
def _read_todays_access_token(self, token_path: Optional[str]) -> Optional[str]:
|
|
613
|
+
"""Return today's USERTOKEN contents, or None if missing/stale/empty."""
|
|
614
|
+
if not token_path or not os.path.exists(token_path):
|
|
615
|
+
return None
|
|
616
|
+
mod_date = dt.datetime.fromtimestamp(os.path.getmtime(token_path)).date()
|
|
617
|
+
if mod_date != dt.datetime.now().date():
|
|
618
|
+
return None
|
|
619
|
+
with open(token_path, "r") as f:
|
|
620
|
+
token = f.read().strip()
|
|
621
|
+
return token or None
|
|
622
|
+
|
|
612
623
|
def _load_access_token(self, force_refresh: bool = False) -> str:
|
|
613
624
|
"""
|
|
614
625
|
Load access token from file, refreshing via TOTP if stale or missing.
|
|
@@ -618,30 +629,67 @@ class Dhan(BrokerBase):
|
|
|
618
629
|
2. TOTP_TOKEN configured → do a fresh login and write to file
|
|
619
630
|
3. ACCESS_TOKEN in config → use it as a last resort (no auto-refresh)
|
|
620
631
|
|
|
621
|
-
|
|
622
|
-
|
|
632
|
+
Concurrent jobs share a Redis lock so only one process hits generateAccessToken;
|
|
633
|
+
losers re-read the file the winner wrote. force_refresh skips the file and the
|
|
634
|
+
static config token. A DH-901 means today's file is already rejected, so only a
|
|
635
|
+
new TOTP login is usable.
|
|
623
636
|
"""
|
|
624
637
|
token_path = config.get(f"{self.account_key}.USERTOKEN")
|
|
625
638
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
token = f.read().strip()
|
|
632
|
-
if token:
|
|
633
|
-
trading_logger.log_info("Loaded today's token from file", {"broker": self.account_key})
|
|
634
|
-
return token
|
|
639
|
+
if not force_refresh:
|
|
640
|
+
token = self._read_todays_access_token(token_path)
|
|
641
|
+
if token:
|
|
642
|
+
trading_logger.log_info("Loaded today's token from file", {"broker": self.account_key})
|
|
643
|
+
return token
|
|
635
644
|
|
|
636
|
-
# Try TOTP-based fresh login
|
|
637
645
|
totp_token = config.get(f"{self.account_key}.TOTP_TOKEN")
|
|
638
646
|
client_id = config.get(f"{self.account_key}.CLIENT_ID")
|
|
639
647
|
pin = config.get(f"{self.account_key}.PIN")
|
|
640
648
|
|
|
641
649
|
if totp_token and client_id and pin:
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
650
|
+
distributed_lock = None
|
|
651
|
+
lock_acquired = False
|
|
652
|
+
try:
|
|
653
|
+
lock_redis = redis.Redis(db=0, encoding="utf-8", decode_responses=True)
|
|
654
|
+
distributed_lock = lock_redis.lock(
|
|
655
|
+
f"dhan:totp-refresh:{self.account_key}",
|
|
656
|
+
timeout=300,
|
|
657
|
+
blocking_timeout=310,
|
|
658
|
+
)
|
|
659
|
+
lock_acquired = bool(distributed_lock.acquire(blocking=True))
|
|
660
|
+
except Exception as e:
|
|
661
|
+
trading_logger.log_warning(
|
|
662
|
+
"Distributed Dhan TOTP lock unavailable; generating token without it",
|
|
663
|
+
{"broker": self.account_key, "error": str(e)},
|
|
664
|
+
)
|
|
665
|
+
|
|
666
|
+
try:
|
|
667
|
+
# Winner may have written the file while we waited for the lock.
|
|
668
|
+
if not force_refresh:
|
|
669
|
+
token = self._read_todays_access_token(token_path)
|
|
670
|
+
if token:
|
|
671
|
+
trading_logger.log_info(
|
|
672
|
+
"Loaded today's token from file after lock wait",
|
|
673
|
+
{"broker": self.account_key},
|
|
674
|
+
)
|
|
675
|
+
return token
|
|
676
|
+
|
|
677
|
+
token = self._fresh_login_totp(
|
|
678
|
+
client_id,
|
|
679
|
+
pin,
|
|
680
|
+
totp_token,
|
|
681
|
+
token_path,
|
|
682
|
+
reuse_existing=not force_refresh,
|
|
683
|
+
)
|
|
684
|
+
if token:
|
|
685
|
+
return token
|
|
686
|
+
finally:
|
|
687
|
+
if lock_acquired and distributed_lock is not None:
|
|
688
|
+
try:
|
|
689
|
+
distributed_lock.release()
|
|
690
|
+
except Exception:
|
|
691
|
+
pass
|
|
692
|
+
|
|
645
693
|
if force_refresh:
|
|
646
694
|
raise AuthenticationError(
|
|
647
695
|
f"Dhan rejected the access token and TOTP login failed for {self.account_key}"
|
|
@@ -694,7 +742,14 @@ class Dhan(BrokerBase):
|
|
|
694
742
|
out = self.api.place_order(**kwargs)
|
|
695
743
|
return out
|
|
696
744
|
|
|
697
|
-
def _fresh_login_totp(
|
|
745
|
+
def _fresh_login_totp(
|
|
746
|
+
self,
|
|
747
|
+
client_id: str,
|
|
748
|
+
pin: str,
|
|
749
|
+
totp_secret: str,
|
|
750
|
+
token_path: Optional[str],
|
|
751
|
+
reuse_existing: bool = True,
|
|
752
|
+
) -> Optional[str]:
|
|
698
753
|
"""
|
|
699
754
|
Obtain a fresh Dhan access token using TOTP, mirroring FivePaisa's _fresh_login logic.
|
|
700
755
|
|
|
@@ -703,7 +758,8 @@ class Dhan(BrokerBase):
|
|
|
703
758
|
body: { dhanClientId, pin, totp }
|
|
704
759
|
|
|
705
760
|
Retries up to 5 times with 40-second waits (same as FivePaisa) to handle
|
|
706
|
-
TOTP window boundaries.
|
|
761
|
+
TOTP window boundaries. On Dhan's 2-minute rate limit, prefers reusing a
|
|
762
|
+
token another process just wrote (unless reuse_existing is False).
|
|
707
763
|
"""
|
|
708
764
|
import pyotp
|
|
709
765
|
|
|
@@ -741,8 +797,20 @@ class Dhan(BrokerBase):
|
|
|
741
797
|
"TOTP login returned no token",
|
|
742
798
|
{"attempt": attempt, "status_code": resp.status_code, "response": data},
|
|
743
799
|
)
|
|
800
|
+
# Another process may already have minted today's token.
|
|
801
|
+
if reuse_existing:
|
|
802
|
+
reused = self._read_todays_access_token(token_path)
|
|
803
|
+
if reused:
|
|
804
|
+
trading_logger.log_info(
|
|
805
|
+
"Reusing token written by another process after TOTP rate limit",
|
|
806
|
+
{"broker": self.account_key, "attempt": attempt},
|
|
807
|
+
)
|
|
808
|
+
return reused
|
|
744
809
|
if attempt < max_attempts:
|
|
745
|
-
|
|
810
|
+
msg = str((data or {}).get("message") or "").lower()
|
|
811
|
+
# Dhan allows one generateAccessToken per client every 2 minutes.
|
|
812
|
+
sleep_secs = 125 if "once every 2 minutes" in msg else 40
|
|
813
|
+
time.sleep(sleep_secs)
|
|
746
814
|
|
|
747
815
|
except Exception as e:
|
|
748
816
|
trading_logger.log_error(
|
|
@@ -298,6 +298,38 @@ def save_symbol_data(saveToFolder: bool = False):
|
|
|
298
298
|
raise
|
|
299
299
|
|
|
300
300
|
|
|
301
|
+
def _margin_float(row: Dict, key: str, default: float = 0.0) -> float:
|
|
302
|
+
try:
|
|
303
|
+
value = row.get(key, default)
|
|
304
|
+
if value is None or value == "":
|
|
305
|
+
return float(default)
|
|
306
|
+
return float(value)
|
|
307
|
+
except (TypeError, ValueError):
|
|
308
|
+
return float(default)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def _cash_and_collateral_from_margin(row: Dict) -> tuple:
|
|
312
|
+
"""Cash available plus collateral from a FivePaisa margin row.
|
|
313
|
+
|
|
314
|
+
Cash is ledger plus pay-in. Collateral is the larger of TotalCollateralValue
|
|
315
|
+
and mutual-fund collateral plus CollateralValueAfterHairCut. The total is
|
|
316
|
+
the figure that matches free margin plus margin already blocked.
|
|
317
|
+
"""
|
|
318
|
+
if "Ledgerbalance" not in row:
|
|
319
|
+
raise KeyError("Ledgerbalance")
|
|
320
|
+
cash = _margin_float(row, "Ledgerbalance") + _margin_float(row, "FundsPayln")
|
|
321
|
+
split = _margin_float(row, "MFCollateralValueAfterHaircut") + _margin_float(
|
|
322
|
+
row, "CollateralValueAfterHairCut"
|
|
323
|
+
)
|
|
324
|
+
collateral = max(split, _margin_float(row, "TotalCollateralValue"))
|
|
325
|
+
if collateral <= 0.0:
|
|
326
|
+
for field in ("Collateral", "collateral", "CollateralValue", "collateral_value"):
|
|
327
|
+
collateral = _margin_float(row, field)
|
|
328
|
+
if collateral > 0.0:
|
|
329
|
+
break
|
|
330
|
+
return cash, collateral
|
|
331
|
+
|
|
332
|
+
|
|
301
333
|
class FivePaisa(BrokerBase):
|
|
302
334
|
"""
|
|
303
335
|
FivePaisa broker implementation with enhanced error handling and logging.
|
|
@@ -1207,26 +1239,10 @@ class FivePaisa(BrokerBase):
|
|
|
1207
1239
|
if not margin_data or len(margin_data) == 0:
|
|
1208
1240
|
raise MarketDataError("No margin data available")
|
|
1209
1241
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
# Get collateral value (FivePaisa has both MF and regular collateral)
|
|
1215
|
-
collateral = 0.0
|
|
1216
|
-
try:
|
|
1217
|
-
mf_collateral = float(margin_data[0].get("MFCollateralValueAfterHaircut", 0))
|
|
1218
|
-
regular_collateral = float(margin_data[0].get("CollateralValueAfterHairCut", 0))
|
|
1219
|
-
collateral = mf_collateral + regular_collateral
|
|
1220
|
-
except (ValueError, TypeError, KeyError):
|
|
1221
|
-
# If specific fields not found, try alternative field names
|
|
1222
|
-
collateral_fields = ["Collateral", "collateral", "CollateralValue", "collateral_value"]
|
|
1223
|
-
for field in collateral_fields:
|
|
1224
|
-
if field in margin_data[0]:
|
|
1225
|
-
try:
|
|
1226
|
-
collateral = float(margin_data[0][field])
|
|
1227
|
-
break
|
|
1228
|
-
except (ValueError, TypeError):
|
|
1229
|
-
continue
|
|
1242
|
+
row = margin_data[0]
|
|
1243
|
+
cash, collateral = _cash_and_collateral_from_margin(row)
|
|
1244
|
+
ledger_balance = float(row["Ledgerbalance"])
|
|
1245
|
+
funds_payln = _margin_float(row, "FundsPayln")
|
|
1230
1246
|
|
|
1231
1247
|
used = 0.0
|
|
1232
1248
|
used_fields = [
|
|
@@ -1860,6 +1860,44 @@ class FlatTrade(BrokerBase):
|
|
|
1860
1860
|
)
|
|
1861
1861
|
self._wait_for_market_data_rate_limit_local(self._historical_rate_limit_interval_secs)
|
|
1862
1862
|
|
|
1863
|
+
def _get_time_price_series_with_retry(
|
|
1864
|
+
self,
|
|
1865
|
+
*,
|
|
1866
|
+
exchange: str,
|
|
1867
|
+
token: str,
|
|
1868
|
+
starttime: float,
|
|
1869
|
+
endtime: float,
|
|
1870
|
+
interval: int,
|
|
1871
|
+
symbol: str,
|
|
1872
|
+
) -> Optional[List]:
|
|
1873
|
+
for attempt in range(1, 4):
|
|
1874
|
+
if self.api is None:
|
|
1875
|
+
raise BrokerConnectionError("API client not initialized")
|
|
1876
|
+
try:
|
|
1877
|
+
self._wait_for_historical_rate_limit()
|
|
1878
|
+
return self.api.get_time_price_series(
|
|
1879
|
+
exchange=exchange,
|
|
1880
|
+
token=token,
|
|
1881
|
+
starttime=starttime,
|
|
1882
|
+
endtime=endtime,
|
|
1883
|
+
interval=interval,
|
|
1884
|
+
)
|
|
1885
|
+
except json.JSONDecodeError as error:
|
|
1886
|
+
trading_logger.log_warning(
|
|
1887
|
+
"JSON decode error in get_time_price_series",
|
|
1888
|
+
{
|
|
1889
|
+
"long_symbol": symbol,
|
|
1890
|
+
"exchange": exchange,
|
|
1891
|
+
"attempt": attempt,
|
|
1892
|
+
"max_attempts": 3,
|
|
1893
|
+
"error": str(error),
|
|
1894
|
+
},
|
|
1895
|
+
)
|
|
1896
|
+
if attempt == 3:
|
|
1897
|
+
raise
|
|
1898
|
+
time.sleep(0.4 * attempt)
|
|
1899
|
+
return None
|
|
1900
|
+
|
|
1863
1901
|
def _wait_for_stream_request_rate_limit(self):
|
|
1864
1902
|
limiter_redis = self._get_rate_limit_redis()
|
|
1865
1903
|
if limiter_redis is not None:
|
|
@@ -1999,11 +2037,16 @@ class FlatTrade(BrokerBase):
|
|
|
1999
2037
|
# Determine the format of symbols and create a DataFrame
|
|
2000
2038
|
if isinstance(symbols, str):
|
|
2001
2039
|
exchange = self.map_exchange_for_api(symbols, exchange)
|
|
2040
|
+
lookup_symbol = (
|
|
2041
|
+
"NIFTY_IND___"
|
|
2042
|
+
if periodicity == "1d" and symbols == "NSENIFTY_IND___"
|
|
2043
|
+
else symbols
|
|
2044
|
+
)
|
|
2002
2045
|
# Use refresh_symbol_map if available, otherwise use default mapping
|
|
2003
2046
|
if refresh_symbol_map and exchange in refresh_symbol_map:
|
|
2004
|
-
scripCode = refresh_symbol_map[exchange].get(
|
|
2047
|
+
scripCode = refresh_symbol_map[exchange].get(lookup_symbol)
|
|
2005
2048
|
else:
|
|
2006
|
-
scripCode = self.exchange_mappings[exchange]["symbol_map"].get(
|
|
2049
|
+
scripCode = self.exchange_mappings[exchange]["symbol_map"].get(lookup_symbol)
|
|
2007
2050
|
if scripCode:
|
|
2008
2051
|
symbols_pd = pd.DataFrame([{"long_symbol": symbols, "Scripcode": scripCode}])
|
|
2009
2052
|
else:
|
|
@@ -2039,10 +2082,7 @@ class FlatTrade(BrokerBase):
|
|
|
2039
2082
|
resolved_market_open_time = market_open_time or get_market_open_time(
|
|
2040
2083
|
exchange=exchange, symbol=row_outer["long_symbol"], as_of=date_start
|
|
2041
2084
|
)
|
|
2042
|
-
|
|
2043
|
-
row_outer["long_symbol"] = "NSENIFTY" + s[s.find("_") :] if s.startswith("NIFTY_") else s
|
|
2044
|
-
# we do the above remapping for downloading permin data to database for legacy reasons.
|
|
2045
|
-
# once NSENIFTY is amended to NIFTY in databae, we can remove this line.
|
|
2085
|
+
row_outer["long_symbol"] = row_outer["long_symbol"].replace("/", "-")
|
|
2046
2086
|
|
|
2047
2087
|
# Parse date_start (accepts datetime, date, or string) -> datetime for API
|
|
2048
2088
|
date_start_parsed = None
|
|
@@ -2074,19 +2114,22 @@ class FlatTrade(BrokerBase):
|
|
|
2074
2114
|
raise BrokerConnectionError("API client not initialized")
|
|
2075
2115
|
data: Optional[List] = None
|
|
2076
2116
|
if periodicity.endswith("m"):
|
|
2077
|
-
self.
|
|
2078
|
-
data = self.api.get_time_price_series(
|
|
2117
|
+
data = self._get_time_price_series_with_retry(
|
|
2079
2118
|
exchange=exch,
|
|
2080
2119
|
token=str(row_outer["Scripcode"]),
|
|
2081
2120
|
starttime=date_start_dt.timestamp(),
|
|
2082
2121
|
endtime=date_end_dt.timestamp(),
|
|
2083
2122
|
interval=extract_number(periodicity),
|
|
2123
|
+
symbol=row_outer["long_symbol"],
|
|
2084
2124
|
)
|
|
2085
2125
|
elif periodicity == "1d":
|
|
2086
|
-
|
|
2087
|
-
|
|
2126
|
+
lookup_symbol = (
|
|
2127
|
+
"NIFTY_IND___"
|
|
2128
|
+
if row_outer["long_symbol"] == "NSENIFTY_IND___"
|
|
2129
|
+
else row_outer["long_symbol"]
|
|
2130
|
+
)
|
|
2088
2131
|
trading_symbol = self.exchange_mappings[exchange]["tradingsymbol_map"].get(
|
|
2089
|
-
|
|
2132
|
+
lookup_symbol
|
|
2090
2133
|
)
|
|
2091
2134
|
|
|
2092
2135
|
def _timeout_handler(signum, frame) -> None:
|
|
@@ -5,6 +5,7 @@ tests/test_calculate_delta_realtime_quotes.py
|
|
|
5
5
|
tests/test_calculate_mtm.py
|
|
6
6
|
tests/test_dhan_historical_diagnostics.py
|
|
7
7
|
tests/test_find_option_with_delta.py
|
|
8
|
+
tests/test_fivepaisa_available_capital.py
|
|
8
9
|
tests/test_fivepaisa_historical_recovery.py
|
|
9
10
|
tests/test_fivepaisa_stream_reconnect.py
|
|
10
11
|
tests/test_flattrade_symbology.py
|
|
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
|
|
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
|
|
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
|