tradx 0.1.0__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.
@@ -0,0 +1,201 @@
1
+ from pydantic import BaseModel, BeforeValidator, Field
2
+ from typing_extensions import Annotated
3
+ from decimal import Decimal
4
+ from datetime import datetime, timedelta
5
+ from typing import Any, Dict
6
+ import json
7
+
8
+
9
+ def parse_datetime(value) -> Any:
10
+ """
11
+ Parses the given value into a datetime object if it is an integer.
12
+ If the value is an integer, it is interpreted as the number of seconds since January 1, 1980.
13
+ The function returns a datetime object representing that date and time.
14
+ If the value is not an integer, it is returned as-is.
15
+ Args:
16
+ value (Any): The value to be parsed. Expected to be an integer representing seconds since January 1, 1980, or any other type.
17
+ Returns:
18
+ Any: A datetime object if the input is an integer, otherwise the input value unchanged.
19
+ """
20
+
21
+ if isinstance(value, int):
22
+ return datetime(1980, 1, 1) + timedelta(seconds=value)
23
+ return value
24
+
25
+
26
+ class BidAskInfo(BaseModel):
27
+ """
28
+ BidAskInfo is a data model that represents bid and ask information in a trading system.
29
+ Attributes:
30
+ Size (int): The size of the bid or ask.
31
+ Price (Decimal): The price of the bid or ask.
32
+ TotalOrders (int): The total number of orders at this bid or ask price.
33
+ BuyBackMarketMaker (int): Indicator of whether the market maker is buying back.
34
+ """
35
+
36
+ Size: int
37
+ Price: Decimal
38
+ TotalOrders: int
39
+ BuyBackMarketMaker: int
40
+
41
+
42
+ class TouchLineData(BaseModel):
43
+ """
44
+ TouchLineData class represents the structure of touch line data for trading instruments.
45
+ Attributes:
46
+ MessageCode (int): The message code.
47
+ MessageVersion (int): The version of the message. Default is -1 (value is not provided).
48
+ ApplicationType (int): The type of application. Default is -1 (value is not provided).
49
+ TokenID (int): The token ID. Default is -1 (value is not provided).
50
+ ExchangeSegment (int): The exchange segment.
51
+ ExchangeInstrumentID (int): The exchange instrument ID.
52
+ ExchangeTimeStamp (datetime): The exchange timestamp.
53
+ LastTradedPrice (Decimal): The last traded price.
54
+ LastTradedQunatity (int): The last traded quantity.
55
+ TotalBuyQuantity (int): The total buy quantity.
56
+ TotalSellQuantity (int): The total sell quantity.
57
+ TotalTradedQuantity (int): The total traded quantity.
58
+ AverageTradedPrice (Decimal): The average traded price.
59
+ LastTradedTime (datetime): The last traded time.
60
+ LastUpdateTime (datetime): The last update time.
61
+ PercentChange (Decimal): The percent change.
62
+ Open (Decimal): The open price.
63
+ High (Decimal): The high price.
64
+ Low (Decimal): The low price.
65
+ Close (Decimal): The close price.
66
+ TotalValueTraded (int): The total value traded. Default is 0.
67
+ BidInfo (BidAskInfo): The bid information.
68
+ AskInfo (BidAskInfo): The ask information.
69
+ BuyBackTotalBuy (int): The total buy back. Default is -1 (value is not provided).
70
+ BuyBackTotalSell (int): The total sell back. Default is -1 (value is not provided).
71
+ BookType (int): The book type.
72
+ XMarketType (int): The market type.
73
+ SequenceNumber (int): The sequence number. Default is -1 (value is not provided).
74
+ Methods:
75
+ from_string(cls, message: str): Creates an instance of TouchLineData from a JSON string.
76
+ Example usage:
77
+ TouchLineData can be instantiated with two types of arguments:
78
+ 1. {
79
+ "MessageCode": 1501,
80
+ "ExchangeSegment": 1,
81
+ "ExchangeInstrumentID": 467,
82
+ "LastTradedPrice": 610.3,
83
+ "LastTradedQunatity": 1,
84
+ "TotalBuyQuantity": 363004,
85
+ "TotalSellQuantity": 327007,
86
+ "TotalTradedQuantity": 1983015,
87
+ "AverageTradedPrice": 612.81,
88
+ "LastTradedTime": 1420632949,
89
+ "LastUpdateTime": 1420632949,
90
+ "PercentChange": -2.038523274478332,
91
+ "Open": 627,
92
+ "High": 627,
93
+ "Low": 605.15,
94
+ "Close": 623,
95
+ "TotalValueTraded": null,
96
+ "AskInfo": {
97
+ "Size": 15,
98
+ "Price": 610.3,
99
+ "TotalOrders": 1,
100
+ "BuyBackMarketMaker": 0
101
+ },
102
+ "BidInfo": {
103
+ "Size": 119,
104
+ "Price": 610.15,
105
+ "TotalOrders": 3,
106
+ "BuyBackMarketMaker": 0
107
+ },
108
+ "XMarketType": 1,
109
+ "BookType": 1
110
+ }
111
+ 2. {
112
+ "MessageCode": 1501,
113
+ "MessageVersion": 4,
114
+ "ApplicationType": 0,
115
+ "TokenID": 0,
116
+ "ExchangeSegment": 1,
117
+ "ExchangeInstrumentID": 26000,
118
+ "ExchangeTimeStamp": 1421315385,
119
+ "Touchline": {
120
+ "BidInfo": {
121
+ "Size": 0,
122
+ "Price": 0,
123
+ "TotalOrders": 0,
124
+ "BuyBackMarketMaker": 0
125
+ },
126
+ "AskInfo": {
127
+ "Size": 0,
128
+ "Price": 0,
129
+ "TotalOrders": 0,
130
+ "BuyBackMarketMaker": 0
131
+ },
132
+ "LastTradedPrice": 23202.15,
133
+ "LastTradedQunatity": 0,
134
+ "TotalBuyQuantity": 0,
135
+ "TotalSellQuantity": 0,
136
+ "TotalTradedQuantity": 0,
137
+ "AverageTradedPrice": 23202.15,
138
+ "LastTradedTime": 1421315385,
139
+ "LastUpdateTime": 1421315385,
140
+ "PercentChange": 0.5,
141
+ "Open": 23165.9,
142
+ "High": 23227.2,
143
+ "Low": 23150.05,
144
+ "Close": 23085.95,
145
+ "TotalValueTraded": null,
146
+ "BuyBackTotalBuy": 0,
147
+ "BuyBackTotalSell": 0
148
+ },
149
+ "BookType": 1,
150
+ "XMarketType": 1,
151
+ "SequenceNumber": 1590018768596832
152
+ }
153
+ """
154
+
155
+ MessageCode: int
156
+ MessageVersion: int = Field(default=-1)
157
+ ApplicationType: int = Field(default=-1)
158
+ TokenID: int = Field(default=-1)
159
+ ExchangeSegment: int
160
+ ExchangeInstrumentID: int
161
+ ExchangeTimeStamp: Annotated[
162
+ datetime, Field(default=datetime(1980, 1, 1)), BeforeValidator(parse_datetime)
163
+ ]
164
+ LastTradedPrice: Decimal
165
+ LastTradedQunatity: int
166
+ TotalBuyQuantity: int
167
+ TotalSellQuantity: int
168
+ TotalTradedQuantity: int
169
+ AverageTradedPrice: Decimal
170
+ LastTradedTime: Annotated[datetime, BeforeValidator(parse_datetime)]
171
+ LastUpdateTime: Annotated[datetime, BeforeValidator(parse_datetime)]
172
+ PercentChange: Decimal
173
+ Open: Decimal
174
+ High: Decimal
175
+ Low: Decimal
176
+ Close: Decimal
177
+ TotalValueTraded: Annotated[
178
+ int, BeforeValidator(lambda x: x if x is not None else 0)
179
+ ]
180
+ BidInfo: BidAskInfo
181
+ AskInfo: BidAskInfo
182
+ BuyBackTotalBuy: int = Field(default=-1)
183
+ BuyBackTotalSell: int = Field(default=-1)
184
+ BookType: int
185
+ XMarketType: int
186
+ SequenceNumber: int = Field(default=-1)
187
+
188
+ def __init__(self, input_data: Any):
189
+ if isinstance(input_data, dict):
190
+
191
+ super().__init__(**input_data)
192
+ elif isinstance(input_data, str):
193
+
194
+ data = json.loads(input_data)
195
+ if "Touchline" in data:
196
+ touchline_data = data.pop("Touchline")
197
+ super().__init__(**data, **touchline_data)
198
+ else:
199
+ super().__init__(**data)
200
+ else:
201
+ raise ValueError("Unsupported input type for TouchLineData")
@@ -0,0 +1,109 @@
1
+ from pydantic import BaseModel, BeforeValidator
2
+ from typing_extensions import Annotated
3
+ from decimal import Decimal
4
+ from datetime import datetime, timedelta
5
+ from typing import Any
6
+ import json
7
+
8
+
9
+ def parse_datetime(value) -> Any:
10
+ """
11
+ Parses the given value into a datetime object if it is an integer.
12
+ If the value is an integer, it is interpreted as the number of seconds since January 1, 1980.
13
+ The function returns a datetime object representing that date and time.
14
+ If the value is not an integer, it is returned as-is.
15
+ Args:
16
+ value (Any): The value to be parsed. Expected to be an integer representing seconds since January 1, 1980, or any other type.
17
+ Returns:
18
+ Any: A datetime object if the input is an integer, otherwise the input value unchanged.
19
+ """
20
+
21
+ if isinstance(value, int):
22
+ return datetime(1980, 1, 1) + timedelta(seconds=value)
23
+ return value
24
+
25
+
26
+ class BidAskInfo(BaseModel):
27
+ """
28
+ BidAskInfo is a data model that represents bid and ask information in a trading system.
29
+ Attributes:
30
+ Size (int): The size of the bid or ask.
31
+ Price (Decimal): The price of the bid or ask.
32
+ TotalOrders (int): The total number of orders at this bid or ask price.
33
+ BuyBackMarketMaker (int): Indicator of whether the market maker is buying back.
34
+ """
35
+
36
+ Size: int
37
+ Price: Decimal
38
+ TotalOrders: int
39
+ BuyBackMarketMaker: int
40
+
41
+
42
+ class TouchLinePartialData(BaseModel):
43
+
44
+ ExchangeSegment: int
45
+ ExchangeInstrumentID: int
46
+ LastTradedPrice: Decimal
47
+ LastTradedQunatity: int
48
+ TotalBuyQuantity: int
49
+ TotalSellQuantity: int
50
+ Volume: int
51
+ AverageTradedPrice: Decimal
52
+ LastTradedTime: Annotated[datetime, BeforeValidator(parse_datetime)]
53
+ LastUpdateTime: Annotated[datetime, BeforeValidator(parse_datetime)]
54
+ PercentChange: Decimal
55
+ Open: Decimal
56
+ High: Decimal
57
+ Low: Decimal
58
+ Close: Decimal
59
+ TotalPriceVolume: int
60
+ BidInfo: BidAskInfo
61
+ AskInfo: BidAskInfo
62
+
63
+ def __init__(self, data: str):
64
+ data = "".join(data.split())
65
+ fields = dict(item.split(":") for item in data.split(","))
66
+ data_dict = {}
67
+ data_dict["ExchangeSegment"], data_dict["ExchangeInstrumentID"] = fields[
68
+ "t"
69
+ ].split("_")
70
+ data_dict["LastTradedPrice"] = Decimal(fields["ltp"])
71
+ data_dict["LastTradedQunatity"] = fields["ltq"]
72
+ data_dict["TotalBuyQuantity"] = fields["tb"]
73
+ data_dict["TotalSellQuantity"] = fields["ts"]
74
+ data_dict["Volume"] = fields["v"]
75
+ data_dict["AverageTradedPrice"] = Decimal(fields["ap"])
76
+ data_dict["LastTradedTime"] = fields["ltt"]
77
+ data_dict["LastUpdateTime"] = fields["lut"]
78
+ data_dict["PercentChange"] = Decimal(fields["pc"])
79
+ data_dict["Open"] = Decimal(fields["o"])
80
+ data_dict["High"] = Decimal(fields["h"])
81
+ data_dict["Low"] = Decimal(fields["l"])
82
+ data_dict["Close"] = Decimal(fields["c"])
83
+ data_dict["TotalPriceVolume"] = fields["vp"]
84
+ bid_info_fields = fields["bi"].split("|")
85
+ ask_info_fields = fields["ai"].split("|")
86
+ data_dict["BidInfo"] = BidAskInfo(
87
+ Size=int(bid_info_fields[0]),
88
+ Price=Decimal(bid_info_fields[1]),
89
+ TotalOrders=int(bid_info_fields[2]),
90
+ BuyBackMarketMaker=int(bid_info_fields[3]),
91
+ )
92
+ data_dict["AskInfo"] = BidAskInfo(
93
+ Size=int(ask_info_fields[0]),
94
+ Price=Decimal(ask_info_fields[1]),
95
+ TotalOrders=int(ask_info_fields[2]),
96
+ BuyBackMarketMaker=int(ask_info_fields[3]),
97
+ )
98
+ super().__init__(**data_dict)
99
+
100
+
101
+ a = """
102
+ t:1_22,ltp:1567.95,ltq:20,tb:1428,ts:0,v:253453,ap:1576.2,ltt:1205682110,
103
+ lut:1205682251,pc:0,o:1599.9,h:1607.25,l:1552.7,c:1567.95,vp:177838490,
104
+ ai:0|1428|1567.95|10,bi:0|0|0|0|1
105
+ """
106
+ c = TouchLinePartialData.from_string(a)
107
+ print(c)
108
+
109
+ # Incomplete information, waiting for response from the user
@@ -0,0 +1,80 @@
1
+ from pydantic import BaseModel
2
+ from typing import Optional, Any
3
+ from datetime import datetime
4
+ from decimal import Decimal
5
+ import json
6
+
7
+
8
+ class TradeConversionEvent(BaseModel):
9
+ """
10
+ TradeConversionEvent represents an event of trade conversion with various attributes.
11
+ Attributes:
12
+ LoginID (str): The login ID of the user.
13
+ ClientID (str): The client ID associated with the trade.
14
+ UniqueKey (str): A unique key identifying the trade conversion event.
15
+ Success (bool): Indicates whether the trade conversion was successful.
16
+ ErrorMessage (Optional[str]): Error message if the trade conversion failed.
17
+ OriginalProduct (str): The original product involved in the trade.
18
+ TargetProduct (str): The target product after conversion.
19
+ OriginalQty (int): The original quantity of the product.
20
+ TargetQty (int): The target quantity after conversion.
21
+ EntityType (str): The type of entity involved in the trade.
22
+ ExchangeSegment (str): The exchange segment where the trade occurred.
23
+ ExchangeInstrumentId (int): The ID of the exchange instrument.
24
+ TargetEntityId (str): The ID of the target entity.
25
+ NetValue (Decimal): The net value of the trade.
26
+ Status (str): The status of the trade conversion.
27
+ RejectionReason (Optional[str]): The reason for rejection if the trade was rejected.
28
+ RejectedBy (Optional[str]): The entity that rejected the trade.
29
+ Price (Decimal): The price at which the trade was executed.
30
+ NOWTimeStamp (datetime): The timestamp of the trade conversion event.
31
+ OrderSide (str): The side of the order (e.g., buy or sell).
32
+ IsProOrder (bool): Indicates if the order is a professional order.
33
+ MessageCode (int): The message code associated with the trade.
34
+ MessageVersion (int): The version of the message.
35
+ TokenID (int): The token ID associated with the trade.
36
+ ApplicationType (int): The type of application used for the trade.
37
+ SequenceNumber (int): The sequence number of the trade.
38
+ Methods:
39
+ from_string(cls, message: str): Creates an instance of TradeConversionEvent from a JSON string.
40
+ """
41
+
42
+ LoginID: str
43
+ ClientID: str
44
+ UniqueKey: str
45
+ Success: bool
46
+ ErrorMessage: Optional[str]
47
+ OriginalProduct: str
48
+ TargetProduct: str
49
+ OriginalQty: int
50
+ TargetQty: int
51
+ EntityType: str
52
+ ExchangeSegment: str
53
+ ExchangeInstrumentId: int
54
+ TargetEntityId: str
55
+ NetValue: Decimal
56
+ Status: str
57
+ RejectionReason: Optional[str]
58
+ RejectedBy: Optional[str]
59
+ Price: Decimal
60
+ NOWTimeStamp: datetime
61
+ OrderSide: str
62
+ IsProOrder: bool
63
+ MessageCode: int
64
+ MessageVersion: int
65
+ TokenID: int
66
+ ApplicationType: int
67
+ SequenceNumber: int
68
+
69
+ def __init__(self, input_data: Any):
70
+ if isinstance(input_data, dict):
71
+
72
+ super().__init__(**input_data)
73
+ elif isinstance(input_data, str):
74
+
75
+ data = json.loads(input_data)
76
+ super().__init__(**data)
77
+ else:
78
+ raise ValueError("Unsupported input type for MarketStatusData")
79
+
80
+
@@ -0,0 +1,153 @@
1
+ from pydantic import BaseModel, BeforeValidator
2
+ from typing_extensions import Annotated
3
+ from typing import Optional, Any, Dict
4
+ from datetime import datetime
5
+ from decimal import Decimal
6
+ import json
7
+
8
+
9
+ def parse_decimal(value) -> Any:
10
+ """
11
+ Converts a string representation of a decimal number to a Decimal object,
12
+ removing any commas. If the input is not a string, it returns the input as is.
13
+ Args:
14
+ value (str or any): The value to be converted to a Decimal. If the value
15
+ is a string, it will remove any commas before conversion.
16
+ Returns:
17
+ Decimal or any: The Decimal representation of the input string, or the
18
+ original input if it is not a string.
19
+ """
20
+
21
+ if isinstance(value, str):
22
+ value = value.replace(",", "")
23
+ return Decimal(value)
24
+ return value
25
+
26
+
27
+ def parse_datetime(value) -> Any:
28
+ """
29
+ Parses a datetime string into a datetime object.
30
+ Args:
31
+ value (Any): The value to be parsed. If the value is a string, it should be in the format "%d-%m-%Y %H:%M:%S".
32
+ Returns:
33
+ Any: A datetime object if the input is a string in the correct format, otherwise returns the input value unchanged.
34
+ """
35
+
36
+ if isinstance(value, str):
37
+ return datetime.strptime(value, "%d-%m-%Y %H:%M:%S")
38
+ return value
39
+
40
+
41
+ class TradeEvent(BaseModel):
42
+ """
43
+ TradeEvent model representing a trade event with various attributes.
44
+ Attributes:
45
+ LoginID (str): The login ID of the user.
46
+ ClientID (str): The client ID, default is "*****".
47
+ AppOrderID (int): The application order ID.
48
+ OrderReferenceID (Optional[str]): The order reference ID.
49
+ GeneratedBy (str): The entity that generated the order.
50
+ ExchangeOrderID (str): The exchange order ID.
51
+ OrderCategoryType (str): The category type of the order.
52
+ ExchangeSegment (str): The exchange segment.
53
+ ExchangeInstrumentID (int): The exchange instrument ID.
54
+ OrderSide (str): The side of the order (buy/sell).
55
+ OrderType (str): The type of the order.
56
+ ProductType (str): The product type.
57
+ TimeInForce (str): The time in force for the order.
58
+ OrderPrice (Decimal): The price of the order.
59
+ OrderQuantity (int): The quantity of the order.
60
+ OrderStopPrice (Decimal): The stop price of the order.
61
+ OrderStatus (str): The status of the order.
62
+ OrderAverageTradedPrice (Decimal): The average traded price of the order.
63
+ LeavesQuantity (int): The remaining quantity of the order.
64
+ CumulativeQuantity (int): The cumulative quantity of the order.
65
+ OrderDisclosedQuantity (int): The disclosed quantity of the order.
66
+ OrderGeneratedDateTime (datetime): The date and time the order was generated.
67
+ ExchangeTransactTime (datetime): The transaction time on the exchange.
68
+ LastUpdateDateTime (datetime): The last update date and time.
69
+ CancelRejectReason (Optional[str]): The reason for order cancellation or rejection.
70
+ OrderUniqueIdentifier (str): The unique identifier for the order.
71
+ OrderLegStatus (str): The status of the order leg.
72
+ LastTradedPrice (Decimal): The last traded price.
73
+ LastTradedQuantity (int): The last traded quantity.
74
+ LastExecutionTransactTime (datetime): The last execution transaction time.
75
+ ExecutionID (str): The execution ID.
76
+ ExecutionReportIndex (int): The execution report index.
77
+ IsSpread (bool): Indicates if the order is a spread.
78
+ OrderAverageTradedPriceAPI (Decimal): The average traded price from the API.
79
+ OrderSideAPI (str): The order side from the API.
80
+ OrderGeneratedDateTimeAPI (datetime): The order generated date and time from the API.
81
+ ExchangeTransactTimeAPI (datetime): The exchange transaction time from the API.
82
+ LastUpdateDateTimeAPI (datetime): The last update date and time from the API.
83
+ OrderExpiryDateAPI (datetime): The order expiry date from the API.
84
+ LastExecutionTransactTimeAPI (datetime): The last execution transaction time from the API.
85
+ MessageSynchronizeUniqueKey (str): The unique key for message synchronization.
86
+ MessageCode (int): The message code.
87
+ MessageVersion (int): The message version.
88
+ TokenID (int): The token ID.
89
+ ApplicationType (int): The application type.
90
+ SequenceNumber (int): The sequence number.
91
+ TradingSymbol (str): The trading symbol.
92
+ Methods:
93
+ from_string(cls, message: str): Creates an instance of TradeEvent from a JSON string.
94
+ """
95
+
96
+ LoginID: str
97
+ ClientID: str = "*****"
98
+ AppOrderID: int
99
+ OrderReferenceID: Optional[str]
100
+ GeneratedBy: str
101
+ ExchangeOrderID: str
102
+ OrderCategoryType: str
103
+ ExchangeSegment: str
104
+ ExchangeInstrumentID: int
105
+ OrderSide: str
106
+ OrderType: str
107
+ ProductType: str
108
+ TimeInForce: str
109
+ OrderPrice: Decimal
110
+ OrderQuantity: int
111
+ OrderStopPrice: Decimal
112
+ OrderStatus: str
113
+ OrderAverageTradedPrice: Annotated[Decimal, BeforeValidator(parse_decimal)]
114
+ LeavesQuantity: int
115
+ CumulativeQuantity: int
116
+ OrderDisclosedQuantity: int
117
+ OrderGeneratedDateTime: datetime
118
+ ExchangeTransactTime: datetime
119
+ LastUpdateDateTime: datetime
120
+ CancelRejectReason: Optional[str]
121
+ OrderUniqueIdentifier: str
122
+ OrderLegStatus: str
123
+ LastTradedPrice: Decimal
124
+ LastTradedQuantity: int
125
+ LastExecutionTransactTime: datetime
126
+ ExecutionID: str
127
+ ExecutionReportIndex: int
128
+ IsSpread: bool
129
+ OrderAverageTradedPriceAPI: Decimal
130
+ OrderSideAPI: str
131
+ OrderGeneratedDateTimeAPI: Annotated[datetime, BeforeValidator(parse_datetime)]
132
+ ExchangeTransactTimeAPI: Annotated[datetime, BeforeValidator(parse_datetime)]
133
+ LastUpdateDateTimeAPI: Annotated[datetime, BeforeValidator(parse_datetime)]
134
+ OrderExpiryDateAPI: Annotated[datetime, BeforeValidator(parse_datetime)]
135
+ LastExecutionTransactTimeAPI: Annotated[datetime, BeforeValidator(parse_datetime)]
136
+ MessageSynchronizeUniqueKey: str
137
+ MessageCode: int
138
+ MessageVersion: int
139
+ TokenID: int
140
+ ApplicationType: int
141
+ SequenceNumber: int
142
+ TradingSymbol: str
143
+
144
+ def __init__(self, input_data: Any):
145
+ if isinstance(input_data, dict):
146
+
147
+ super().__init__(**input_data)
148
+ elif isinstance(input_data, str):
149
+
150
+ data = json.loads(input_data)
151
+ super().__init__(**data)
152
+ else:
153
+ raise ValueError("Unsupported input type for MarketStatusData")
@@ -0,0 +1,32 @@
1
+ """
2
+ This module defines a list of holidays for the years 2024 and 2025.
3
+
4
+ The holidays are represented as `datetime.date` objects and include major
5
+ festivals and public holidays such as Christmas, Mahashivratri, Holi,
6
+ Id-Ul-Fitr, Shri Mahavir Jayanti, Dr. Baba Saheb Ambedkar Jayanti,
7
+ Good Friday, Maharashtra Day, Independence Day, Ganesh Chaturthi,
8
+ Mahatma Gandhi Jayanti/Dussehra, Diwali Laxmi Pujan, Diwali-Balipratipada,
9
+ and Prakash Gurpurb Sri Guru Nanak Dev.
10
+
11
+ The holidays list can be used for various purposes such as checking if a
12
+ given date is a holiday, scheduling events, or generating holiday calendars.
13
+ """
14
+ from datetime import datetime
15
+
16
+ holidays = [
17
+ datetime(2024, 12, 25).date(), # Christmas
18
+ datetime(2025, 2, 26).date(), # Mahashivratri
19
+ datetime(2025, 3, 14).date(), # Holi
20
+ datetime(2025, 3, 31).date(), # Id-Ul-Fitr (Ramadan Eid)
21
+ datetime(2025, 4, 10).date(), # Shri Mahavir Jayanti
22
+ datetime(2025, 4, 14).date(), # Dr. Baba Saheb Ambedkar Jayanti
23
+ datetime(2025, 4, 18).date(), # Good Friday
24
+ datetime(2025, 5, 1).date(), # Maharashtra Day
25
+ datetime(2025, 8, 15).date(), # Independence Day
26
+ datetime(2025, 8, 27).date(), # Ganesh Chaturthi
27
+ datetime(2025, 10, 2).date(), # Mahatma Gandhi Jayanti/Dussehra
28
+ datetime(2025, 10, 21).date(), # Diwali Laxmi Pujan
29
+ datetime(2025, 10, 22).date(), # Diwali-Balipratipada
30
+ datetime(2025, 11, 5).date(), # Prakash Gurpurb Sri Guru Nanak Dev
31
+ datetime(2025, 12, 25).date(), # Christmas
32
+ ]
tradx/dualHashMap.py ADDED
@@ -0,0 +1,57 @@
1
+ from typing import Dict, Any
2
+
3
+
4
+ class DualHashMap:
5
+ def __init__(self):
6
+ # Single dictionary to maintain bidirectional mapping
7
+ self.mapping: Dict[Any, Any] = {}
8
+
9
+ def insert(self, key, value):
10
+ """
11
+ Inserts a key-value pair into the hash map.
12
+
13
+ :param key: An integer key or a string key.
14
+ :param value: A string value or an integer value.
15
+ """
16
+ assert isinstance(key, (str, int)), "Value must be a string or an integer"
17
+ assert isinstance(value, (str, int)), "Value must be a string or an integer"
18
+ self.mapping[key] = value
19
+ self.mapping[value] = key
20
+
21
+ def get(self, key):
22
+ """
23
+ Retrieves the value associated with the key.
24
+
25
+ :param key: An integer or string key.
26
+ :return: The associated value (string for int keys, int for string keys).
27
+ :raises KeyError: If the key does not exist.
28
+ """
29
+ return self.mapping[key]
30
+
31
+ def remove(self, key):
32
+ """
33
+ Removes the key-value pair associated with the given key.
34
+
35
+ :param key: An integer or string key.
36
+ :raises KeyError: If the key does not exist.
37
+ """
38
+ value = self.mapping.pop(key)
39
+ self.mapping.pop(value)
40
+
41
+ def __repr__(self):
42
+ return f"DualHashMap({{k: v for k, v in self.mapping.items() if isinstance(k, int)}})"
43
+
44
+ """
45
+ # Example usage:
46
+ dual_map = DualHashMap()
47
+ dual_map.insert(1, "one")
48
+ dual_map.insert(2, "two")
49
+
50
+ print(dual_map.get(1)) # Output: "one"
51
+ print(dual_map.get("one")) # Output: 1
52
+
53
+ # Remove a mapping
54
+ dual_map.remove(1)
55
+
56
+ print(dual_map) # Output: DualHashMap({2: 'two'})
57
+ """