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.
- tradx/__init__.py +2 -0
- tradx/algoContainer.py +90 -0
- tradx/baseClass/baseAlgo.py +338 -0
- tradx/baseClass/candleData.py +89 -0
- tradx/baseClass/cmInstrument.py +84 -0
- tradx/baseClass/futureInstrument.py +74 -0
- tradx/baseClass/index.py +24 -0
- tradx/baseClass/instrumentPropertyChangeData.py +14 -0
- tradx/baseClass/ltpData.py +89 -0
- tradx/baseClass/ltpPartialData.py +108 -0
- tradx/baseClass/marketDepthData.py +126 -0
- tradx/baseClass/marketStatusData.py +110 -0
- tradx/baseClass/openInterestData.py +84 -0
- tradx/baseClass/openInterestPartialData.py +47 -0
- tradx/baseClass/optionsInstrument.py +279 -0
- tradx/baseClass/order.py +27 -0
- tradx/baseClass/orderEvent.py +90 -0
- tradx/baseClass/position.py +46 -0
- tradx/baseClass/positionEvent.py +84 -0
- tradx/baseClass/touchLineData.py +201 -0
- tradx/baseClass/touchLinePartialData.py +109 -0
- tradx/baseClass/tradeConversionEvent.py +80 -0
- tradx/baseClass/tradeEvent.py +153 -0
- tradx/constants/holidays.py +32 -0
- tradx/dualHashMap.py +57 -0
- tradx/interactiveEngine.py +764 -0
- tradx/logger/logger.py +83 -0
- tradx/logger/logger2.py +73 -0
- tradx/marketDataEngine.py +781 -0
- tradx/py.typed +0 -0
- tradx-0.1.0.dist-info/METADATA +69 -0
- tradx-0.1.0.dist-info/RECORD +33 -0
- tradx-0.1.0.dist-info/WHEEL +4 -0
tradx/baseClass/index.py
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
from pydantic import BaseModel
|
2
|
+
|
3
|
+
class Index(BaseModel):
|
4
|
+
"""
|
5
|
+
A class used to represent an Index.
|
6
|
+
Attributes
|
7
|
+
----------
|
8
|
+
Name : str
|
9
|
+
The name of the index.
|
10
|
+
ExchangeSegment : int
|
11
|
+
The segment of the exchange.
|
12
|
+
ExchangeInstrumentID : int
|
13
|
+
The instrument ID of the exchange.
|
14
|
+
Methods
|
15
|
+
-------
|
16
|
+
__init__(self, Name: str, ExchangeSegment: int, ExchangeInstrumentID: int)
|
17
|
+
Constructs all the necessary attributes for the Index object.
|
18
|
+
"""
|
19
|
+
|
20
|
+
Name: str
|
21
|
+
ExchangeSegment: int
|
22
|
+
ExchangeInstrumentID: int
|
23
|
+
def __init__(self, Name: str, ExchangeSegment: int, ExchangeInstrumentID: int):
|
24
|
+
super().__init__(Name=Name, ExchangeSegment=ExchangeSegment, ExchangeInstrumentID=ExchangeInstrumentID)
|
@@ -0,0 +1,14 @@
|
|
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
|
+
from enum import Enum
|
8
|
+
|
9
|
+
|
10
|
+
class InstrumentPropertyChangeData(BaseModel):
|
11
|
+
"""
|
12
|
+
yet to be implemented
|
13
|
+
"""
|
14
|
+
...
|
@@ -0,0 +1,89 @@
|
|
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, Dict
|
6
|
+
import json
|
7
|
+
from enum import Enum
|
8
|
+
|
9
|
+
|
10
|
+
def parse_datetime(value) -> Any:
|
11
|
+
"""
|
12
|
+
Parses the given value into a datetime object if it is an integer.
|
13
|
+
If the value is an integer, it is interpreted as the number of seconds since January 1, 1980.
|
14
|
+
The function returns a datetime object representing that date and time.
|
15
|
+
If the value is not an integer, it is returned as-is.
|
16
|
+
Args:
|
17
|
+
value (Any): The value to be parsed. Expected to be an integer representing seconds since January 1, 1980, or any other type.
|
18
|
+
Returns:
|
19
|
+
Any: A datetime object if the input is an integer, otherwise the input value unchanged.
|
20
|
+
"""
|
21
|
+
|
22
|
+
if isinstance(value, int):
|
23
|
+
return datetime(1980, 1, 1) + timedelta(seconds=value)
|
24
|
+
return value
|
25
|
+
|
26
|
+
|
27
|
+
class ExchangeMarketType(Enum):
|
28
|
+
"""
|
29
|
+
Enum class representing different types of exchange market statuses.
|
30
|
+
Attributes:
|
31
|
+
Normal (int): Represents a normal market type.
|
32
|
+
OddLot (int): Represents an odd lot market type.
|
33
|
+
Spot (int): Represents a spot market type.
|
34
|
+
Auction (int): Represents an auction market type.
|
35
|
+
CallAuction1 (int): Represents the first call auction market type.
|
36
|
+
CallAuction2 (int): Represents the second call auction market type.
|
37
|
+
"""
|
38
|
+
|
39
|
+
Normal = 1
|
40
|
+
OddLot = 2
|
41
|
+
Spot = 3
|
42
|
+
Auction = 4
|
43
|
+
CallAuction1 = 5
|
44
|
+
CallAuction2 = 6
|
45
|
+
|
46
|
+
|
47
|
+
class LtpData(BaseModel):
|
48
|
+
"""
|
49
|
+
LtpData model representing the Last Traded Price data.
|
50
|
+
Attributes:
|
51
|
+
MessageCode (int): The message code.
|
52
|
+
MessageVersion (int): The version of the message.
|
53
|
+
ApplicationType (int): The type of application.
|
54
|
+
TokenID (int): The token ID.
|
55
|
+
ExchangeSegment (int): The exchange segment.
|
56
|
+
ExchangeInstrumentID (int): The exchange instrument ID.
|
57
|
+
BookType (int): The type of book.
|
58
|
+
XMarketType (ExchangeMarketType): The market type.
|
59
|
+
LastTradedPrice (Decimal): The last traded price.
|
60
|
+
LastTradedQunatity (int): The last traded quantity.
|
61
|
+
LastUpdateTime (datetime): The last update time, parsed from a string.
|
62
|
+
Methods:
|
63
|
+
from_string(cls, message: str): Class method to create an instance of LtpData from a JSON string.
|
64
|
+
"""
|
65
|
+
|
66
|
+
MessageCode: int
|
67
|
+
MessageVersion: int
|
68
|
+
ApplicationType: int
|
69
|
+
TokenID: int
|
70
|
+
ExchangeSegment: int
|
71
|
+
ExchangeInstrumentID: int
|
72
|
+
BookType: int
|
73
|
+
XMarketType: ExchangeMarketType
|
74
|
+
LastTradedPrice: Decimal
|
75
|
+
LastTradedQunatity: int
|
76
|
+
LastUpdateTime: Annotated[datetime, BeforeValidator(parse_datetime)]
|
77
|
+
|
78
|
+
class Config:
|
79
|
+
use_enum_values = True
|
80
|
+
|
81
|
+
def __init__(self, input_data: Any):
|
82
|
+
if isinstance(input_data, dict):
|
83
|
+
super().__init__(**input_data)
|
84
|
+
elif isinstance(input_data, str):
|
85
|
+
|
86
|
+
data = json.loads(input_data)
|
87
|
+
super().__init__(**data)
|
88
|
+
else:
|
89
|
+
raise ValueError("Unsupported input type for LtpData")
|
@@ -0,0 +1,108 @@
|
|
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, Dict
|
6
|
+
import json
|
7
|
+
from enum import Enum
|
8
|
+
|
9
|
+
|
10
|
+
def parse_datetime(value) -> Any:
|
11
|
+
"""
|
12
|
+
Parses the given value into a datetime object if it is an integer.
|
13
|
+
If the value is an integer, it is interpreted as the number of seconds since January 1, 1980.
|
14
|
+
The function returns a datetime object representing that date and time.
|
15
|
+
If the value is not an integer, it is returned as-is.
|
16
|
+
Args:
|
17
|
+
value (Any): The value to be parsed. Expected to be an integer representing seconds since January 1, 1980, or any other type.
|
18
|
+
Returns:
|
19
|
+
Any: A datetime object if the input is an integer, otherwise the input value unchanged.
|
20
|
+
"""
|
21
|
+
|
22
|
+
if isinstance(value, int):
|
23
|
+
return datetime(1980, 1, 1) + timedelta(seconds=value)
|
24
|
+
return value
|
25
|
+
|
26
|
+
|
27
|
+
class ExchangeMarketType(Enum):
|
28
|
+
"""
|
29
|
+
Enum class representing different types of exchange market statuses.
|
30
|
+
Attributes:
|
31
|
+
Normal (int): Represents a normal market type.
|
32
|
+
OddLot (int): Represents an odd lot market type.
|
33
|
+
Spot (int): Represents a spot market type.
|
34
|
+
Auction (int): Represents an auction market type.
|
35
|
+
CallAuction1 (int): Represents the first call auction market type.
|
36
|
+
CallAuction2 (int): Represents the second call auction market type.
|
37
|
+
"""
|
38
|
+
|
39
|
+
Normal = 1
|
40
|
+
OddLot = 2
|
41
|
+
Spot = 3
|
42
|
+
Auction = 4
|
43
|
+
CallAuction1 = 5
|
44
|
+
CallAuction2 = 6
|
45
|
+
|
46
|
+
|
47
|
+
class LtpPartialData(BaseModel):
|
48
|
+
"""
|
49
|
+
LtpPartialData is a model representing partial data for the last traded price (LTP) of an instrument.
|
50
|
+
Attributes:
|
51
|
+
ExchangeSegment (int): The exchange segment identifier.
|
52
|
+
ExchangeInstrumentID (int): The exchange instrument identifier.
|
53
|
+
BookType (int): The book type identifier.
|
54
|
+
MarketType (ExchangeMarketType): The market type.
|
55
|
+
LastTradedPrice (Decimal): The last traded price of the instrument.
|
56
|
+
LastTradedQunatity (int): The last traded quantity of the instrument.
|
57
|
+
LastUpdateTime (datetime): The last update time of the data.
|
58
|
+
Methods:
|
59
|
+
from_string(cls, message: str): Parses a string message to create an instance of LtpPartialData.
|
60
|
+
Args:
|
61
|
+
message (str): The input string containing key-value pairs separated by commas.
|
62
|
+
Returns:
|
63
|
+
LtpPartialData: An instance of LtpPartialData populated with the parsed data.
|
64
|
+
"""
|
65
|
+
|
66
|
+
ExchangeSegment: int
|
67
|
+
ExchangeInstrumentID: int
|
68
|
+
BookType: int
|
69
|
+
MarketType: ExchangeMarketType
|
70
|
+
LastTradedPrice: Decimal
|
71
|
+
LastTradedQunatity: int
|
72
|
+
LastUpdateTime: Annotated[datetime, BeforeValidator(parse_datetime)]
|
73
|
+
|
74
|
+
class Config:
|
75
|
+
use_enum_values = True
|
76
|
+
|
77
|
+
def __init__(self, input_data: Any):
|
78
|
+
if isinstance(input_data, dict):
|
79
|
+
|
80
|
+
super().__init__(**input_data)
|
81
|
+
elif isinstance(input_data, str):
|
82
|
+
|
83
|
+
# Split the message by commas to get individual key-value pairs
|
84
|
+
key_value_pairs = input_data.split(",")
|
85
|
+
|
86
|
+
# Initialize an empty dictionary to store the parsed data
|
87
|
+
data = {}
|
88
|
+
|
89
|
+
# Iterate over each key-value pair
|
90
|
+
for pair in key_value_pairs:
|
91
|
+
key, value = pair.split(":")
|
92
|
+
if key == "t":
|
93
|
+
exchange_segment, instrument_id = map(int, value.split("_"))
|
94
|
+
data["ExchangeSegment"] = exchange_segment
|
95
|
+
data["ExchangeInstrumentID"] = instrument_id
|
96
|
+
elif key == "ltp":
|
97
|
+
data["LastTradedPrice"] = Decimal(value)
|
98
|
+
elif key == "ltq":
|
99
|
+
data["LastTradedQunatity"] = int(value)
|
100
|
+
elif key == "lut":
|
101
|
+
data["LastUpdateTime"] = int(value)
|
102
|
+
elif key == "bt":
|
103
|
+
data["BookType"] = int(value)
|
104
|
+
elif key == "mt":
|
105
|
+
data["MarketType"] = int(value)
|
106
|
+
super().__init__(**data)
|
107
|
+
else:
|
108
|
+
raise ValueError("Unsupported input type for LtpPartialData")
|
@@ -0,0 +1,126 @@
|
|
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, 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 representing the bid and ask information in a market depth context.
|
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 if the market maker is buying back.
|
34
|
+
"""
|
35
|
+
|
36
|
+
Size: int
|
37
|
+
Price: Decimal
|
38
|
+
TotalOrders: int
|
39
|
+
BuyBackMarketMaker: int
|
40
|
+
|
41
|
+
|
42
|
+
class TouchlineInfo(BaseModel):
|
43
|
+
"""
|
44
|
+
TouchlineInfo represents the market depth data for a trading instrument.
|
45
|
+
Attributes:
|
46
|
+
BidInfo (BidAskInfo): Information about the bid.
|
47
|
+
AskInfo (BidAskInfo): Information about the ask.
|
48
|
+
LastTradedPrice (Decimal): The last traded price of the instrument.
|
49
|
+
LastTradedQunatity (int): The quantity of the last trade.
|
50
|
+
TotalBuyQuantity (int): The total quantity of buy orders.
|
51
|
+
TotalSellQuantity (int): The total quantity of sell orders.
|
52
|
+
TotalTradedQuantity (int): The total quantity of traded orders.
|
53
|
+
AverageTradedPrice (Decimal): The average price of traded orders.
|
54
|
+
LastTradedTime (datetime): The time of the last trade.
|
55
|
+
LastUpdateTime (datetime): The time of the last update.
|
56
|
+
PercentChange (Decimal): The percentage change in price.
|
57
|
+
Open (Decimal): The opening price.
|
58
|
+
High (Decimal): The highest price.
|
59
|
+
Low (Decimal): The lowest price.
|
60
|
+
Close (Decimal): The closing price.
|
61
|
+
TotalValueTraded (int): The total value of traded orders.
|
62
|
+
BuyBackTotalBuy (int): The total quantity of buy-back orders.
|
63
|
+
BuyBackTotalSell (int): The total quantity of sell-back orders.
|
64
|
+
"""
|
65
|
+
|
66
|
+
BidInfo: BidAskInfo
|
67
|
+
AskInfo: BidAskInfo
|
68
|
+
LastTradedPrice: Decimal
|
69
|
+
LastTradedQunatity: int
|
70
|
+
TotalBuyQuantity: int
|
71
|
+
TotalSellQuantity: int
|
72
|
+
TotalTradedQuantity: int
|
73
|
+
AverageTradedPrice: Decimal
|
74
|
+
LastTradedTime: Annotated[datetime, BeforeValidator(parse_datetime)]
|
75
|
+
LastUpdateTime: Annotated[datetime, BeforeValidator(parse_datetime)]
|
76
|
+
PercentChange: Decimal
|
77
|
+
Open: Decimal
|
78
|
+
High: Decimal
|
79
|
+
Low: Decimal
|
80
|
+
Close: Decimal
|
81
|
+
TotalValueTraded: int
|
82
|
+
BuyBackTotalBuy: int
|
83
|
+
BuyBackTotalSell: int
|
84
|
+
|
85
|
+
|
86
|
+
class MarketDepthData(BaseModel):
|
87
|
+
"""
|
88
|
+
MarketDepthData represents the market depth information for a specific instrument.
|
89
|
+
Attributes:
|
90
|
+
MessageCode (int): The code representing the type of message.
|
91
|
+
MessageVersion (int): The version of the message format.
|
92
|
+
ApplicationType (int): The type of application sending the message.
|
93
|
+
TokenID (int): The unique identifier for the token.
|
94
|
+
ExchangeSegment (int): The segment of the exchange.
|
95
|
+
ExchangeInstrumentID (int): The unique identifier for the instrument on the exchange.
|
96
|
+
ExchangeTimeStamp (datetime): The timestamp of the data from the exchange.
|
97
|
+
Bids (list[BidAskInfo]): A list of bid information.
|
98
|
+
Asks (list[BidAskInfo]): A list of ask information.
|
99
|
+
Touchline (TouchlineInfo): The touchline information.
|
100
|
+
BookType (int): The type of order book.
|
101
|
+
XMarketType (int): The type of market.
|
102
|
+
SequenceNumber (int): The sequence number of the message.
|
103
|
+
"""
|
104
|
+
|
105
|
+
MessageCode: int
|
106
|
+
MessageVersion: int
|
107
|
+
ApplicationType: int
|
108
|
+
TokenID: int
|
109
|
+
ExchangeSegment: int
|
110
|
+
ExchangeInstrumentID: int
|
111
|
+
ExchangeTimeStamp: Annotated[datetime, BeforeValidator(parse_datetime)]
|
112
|
+
Bids: list[BidAskInfo]
|
113
|
+
Asks: list[BidAskInfo]
|
114
|
+
Touchline: TouchlineInfo
|
115
|
+
BookType: int
|
116
|
+
XMarketType: int
|
117
|
+
SequenceNumber: int
|
118
|
+
|
119
|
+
def __init__(self, input_data: Any):
|
120
|
+
if isinstance(input_data, dict):
|
121
|
+
super().__init__(**input_data)
|
122
|
+
elif isinstance(input_data, str):
|
123
|
+
data = json.loads(input_data)
|
124
|
+
super().__init__(**data)
|
125
|
+
else:
|
126
|
+
raise ValueError("Unsupported input type for MarketDepthData")
|
@@ -0,0 +1,110 @@
|
|
1
|
+
from pydantic import BaseModel, BeforeValidator
|
2
|
+
from typing_extensions import Annotated
|
3
|
+
from decimal import Decimal
|
4
|
+
from datetime import datetime, timedelta
|
5
|
+
import json
|
6
|
+
from typing import Any, Dict
|
7
|
+
from enum import Enum
|
8
|
+
|
9
|
+
|
10
|
+
def parse_datetime(value) -> Any:
|
11
|
+
"""
|
12
|
+
Parses the given value into a datetime object if it is an integer.
|
13
|
+
If the value is an integer, it is interpreted as the number of seconds since January 1, 1980.
|
14
|
+
The function returns a datetime object representing that date and time.
|
15
|
+
If the value is not an integer, it is returned as-is.
|
16
|
+
Args:
|
17
|
+
value (Any): The value to be parsed. Expected to be an integer representing seconds since January 1, 1980, or any other type.
|
18
|
+
Returns:
|
19
|
+
Any: A datetime object if the input is an integer, otherwise the input value unchanged.
|
20
|
+
"""
|
21
|
+
|
22
|
+
if isinstance(value, int):
|
23
|
+
return datetime(1980, 1, 1) + timedelta(seconds=value)
|
24
|
+
return value
|
25
|
+
|
26
|
+
|
27
|
+
class ExchangeTradingSession(Enum):
|
28
|
+
"""
|
29
|
+
Enum class representing different stages of an exchange trading session.
|
30
|
+
Attributes:
|
31
|
+
PreOpenStart (int): Represents the start of the pre-open session.
|
32
|
+
PreOpenEnd (int): Represents the end of the pre-open session.
|
33
|
+
NormalStart (int): Represents the start of the normal trading session.
|
34
|
+
NormalEnd (int): Represents the end of the normal trading session.
|
35
|
+
PreClosingStart (int): Represents the start of the pre-closing session.
|
36
|
+
PreClosingEnd (int): Represents the end of the pre-closing session.
|
37
|
+
"""
|
38
|
+
|
39
|
+
PreOpenStart = 0
|
40
|
+
PreOpenEnd = 1
|
41
|
+
NormalStart = 2
|
42
|
+
NormalEnd = 4
|
43
|
+
PreClosingStart = 8
|
44
|
+
PreClosingEnd = 16
|
45
|
+
|
46
|
+
|
47
|
+
class ExchangeMarketType(Enum):
|
48
|
+
"""
|
49
|
+
Enum class representing different types of exchange market statuses.
|
50
|
+
Attributes:
|
51
|
+
Normal (int): Represents a normal market type.
|
52
|
+
OddLot (int): Represents an odd lot market type.
|
53
|
+
Spot (int): Represents a spot market type.
|
54
|
+
Auction (int): Represents an auction market type.
|
55
|
+
CallAuction1 (int): Represents the first call auction market type.
|
56
|
+
CallAuction2 (int): Represents the second call auction market type.
|
57
|
+
"""
|
58
|
+
|
59
|
+
Normal = 1
|
60
|
+
OddLot = 2
|
61
|
+
Spot = 3
|
62
|
+
Auction = 4
|
63
|
+
CallAuction1 = 5
|
64
|
+
CallAuction2 = 6
|
65
|
+
|
66
|
+
|
67
|
+
class MarketStatusData(BaseModel):
|
68
|
+
"""
|
69
|
+
MarketStatusData is a data model representing the status of a market.
|
70
|
+
Attributes:
|
71
|
+
ApplicationType (int): The type of application.
|
72
|
+
ExchangeInstrumentID (int): The ID of the exchange instrument.
|
73
|
+
ExchangeSegment (int): The segment of the exchange.
|
74
|
+
ExchangeTimeStamp (datetime): The timestamp of the exchange, validated and parsed.
|
75
|
+
maketType (ExchangeMarketType): The type of market.
|
76
|
+
message (str): The message content.
|
77
|
+
MessageCode (int): The code of the message.
|
78
|
+
MessageVersion (int): The version of the message.
|
79
|
+
SequenceNumber (int): The sequence number.
|
80
|
+
TokenID (int): The token ID.
|
81
|
+
tradingSession (ExchangeTradingSession): The trading session.
|
82
|
+
Methods:
|
83
|
+
from_string(cls, message: str): Class method to create an instance of MarketStatusData from a JSON string.
|
84
|
+
"""
|
85
|
+
|
86
|
+
ApplicationType: int
|
87
|
+
ExchangeInstrumentID: int
|
88
|
+
ExchangeSegment: int
|
89
|
+
ExchangeTimeStamp: Annotated[datetime, BeforeValidator(parse_datetime)]
|
90
|
+
maketType: ExchangeMarketType
|
91
|
+
message: str
|
92
|
+
MessageCode: int
|
93
|
+
MessageVersion: int
|
94
|
+
SequenceNumber: int
|
95
|
+
TokenID: int
|
96
|
+
tradingSession: ExchangeTradingSession
|
97
|
+
|
98
|
+
class Config:
|
99
|
+
use_enum_values = True
|
100
|
+
|
101
|
+
def __init__(self, input_data: Any):
|
102
|
+
if isinstance(input_data, dict):
|
103
|
+
|
104
|
+
super().__init__(**input_data)
|
105
|
+
elif isinstance(input_data, str):
|
106
|
+
|
107
|
+
data = json.loads(input_data)
|
108
|
+
super().__init__(**data)
|
109
|
+
else:
|
110
|
+
raise ValueError("Unsupported input type for MarketStatusData")
|
@@ -0,0 +1,84 @@
|
|
1
|
+
from pydantic import BaseModel, BeforeValidator
|
2
|
+
from typing_extensions import Annotated
|
3
|
+
from decimal import Decimal
|
4
|
+
from datetime import datetime, timedelta
|
5
|
+
import json
|
6
|
+
from typing import Any, Dict
|
7
|
+
from enum import Enum
|
8
|
+
|
9
|
+
|
10
|
+
def parse_datetime(value) -> Any:
|
11
|
+
"""
|
12
|
+
Parses the given value into a datetime object if it is an integer.
|
13
|
+
If the value is an integer, it is interpreted as the number of seconds since January 1, 1980.
|
14
|
+
The function returns a datetime object representing that date and time.
|
15
|
+
If the value is not an integer, it is returned as-is.
|
16
|
+
Args:
|
17
|
+
value (Any): The value to be parsed. Expected to be an integer representing seconds since January 1, 1980, or any other type.
|
18
|
+
Returns:
|
19
|
+
Any: A datetime object if the input is an integer, otherwise the input value unchanged.
|
20
|
+
"""
|
21
|
+
|
22
|
+
if isinstance(value, int):
|
23
|
+
return datetime(1980, 1, 1) + timedelta(seconds=value)
|
24
|
+
return value
|
25
|
+
|
26
|
+
|
27
|
+
class ExchangeMarketType(Enum):
|
28
|
+
"""
|
29
|
+
Enum class representing different types of exchange market statuses.
|
30
|
+
Attributes:
|
31
|
+
Normal (int): Represents a normal market type.
|
32
|
+
OddLot (int): Represents an odd lot market type.
|
33
|
+
Spot (int): Represents a spot market type.
|
34
|
+
Auction (int): Represents an auction market type.
|
35
|
+
CallAuction1 (int): Represents the first call auction market type.
|
36
|
+
CallAuction2 (int): Represents the second call auction market type.
|
37
|
+
"""
|
38
|
+
|
39
|
+
Normal = 1
|
40
|
+
OddLot = 2
|
41
|
+
Spot = 3
|
42
|
+
Auction = 4
|
43
|
+
CallAuction1 = 5
|
44
|
+
CallAuction2 = 6
|
45
|
+
|
46
|
+
|
47
|
+
class OpenInterestData(BaseModel):
|
48
|
+
"""
|
49
|
+
OpenInterestData model representing the structure of open interest data.
|
50
|
+
Attributes:
|
51
|
+
MessageCode (int): The message code.
|
52
|
+
MessageVersion (int): The version of the message.
|
53
|
+
ApplicationType (int): The type of application.
|
54
|
+
TokenID (int): The token ID.
|
55
|
+
ExchangeSegment (int): The exchange segment.
|
56
|
+
ExchangeInstrumentID (int): The exchange instrument ID.
|
57
|
+
ExchangeTimeStamp (datetime): The timestamp of the exchange, validated and parsed.
|
58
|
+
XTSMarketType (ExchangeMarketType): The market type of the exchange.
|
59
|
+
OpenInterest (int): The open interest value.
|
60
|
+
Methods:
|
61
|
+
from_string(cls, message: str): Class method to create an instance of OpenInterestData from a JSON string.
|
62
|
+
"""
|
63
|
+
|
64
|
+
MessageCode: int
|
65
|
+
MessageVersion: int
|
66
|
+
ApplicationType: int
|
67
|
+
TokenID: int
|
68
|
+
ExchangeSegment: int
|
69
|
+
ExchangeInstrumentID: int
|
70
|
+
ExchangeTimeStamp: Annotated[datetime, BeforeValidator(parse_datetime)]
|
71
|
+
XTSMarketType: ExchangeMarketType
|
72
|
+
OpenInterest: int
|
73
|
+
|
74
|
+
class Config:
|
75
|
+
use_enum_values = True
|
76
|
+
|
77
|
+
def __init__(self, input_data: Any):
|
78
|
+
if isinstance(input_data, dict):
|
79
|
+
super().__init__(**input_data)
|
80
|
+
elif isinstance(input_data, str):
|
81
|
+
data = json.loads(input_data)
|
82
|
+
super().__init__(**data)
|
83
|
+
else:
|
84
|
+
raise ValueError("Unsupported input type for OpenInterestData")
|
@@ -0,0 +1,47 @@
|
|
1
|
+
from pydantic import BaseModel, BeforeValidator
|
2
|
+
from typing_extensions import Annotated
|
3
|
+
from decimal import Decimal
|
4
|
+
from datetime import datetime, timedelta
|
5
|
+
import json
|
6
|
+
from typing import Any, Dict
|
7
|
+
|
8
|
+
|
9
|
+
class OpenInterestPartialData(BaseModel):
|
10
|
+
"""
|
11
|
+
A class to represent partial data of open interest.
|
12
|
+
Attributes:
|
13
|
+
-----------
|
14
|
+
ExchangeSegment : int
|
15
|
+
The segment of the exchange.
|
16
|
+
ExchangeInstrumentID : int
|
17
|
+
The instrument ID of the exchange.
|
18
|
+
OpenInterest : int
|
19
|
+
The open interest value.
|
20
|
+
Methods:
|
21
|
+
--------
|
22
|
+
from_string(cls, message: str):
|
23
|
+
Parses a string message to create an instance of OpenInterestPartialData.
|
24
|
+
The message should be in the format "t:exchange_segment_instrument_id,o:open_interest".
|
25
|
+
"""
|
26
|
+
|
27
|
+
ExchangeSegment: int
|
28
|
+
ExchangeInstrumentID: int
|
29
|
+
OpenInterest: int
|
30
|
+
|
31
|
+
def __init__(self, input_data: Any):
|
32
|
+
if isinstance(input_data, dict):
|
33
|
+
super().__init__(**input_data)
|
34
|
+
elif isinstance(input_data, str):
|
35
|
+
parts = input_data.split(",")
|
36
|
+
data = {}
|
37
|
+
for part in parts:
|
38
|
+
key, value = part.split(":")
|
39
|
+
if key == "t":
|
40
|
+
exchange_segment, instrument_id = value.split("_")
|
41
|
+
data["ExchangeSegment"] = int(exchange_segment)
|
42
|
+
data["ExchangeInstrumentID"] = int(instrument_id)
|
43
|
+
elif key == "o":
|
44
|
+
data["OpenInterest"] = int(value)
|
45
|
+
super().__init__(**data)
|
46
|
+
else:
|
47
|
+
raise ValueError("Unsupported input type for OpenInterestPartialData")
|