kalshi-python-async 3.0.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.
- kalshi_python_async/__init__.py +272 -0
- kalshi_python_async/api/__init__.py +19 -0
- kalshi_python_async/api/api_keys_api.py +1098 -0
- kalshi_python_async/api/communications_api.py +3216 -0
- kalshi_python_async/api/events_api.py +1941 -0
- kalshi_python_async/api/exchange_api.py +1263 -0
- kalshi_python_async/api/fcm_api.py +792 -0
- kalshi_python_async/api/incentive_programs_api.py +346 -0
- kalshi_python_async/api/live_data_api.py +564 -0
- kalshi_python_async/api/market_api.py +2568 -0
- kalshi_python_async/api/milestone_api.py +689 -0
- kalshi_python_async/api/multivariate_api.py +1486 -0
- kalshi_python_async/api/order_groups_api.py +1375 -0
- kalshi_python_async/api/orders_api.py +2913 -0
- kalshi_python_async/api/portfolio_api.py +1572 -0
- kalshi_python_async/api/search_api.py +516 -0
- kalshi_python_async/api/structured_targets_api.py +605 -0
- kalshi_python_async/api_client.py +833 -0
- kalshi_python_async/api_response.py +21 -0
- kalshi_python_async/auth.py +89 -0
- kalshi_python_async/configuration.py +622 -0
- kalshi_python_async/exceptions.py +216 -0
- kalshi_python_async/models/__init__.py +136 -0
- kalshi_python_async/models/accept_quote_request.py +94 -0
- kalshi_python_async/models/amend_order_request.py +120 -0
- kalshi_python_async/models/amend_order_response.py +96 -0
- kalshi_python_async/models/announcement.py +108 -0
- kalshi_python_async/models/api_key.py +89 -0
- kalshi_python_async/models/associated_event.py +105 -0
- kalshi_python_async/models/batch_cancel_orders_individual_response.py +111 -0
- kalshi_python_async/models/batch_cancel_orders_request.py +87 -0
- kalshi_python_async/models/batch_cancel_orders_response.py +95 -0
- kalshi_python_async/models/batch_create_orders_individual_response.py +114 -0
- kalshi_python_async/models/batch_create_orders_request.py +95 -0
- kalshi_python_async/models/batch_create_orders_response.py +95 -0
- kalshi_python_async/models/batch_get_market_candlesticks_response.py +95 -0
- kalshi_python_async/models/bid_ask_distribution.py +101 -0
- kalshi_python_async/models/cancel_order_response.py +93 -0
- kalshi_python_async/models/create_api_key_request.py +89 -0
- kalshi_python_async/models/create_api_key_response.py +87 -0
- kalshi_python_async/models/create_market_in_multivariate_event_collection_request.py +95 -0
- kalshi_python_async/models/create_market_in_multivariate_event_collection_response.py +89 -0
- kalshi_python_async/models/create_order_group_request.py +88 -0
- kalshi_python_async/models/create_order_group_response.py +87 -0
- kalshi_python_async/models/create_order_request.py +159 -0
- kalshi_python_async/models/create_order_response.py +91 -0
- kalshi_python_async/models/create_quote_request.py +93 -0
- kalshi_python_async/models/create_quote_response.py +87 -0
- kalshi_python_async/models/create_rfq_request.py +97 -0
- kalshi_python_async/models/create_rfq_response.py +87 -0
- kalshi_python_async/models/daily_schedule.py +89 -0
- kalshi_python_async/models/decrease_order_request.py +90 -0
- kalshi_python_async/models/decrease_order_response.py +91 -0
- kalshi_python_async/models/error_response.py +93 -0
- kalshi_python_async/models/event_data.py +133 -0
- kalshi_python_async/models/event_position.py +105 -0
- kalshi_python_async/models/exchange_status.py +97 -0
- kalshi_python_async/models/fill.py +134 -0
- kalshi_python_async/models/forecast_percentiles_point.py +101 -0
- kalshi_python_async/models/generate_api_key_request.py +87 -0
- kalshi_python_async/models/generate_api_key_response.py +89 -0
- kalshi_python_async/models/get_api_keys_response.py +95 -0
- kalshi_python_async/models/get_balance_response.py +91 -0
- kalshi_python_async/models/get_communications_id_response.py +87 -0
- kalshi_python_async/models/get_event_candlesticks_response.py +104 -0
- kalshi_python_async/models/get_event_forecast_percentiles_history_response.py +95 -0
- kalshi_python_async/models/get_event_metadata_response.py +123 -0
- kalshi_python_async/models/get_event_response.py +101 -0
- kalshi_python_async/models/get_events_candlesticks_response.py +95 -0
- kalshi_python_async/models/get_events_candlesticks_response_events_inner.py +106 -0
- kalshi_python_async/models/get_events_response.py +107 -0
- kalshi_python_async/models/get_exchange_announcements_response.py +95 -0
- kalshi_python_async/models/get_exchange_schedule_response.py +91 -0
- kalshi_python_async/models/get_fills_response.py +97 -0
- kalshi_python_async/models/get_filters_by_sports_response.py +102 -0
- kalshi_python_async/models/get_incentive_programs_response.py +97 -0
- kalshi_python_async/models/get_live_data_response.py +91 -0
- kalshi_python_async/models/get_live_datas_response.py +95 -0
- kalshi_python_async/models/get_market_candlesticks_response.py +97 -0
- kalshi_python_async/models/get_market_orderbook_response.py +91 -0
- kalshi_python_async/models/get_market_response.py +91 -0
- kalshi_python_async/models/get_markets_response.py +97 -0
- kalshi_python_async/models/get_milestone_response.py +91 -0
- kalshi_python_async/models/get_milestones_response.py +97 -0
- kalshi_python_async/models/get_multivariate_event_collection_lookup_history_response.py +95 -0
- kalshi_python_async/models/get_multivariate_event_collection_response.py +91 -0
- kalshi_python_async/models/get_multivariate_event_collections_response.py +97 -0
- kalshi_python_async/models/get_multivariate_events_response.py +97 -0
- kalshi_python_async/models/get_order_group_response.py +89 -0
- kalshi_python_async/models/get_order_groups_response.py +95 -0
- kalshi_python_async/models/get_order_queue_position_response.py +87 -0
- kalshi_python_async/models/get_order_queue_positions_response.py +95 -0
- kalshi_python_async/models/get_order_response.py +91 -0
- kalshi_python_async/models/get_orders_response.py +97 -0
- kalshi_python_async/models/get_portfolio_resting_order_total_value_response.py +87 -0
- kalshi_python_async/models/get_positions_response.py +107 -0
- kalshi_python_async/models/get_quote_response.py +91 -0
- kalshi_python_async/models/get_quotes_response.py +97 -0
- kalshi_python_async/models/get_rfq_response.py +91 -0
- kalshi_python_async/models/get_rfqs_response.py +97 -0
- kalshi_python_async/models/get_series_fee_changes_response.py +95 -0
- kalshi_python_async/models/get_series_list_response.py +95 -0
- kalshi_python_async/models/get_series_response.py +91 -0
- kalshi_python_async/models/get_settlements_response.py +97 -0
- kalshi_python_async/models/get_structured_target_response.py +91 -0
- kalshi_python_async/models/get_structured_targets_response.py +97 -0
- kalshi_python_async/models/get_tags_for_series_categories_response.py +87 -0
- kalshi_python_async/models/get_trades_response.py +97 -0
- kalshi_python_async/models/get_user_data_timestamp_response.py +88 -0
- kalshi_python_async/models/incentive_program.py +121 -0
- kalshi_python_async/models/live_data.py +91 -0
- kalshi_python_async/models/lookup_point.py +102 -0
- kalshi_python_async/models/lookup_tickers_for_market_in_multivariate_event_collection_request.py +95 -0
- kalshi_python_async/models/lookup_tickers_for_market_in_multivariate_event_collection_response.py +89 -0
- kalshi_python_async/models/maintenance_window.py +90 -0
- kalshi_python_async/models/market.py +307 -0
- kalshi_python_async/models/market_candlestick.py +108 -0
- kalshi_python_async/models/market_candlesticks_response.py +97 -0
- kalshi_python_async/models/market_metadata.py +91 -0
- kalshi_python_async/models/market_position.py +110 -0
- kalshi_python_async/models/milestone.py +120 -0
- kalshi_python_async/models/multivariate_event_collection.py +122 -0
- kalshi_python_async/models/mve_selected_leg.py +91 -0
- kalshi_python_async/models/order.py +189 -0
- kalshi_python_async/models/order_group.py +89 -0
- kalshi_python_async/models/order_queue_position.py +91 -0
- kalshi_python_async/models/order_status.py +38 -0
- kalshi_python_async/models/orderbook.py +94 -0
- kalshi_python_async/models/percentile_point.py +93 -0
- kalshi_python_async/models/price_distribution.py +157 -0
- kalshi_python_async/models/price_range.py +91 -0
- kalshi_python_async/models/quote.py +153 -0
- kalshi_python_async/models/rfq.py +129 -0
- kalshi_python_async/models/schedule.py +105 -0
- kalshi_python_async/models/scope_list.py +87 -0
- kalshi_python_async/models/self_trade_prevention_type.py +37 -0
- kalshi_python_async/models/series.py +129 -0
- kalshi_python_async/models/series_fee_change.py +103 -0
- kalshi_python_async/models/settlement.py +118 -0
- kalshi_python_async/models/settlement_source.py +89 -0
- kalshi_python_async/models/sport_filter_details.py +102 -0
- kalshi_python_async/models/structured_target.py +98 -0
- kalshi_python_async/models/ticker_pair.py +98 -0
- kalshi_python_async/models/trade.py +113 -0
- kalshi_python_async/models/weekly_schedule.py +154 -0
- kalshi_python_async/py.typed +0 -0
- kalshi_python_async/rest.py +213 -0
- kalshi_python_async-3.0.0.dist-info/METADATA +78 -0
- kalshi_python_async-3.0.0.dist-info/RECORD +151 -0
- kalshi_python_async-3.0.0.dist-info/WHEEL +5 -0
- kalshi_python_async-3.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Kalshi Trade API Manual Endpoints
|
|
5
|
+
|
|
6
|
+
Manually defined OpenAPI spec for endpoints being migrated to spec-first approach
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictStr
|
|
22
|
+
from typing import Any, ClassVar, Dict, List, Optional
|
|
23
|
+
from typing import Optional, Set
|
|
24
|
+
from typing_extensions import Self
|
|
25
|
+
|
|
26
|
+
class StructuredTarget(BaseModel):
|
|
27
|
+
"""
|
|
28
|
+
StructuredTarget
|
|
29
|
+
""" # noqa: E501
|
|
30
|
+
id: Optional[StrictStr] = Field(default=None, description="Unique identifier for the structured target.")
|
|
31
|
+
name: Optional[StrictStr] = Field(default=None, description="Name of the structured target.")
|
|
32
|
+
type: Optional[StrictStr] = Field(default=None, description="Type of the structured target.")
|
|
33
|
+
details: Optional[Dict[str, Any]] = Field(default=None, description="Additional details about the structured target. Contains flexible JSON data specific to the target type.")
|
|
34
|
+
source_id: Optional[StrictStr] = Field(default=None, description="External source identifier for the structured target, if available (e.g., third-party data provider ID).")
|
|
35
|
+
last_updated_ts: Optional[datetime] = Field(default=None, description="Timestamp when this structured target was last updated.")
|
|
36
|
+
__properties: ClassVar[List[str]] = ["id", "name", "type", "details", "source_id", "last_updated_ts"]
|
|
37
|
+
|
|
38
|
+
model_config = ConfigDict(
|
|
39
|
+
populate_by_name=True,
|
|
40
|
+
validate_assignment=True,
|
|
41
|
+
protected_namespaces=(),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def to_str(self) -> str:
|
|
46
|
+
"""Returns the string representation of the model using alias"""
|
|
47
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
48
|
+
|
|
49
|
+
def to_json(self) -> str:
|
|
50
|
+
"""Returns the JSON representation of the model using alias"""
|
|
51
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
52
|
+
return json.dumps(self.to_dict())
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
56
|
+
"""Create an instance of StructuredTarget from a JSON string"""
|
|
57
|
+
return cls.from_dict(json.loads(json_str))
|
|
58
|
+
|
|
59
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
60
|
+
"""Return the dictionary representation of the model using alias.
|
|
61
|
+
|
|
62
|
+
This has the following differences from calling pydantic's
|
|
63
|
+
`self.model_dump(by_alias=True)`:
|
|
64
|
+
|
|
65
|
+
* `None` is only added to the output dict for nullable fields that
|
|
66
|
+
were set at model initialization. Other fields with value `None`
|
|
67
|
+
are ignored.
|
|
68
|
+
"""
|
|
69
|
+
excluded_fields: Set[str] = set([
|
|
70
|
+
])
|
|
71
|
+
|
|
72
|
+
_dict = self.model_dump(
|
|
73
|
+
by_alias=True,
|
|
74
|
+
exclude=excluded_fields,
|
|
75
|
+
exclude_none=True,
|
|
76
|
+
)
|
|
77
|
+
return _dict
|
|
78
|
+
|
|
79
|
+
@classmethod
|
|
80
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
81
|
+
"""Create an instance of StructuredTarget from a dict"""
|
|
82
|
+
if obj is None:
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
if not isinstance(obj, dict):
|
|
86
|
+
return cls.model_validate(obj)
|
|
87
|
+
|
|
88
|
+
_obj = cls.model_validate({
|
|
89
|
+
"id": obj.get("id"),
|
|
90
|
+
"name": obj.get("name"),
|
|
91
|
+
"type": obj.get("type"),
|
|
92
|
+
"details": obj.get("details"),
|
|
93
|
+
"source_id": obj.get("source_id"),
|
|
94
|
+
"last_updated_ts": obj.get("last_updated_ts")
|
|
95
|
+
})
|
|
96
|
+
return _obj
|
|
97
|
+
|
|
98
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Kalshi Trade API Manual Endpoints
|
|
5
|
+
|
|
6
|
+
Manually defined OpenAPI spec for endpoints being migrated to spec-first approach
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator
|
|
21
|
+
from typing import Any, ClassVar, Dict, List
|
|
22
|
+
from typing import Optional, Set
|
|
23
|
+
from typing_extensions import Self
|
|
24
|
+
|
|
25
|
+
class TickerPair(BaseModel):
|
|
26
|
+
"""
|
|
27
|
+
TickerPair
|
|
28
|
+
""" # noqa: E501
|
|
29
|
+
market_ticker: StrictStr = Field(description="Market ticker identifier.")
|
|
30
|
+
event_ticker: StrictStr = Field(description="Event ticker identifier.")
|
|
31
|
+
side: StrictStr = Field(description="Side of the market (yes or no).")
|
|
32
|
+
__properties: ClassVar[List[str]] = ["market_ticker", "event_ticker", "side"]
|
|
33
|
+
|
|
34
|
+
@field_validator('side')
|
|
35
|
+
def side_validate_enum(cls, value):
|
|
36
|
+
"""Validates the enum"""
|
|
37
|
+
if value not in set(['true', 'false']):
|
|
38
|
+
raise ValueError("must be one of enum values ('true', 'false')")
|
|
39
|
+
return value
|
|
40
|
+
|
|
41
|
+
model_config = ConfigDict(
|
|
42
|
+
populate_by_name=True,
|
|
43
|
+
validate_assignment=True,
|
|
44
|
+
protected_namespaces=(),
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def to_str(self) -> str:
|
|
49
|
+
"""Returns the string representation of the model using alias"""
|
|
50
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
51
|
+
|
|
52
|
+
def to_json(self) -> str:
|
|
53
|
+
"""Returns the JSON representation of the model using alias"""
|
|
54
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
55
|
+
return json.dumps(self.to_dict())
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
59
|
+
"""Create an instance of TickerPair from a JSON string"""
|
|
60
|
+
return cls.from_dict(json.loads(json_str))
|
|
61
|
+
|
|
62
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
63
|
+
"""Return the dictionary representation of the model using alias.
|
|
64
|
+
|
|
65
|
+
This has the following differences from calling pydantic's
|
|
66
|
+
`self.model_dump(by_alias=True)`:
|
|
67
|
+
|
|
68
|
+
* `None` is only added to the output dict for nullable fields that
|
|
69
|
+
were set at model initialization. Other fields with value `None`
|
|
70
|
+
are ignored.
|
|
71
|
+
"""
|
|
72
|
+
excluded_fields: Set[str] = set([
|
|
73
|
+
])
|
|
74
|
+
|
|
75
|
+
_dict = self.model_dump(
|
|
76
|
+
by_alias=True,
|
|
77
|
+
exclude=excluded_fields,
|
|
78
|
+
exclude_none=True,
|
|
79
|
+
)
|
|
80
|
+
return _dict
|
|
81
|
+
|
|
82
|
+
@classmethod
|
|
83
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
84
|
+
"""Create an instance of TickerPair from a dict"""
|
|
85
|
+
if obj is None:
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
if not isinstance(obj, dict):
|
|
89
|
+
return cls.model_validate(obj)
|
|
90
|
+
|
|
91
|
+
_obj = cls.model_validate({
|
|
92
|
+
"market_ticker": obj.get("market_ticker"),
|
|
93
|
+
"event_ticker": obj.get("event_ticker"),
|
|
94
|
+
"side": obj.get("side")
|
|
95
|
+
})
|
|
96
|
+
return _obj
|
|
97
|
+
|
|
98
|
+
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Kalshi Trade API Manual Endpoints
|
|
5
|
+
|
|
6
|
+
Manually defined OpenAPI spec for endpoints being migrated to spec-first approach
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, StrictStr, field_validator
|
|
22
|
+
from typing import Any, ClassVar, Dict, List, Optional, Union
|
|
23
|
+
from typing import Optional, Set
|
|
24
|
+
from typing_extensions import Self
|
|
25
|
+
|
|
26
|
+
class Trade(BaseModel):
|
|
27
|
+
"""
|
|
28
|
+
Trade
|
|
29
|
+
""" # noqa: E501
|
|
30
|
+
trade_id: StrictStr = Field(description="Unique identifier for this trade")
|
|
31
|
+
ticker: StrictStr = Field(description="Unique identifier for the market")
|
|
32
|
+
price: Union[StrictFloat, StrictInt] = Field(description="Trade price (deprecated - use yes_price or no_price)")
|
|
33
|
+
count: StrictInt = Field(description="Number of contracts bought or sold in this trade")
|
|
34
|
+
yes_price: StrictInt = Field(description="Yes price for this trade in cents")
|
|
35
|
+
no_price: StrictInt = Field(description="No price for this trade in cents")
|
|
36
|
+
yes_price_dollars: StrictStr = Field(description="US dollar amount as a fixed-point decimal string with exactly 4 decimal places")
|
|
37
|
+
no_price_dollars: StrictStr = Field(description="US dollar amount as a fixed-point decimal string with exactly 4 decimal places")
|
|
38
|
+
taker_side: StrictStr = Field(description="Side for the taker of this trade")
|
|
39
|
+
created_time: Optional[datetime] = Field(default=None, description="Timestamp when this trade was executed")
|
|
40
|
+
__properties: ClassVar[List[str]] = ["trade_id", "ticker", "price", "count", "yes_price", "no_price", "yes_price_dollars", "no_price_dollars", "taker_side", "created_time"]
|
|
41
|
+
|
|
42
|
+
@field_validator('taker_side')
|
|
43
|
+
def taker_side_validate_enum(cls, value):
|
|
44
|
+
"""Validates the enum"""
|
|
45
|
+
if value not in set(['yes', 'no']):
|
|
46
|
+
raise ValueError("must be one of enum values ('yes', 'no')")
|
|
47
|
+
return value
|
|
48
|
+
|
|
49
|
+
model_config = ConfigDict(
|
|
50
|
+
populate_by_name=True,
|
|
51
|
+
validate_assignment=True,
|
|
52
|
+
protected_namespaces=(),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def to_str(self) -> str:
|
|
57
|
+
"""Returns the string representation of the model using alias"""
|
|
58
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
59
|
+
|
|
60
|
+
def to_json(self) -> str:
|
|
61
|
+
"""Returns the JSON representation of the model using alias"""
|
|
62
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
63
|
+
return json.dumps(self.to_dict())
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
67
|
+
"""Create an instance of Trade from a JSON string"""
|
|
68
|
+
return cls.from_dict(json.loads(json_str))
|
|
69
|
+
|
|
70
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
71
|
+
"""Return the dictionary representation of the model using alias.
|
|
72
|
+
|
|
73
|
+
This has the following differences from calling pydantic's
|
|
74
|
+
`self.model_dump(by_alias=True)`:
|
|
75
|
+
|
|
76
|
+
* `None` is only added to the output dict for nullable fields that
|
|
77
|
+
were set at model initialization. Other fields with value `None`
|
|
78
|
+
are ignored.
|
|
79
|
+
"""
|
|
80
|
+
excluded_fields: Set[str] = set([
|
|
81
|
+
])
|
|
82
|
+
|
|
83
|
+
_dict = self.model_dump(
|
|
84
|
+
by_alias=True,
|
|
85
|
+
exclude=excluded_fields,
|
|
86
|
+
exclude_none=True,
|
|
87
|
+
)
|
|
88
|
+
return _dict
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
92
|
+
"""Create an instance of Trade from a dict"""
|
|
93
|
+
if obj is None:
|
|
94
|
+
return None
|
|
95
|
+
|
|
96
|
+
if not isinstance(obj, dict):
|
|
97
|
+
return cls.model_validate(obj)
|
|
98
|
+
|
|
99
|
+
_obj = cls.model_validate({
|
|
100
|
+
"trade_id": obj.get("trade_id"),
|
|
101
|
+
"ticker": obj.get("ticker"),
|
|
102
|
+
"price": obj.get("price"),
|
|
103
|
+
"count": obj.get("count"),
|
|
104
|
+
"yes_price": obj.get("yes_price"),
|
|
105
|
+
"no_price": obj.get("no_price"),
|
|
106
|
+
"yes_price_dollars": obj.get("yes_price_dollars"),
|
|
107
|
+
"no_price_dollars": obj.get("no_price_dollars"),
|
|
108
|
+
"taker_side": obj.get("taker_side"),
|
|
109
|
+
"created_time": obj.get("created_time")
|
|
110
|
+
})
|
|
111
|
+
return _obj
|
|
112
|
+
|
|
113
|
+
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Kalshi Trade API Manual Endpoints
|
|
5
|
+
|
|
6
|
+
Manually defined OpenAPI spec for endpoints being migrated to spec-first approach
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
import pprint
|
|
17
|
+
import re # noqa: F401
|
|
18
|
+
import json
|
|
19
|
+
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
22
|
+
from typing import Any, ClassVar, Dict, List
|
|
23
|
+
from kalshi_python_async.models.daily_schedule import DailySchedule
|
|
24
|
+
from typing import Optional, Set
|
|
25
|
+
from typing_extensions import Self
|
|
26
|
+
|
|
27
|
+
class WeeklySchedule(BaseModel):
|
|
28
|
+
"""
|
|
29
|
+
WeeklySchedule
|
|
30
|
+
""" # noqa: E501
|
|
31
|
+
start_time: datetime = Field(description="Start date and time for when this weekly schedule is effective.")
|
|
32
|
+
end_time: datetime = Field(description="End date and time for when this weekly schedule is no longer effective.")
|
|
33
|
+
monday: List[DailySchedule] = Field(description="Trading hours for Monday. May contain multiple sessions.")
|
|
34
|
+
tuesday: List[DailySchedule] = Field(description="Trading hours for Tuesday. May contain multiple sessions.")
|
|
35
|
+
wednesday: List[DailySchedule] = Field(description="Trading hours for Wednesday. May contain multiple sessions.")
|
|
36
|
+
thursday: List[DailySchedule] = Field(description="Trading hours for Thursday. May contain multiple sessions.")
|
|
37
|
+
friday: List[DailySchedule] = Field(description="Trading hours for Friday. May contain multiple sessions.")
|
|
38
|
+
saturday: List[DailySchedule] = Field(description="Trading hours for Saturday. May contain multiple sessions.")
|
|
39
|
+
sunday: List[DailySchedule] = Field(description="Trading hours for Sunday. May contain multiple sessions.")
|
|
40
|
+
__properties: ClassVar[List[str]] = ["start_time", "end_time", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
|
|
41
|
+
|
|
42
|
+
model_config = ConfigDict(
|
|
43
|
+
populate_by_name=True,
|
|
44
|
+
validate_assignment=True,
|
|
45
|
+
protected_namespaces=(),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def to_str(self) -> str:
|
|
50
|
+
"""Returns the string representation of the model using alias"""
|
|
51
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
52
|
+
|
|
53
|
+
def to_json(self) -> str:
|
|
54
|
+
"""Returns the JSON representation of the model using alias"""
|
|
55
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
56
|
+
return json.dumps(self.to_dict())
|
|
57
|
+
|
|
58
|
+
@classmethod
|
|
59
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
60
|
+
"""Create an instance of WeeklySchedule from a JSON string"""
|
|
61
|
+
return cls.from_dict(json.loads(json_str))
|
|
62
|
+
|
|
63
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
64
|
+
"""Return the dictionary representation of the model using alias.
|
|
65
|
+
|
|
66
|
+
This has the following differences from calling pydantic's
|
|
67
|
+
`self.model_dump(by_alias=True)`:
|
|
68
|
+
|
|
69
|
+
* `None` is only added to the output dict for nullable fields that
|
|
70
|
+
were set at model initialization. Other fields with value `None`
|
|
71
|
+
are ignored.
|
|
72
|
+
"""
|
|
73
|
+
excluded_fields: Set[str] = set([
|
|
74
|
+
])
|
|
75
|
+
|
|
76
|
+
_dict = self.model_dump(
|
|
77
|
+
by_alias=True,
|
|
78
|
+
exclude=excluded_fields,
|
|
79
|
+
exclude_none=True,
|
|
80
|
+
)
|
|
81
|
+
# override the default output from pydantic by calling `to_dict()` of each item in monday (list)
|
|
82
|
+
_items = []
|
|
83
|
+
if self.monday:
|
|
84
|
+
for _item_monday in self.monday:
|
|
85
|
+
if _item_monday:
|
|
86
|
+
_items.append(_item_monday.to_dict())
|
|
87
|
+
_dict['monday'] = _items
|
|
88
|
+
# override the default output from pydantic by calling `to_dict()` of each item in tuesday (list)
|
|
89
|
+
_items = []
|
|
90
|
+
if self.tuesday:
|
|
91
|
+
for _item_tuesday in self.tuesday:
|
|
92
|
+
if _item_tuesday:
|
|
93
|
+
_items.append(_item_tuesday.to_dict())
|
|
94
|
+
_dict['tuesday'] = _items
|
|
95
|
+
# override the default output from pydantic by calling `to_dict()` of each item in wednesday (list)
|
|
96
|
+
_items = []
|
|
97
|
+
if self.wednesday:
|
|
98
|
+
for _item_wednesday in self.wednesday:
|
|
99
|
+
if _item_wednesday:
|
|
100
|
+
_items.append(_item_wednesday.to_dict())
|
|
101
|
+
_dict['wednesday'] = _items
|
|
102
|
+
# override the default output from pydantic by calling `to_dict()` of each item in thursday (list)
|
|
103
|
+
_items = []
|
|
104
|
+
if self.thursday:
|
|
105
|
+
for _item_thursday in self.thursday:
|
|
106
|
+
if _item_thursday:
|
|
107
|
+
_items.append(_item_thursday.to_dict())
|
|
108
|
+
_dict['thursday'] = _items
|
|
109
|
+
# override the default output from pydantic by calling `to_dict()` of each item in friday (list)
|
|
110
|
+
_items = []
|
|
111
|
+
if self.friday:
|
|
112
|
+
for _item_friday in self.friday:
|
|
113
|
+
if _item_friday:
|
|
114
|
+
_items.append(_item_friday.to_dict())
|
|
115
|
+
_dict['friday'] = _items
|
|
116
|
+
# override the default output from pydantic by calling `to_dict()` of each item in saturday (list)
|
|
117
|
+
_items = []
|
|
118
|
+
if self.saturday:
|
|
119
|
+
for _item_saturday in self.saturday:
|
|
120
|
+
if _item_saturday:
|
|
121
|
+
_items.append(_item_saturday.to_dict())
|
|
122
|
+
_dict['saturday'] = _items
|
|
123
|
+
# override the default output from pydantic by calling `to_dict()` of each item in sunday (list)
|
|
124
|
+
_items = []
|
|
125
|
+
if self.sunday:
|
|
126
|
+
for _item_sunday in self.sunday:
|
|
127
|
+
if _item_sunday:
|
|
128
|
+
_items.append(_item_sunday.to_dict())
|
|
129
|
+
_dict['sunday'] = _items
|
|
130
|
+
return _dict
|
|
131
|
+
|
|
132
|
+
@classmethod
|
|
133
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
134
|
+
"""Create an instance of WeeklySchedule from a dict"""
|
|
135
|
+
if obj is None:
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
if not isinstance(obj, dict):
|
|
139
|
+
return cls.model_validate(obj)
|
|
140
|
+
|
|
141
|
+
_obj = cls.model_validate({
|
|
142
|
+
"start_time": obj.get("start_time"),
|
|
143
|
+
"end_time": obj.get("end_time"),
|
|
144
|
+
"monday": [DailySchedule.from_dict(_item) for _item in obj["monday"]] if obj.get("monday") is not None else None,
|
|
145
|
+
"tuesday": [DailySchedule.from_dict(_item) for _item in obj["tuesday"]] if obj.get("tuesday") is not None else None,
|
|
146
|
+
"wednesday": [DailySchedule.from_dict(_item) for _item in obj["wednesday"]] if obj.get("wednesday") is not None else None,
|
|
147
|
+
"thursday": [DailySchedule.from_dict(_item) for _item in obj["thursday"]] if obj.get("thursday") is not None else None,
|
|
148
|
+
"friday": [DailySchedule.from_dict(_item) for _item in obj["friday"]] if obj.get("friday") is not None else None,
|
|
149
|
+
"saturday": [DailySchedule.from_dict(_item) for _item in obj["saturday"]] if obj.get("saturday") is not None else None,
|
|
150
|
+
"sunday": [DailySchedule.from_dict(_item) for _item in obj["sunday"]] if obj.get("sunday") is not None else None
|
|
151
|
+
})
|
|
152
|
+
return _obj
|
|
153
|
+
|
|
154
|
+
|
|
File without changes
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Kalshi Trade API Manual Endpoints
|
|
5
|
+
|
|
6
|
+
Manually defined OpenAPI spec for endpoints being migrated to spec-first approach
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import io
|
|
16
|
+
import json
|
|
17
|
+
import re
|
|
18
|
+
import ssl
|
|
19
|
+
from typing import Optional, Union
|
|
20
|
+
|
|
21
|
+
import aiohttp
|
|
22
|
+
import aiohttp_retry
|
|
23
|
+
|
|
24
|
+
from kalshi_python_async.exceptions import ApiException, ApiValueError
|
|
25
|
+
|
|
26
|
+
RESTResponseType = aiohttp.ClientResponse
|
|
27
|
+
|
|
28
|
+
ALLOW_RETRY_METHODS = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE'})
|
|
29
|
+
|
|
30
|
+
class RESTResponse(io.IOBase):
|
|
31
|
+
|
|
32
|
+
def __init__(self, resp) -> None:
|
|
33
|
+
self.response = resp
|
|
34
|
+
self.status = resp.status
|
|
35
|
+
self.reason = resp.reason
|
|
36
|
+
self.data = None
|
|
37
|
+
|
|
38
|
+
async def read(self):
|
|
39
|
+
if self.data is None:
|
|
40
|
+
self.data = await self.response.read()
|
|
41
|
+
return self.data
|
|
42
|
+
|
|
43
|
+
def getheaders(self):
|
|
44
|
+
"""Returns a CIMultiDictProxy of the response headers."""
|
|
45
|
+
return self.response.headers
|
|
46
|
+
|
|
47
|
+
def getheader(self, name, default=None):
|
|
48
|
+
"""Returns a given response header."""
|
|
49
|
+
return self.response.headers.get(name, default)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class RESTClientObject:
|
|
53
|
+
|
|
54
|
+
def __init__(self, configuration) -> None:
|
|
55
|
+
|
|
56
|
+
# maxsize is number of requests to host that are allowed in parallel
|
|
57
|
+
self.maxsize = configuration.connection_pool_maxsize
|
|
58
|
+
|
|
59
|
+
self.ssl_context = ssl.create_default_context(
|
|
60
|
+
cafile=configuration.ssl_ca_cert,
|
|
61
|
+
cadata=configuration.ca_cert_data,
|
|
62
|
+
)
|
|
63
|
+
if configuration.cert_file:
|
|
64
|
+
self.ssl_context.load_cert_chain(
|
|
65
|
+
configuration.cert_file, keyfile=configuration.key_file
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if not configuration.verify_ssl:
|
|
69
|
+
self.ssl_context.check_hostname = False
|
|
70
|
+
self.ssl_context.verify_mode = ssl.CERT_NONE
|
|
71
|
+
|
|
72
|
+
self.proxy = configuration.proxy
|
|
73
|
+
self.proxy_headers = configuration.proxy_headers
|
|
74
|
+
|
|
75
|
+
self.retries = configuration.retries
|
|
76
|
+
|
|
77
|
+
self.pool_manager: Optional[aiohttp.ClientSession] = None
|
|
78
|
+
self.retry_client: Optional[aiohttp_retry.RetryClient] = None
|
|
79
|
+
|
|
80
|
+
async def close(self) -> None:
|
|
81
|
+
if self.pool_manager:
|
|
82
|
+
await self.pool_manager.close()
|
|
83
|
+
if self.retry_client is not None:
|
|
84
|
+
await self.retry_client.close()
|
|
85
|
+
|
|
86
|
+
async def request(
|
|
87
|
+
self,
|
|
88
|
+
method,
|
|
89
|
+
url,
|
|
90
|
+
headers=None,
|
|
91
|
+
body=None,
|
|
92
|
+
post_params=None,
|
|
93
|
+
_request_timeout=None
|
|
94
|
+
):
|
|
95
|
+
"""Execute request
|
|
96
|
+
|
|
97
|
+
:param method: http request method
|
|
98
|
+
:param url: http request url
|
|
99
|
+
:param headers: http request headers
|
|
100
|
+
:param body: request json body, for `application/json`
|
|
101
|
+
:param post_params: request post parameters,
|
|
102
|
+
`application/x-www-form-urlencoded`
|
|
103
|
+
and `multipart/form-data`
|
|
104
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
105
|
+
number provided, it will be total request
|
|
106
|
+
timeout. It can also be a pair (tuple) of
|
|
107
|
+
(connection, read) timeouts.
|
|
108
|
+
"""
|
|
109
|
+
method = method.upper()
|
|
110
|
+
assert method in [
|
|
111
|
+
'GET',
|
|
112
|
+
'HEAD',
|
|
113
|
+
'DELETE',
|
|
114
|
+
'POST',
|
|
115
|
+
'PUT',
|
|
116
|
+
'PATCH',
|
|
117
|
+
'OPTIONS'
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
if post_params and body:
|
|
121
|
+
raise ApiValueError(
|
|
122
|
+
"body parameter cannot be used with post_params parameter."
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
post_params = post_params or {}
|
|
126
|
+
headers = headers or {}
|
|
127
|
+
# url already contains the URL query string
|
|
128
|
+
timeout = _request_timeout or 5 * 60
|
|
129
|
+
|
|
130
|
+
if 'Content-Type' not in headers:
|
|
131
|
+
headers['Content-Type'] = 'application/json'
|
|
132
|
+
|
|
133
|
+
args = {
|
|
134
|
+
"method": method,
|
|
135
|
+
"url": url,
|
|
136
|
+
"timeout": timeout,
|
|
137
|
+
"headers": headers
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if self.proxy:
|
|
141
|
+
args["proxy"] = self.proxy
|
|
142
|
+
if self.proxy_headers:
|
|
143
|
+
args["proxy_headers"] = self.proxy_headers
|
|
144
|
+
|
|
145
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
|
146
|
+
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
|
|
147
|
+
if re.search('json', headers['Content-Type'], re.IGNORECASE):
|
|
148
|
+
if body is not None:
|
|
149
|
+
body = json.dumps(body)
|
|
150
|
+
args["data"] = body
|
|
151
|
+
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
|
152
|
+
args["data"] = aiohttp.FormData(post_params)
|
|
153
|
+
elif headers['Content-Type'] == 'multipart/form-data':
|
|
154
|
+
# must del headers['Content-Type'], or the correct
|
|
155
|
+
# Content-Type which generated by aiohttp
|
|
156
|
+
del headers['Content-Type']
|
|
157
|
+
data = aiohttp.FormData()
|
|
158
|
+
for param in post_params:
|
|
159
|
+
k, v = param
|
|
160
|
+
if isinstance(v, tuple) and len(v) == 3:
|
|
161
|
+
data.add_field(
|
|
162
|
+
k,
|
|
163
|
+
value=v[1],
|
|
164
|
+
filename=v[0],
|
|
165
|
+
content_type=v[2]
|
|
166
|
+
)
|
|
167
|
+
else:
|
|
168
|
+
# Ensures that dict objects are serialized
|
|
169
|
+
if isinstance(v, dict):
|
|
170
|
+
v = json.dumps(v)
|
|
171
|
+
elif isinstance(v, int):
|
|
172
|
+
v = str(v)
|
|
173
|
+
data.add_field(k, v)
|
|
174
|
+
args["data"] = data
|
|
175
|
+
|
|
176
|
+
# Pass a `bytes` or `str` parameter directly in the body to support
|
|
177
|
+
# other content types than Json when `body` argument is provided
|
|
178
|
+
# in serialized form
|
|
179
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
|
180
|
+
args["data"] = body
|
|
181
|
+
else:
|
|
182
|
+
# Cannot generate the request from given parameters
|
|
183
|
+
msg = """Cannot prepare a request message for provided
|
|
184
|
+
arguments. Please check that your arguments match
|
|
185
|
+
declared content type."""
|
|
186
|
+
raise ApiException(status=0, reason=msg)
|
|
187
|
+
|
|
188
|
+
pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
|
|
189
|
+
|
|
190
|
+
# https pool manager
|
|
191
|
+
if self.pool_manager is None:
|
|
192
|
+
self.pool_manager = aiohttp.ClientSession(
|
|
193
|
+
connector=aiohttp.TCPConnector(limit=self.maxsize, ssl=self.ssl_context),
|
|
194
|
+
trust_env=True,
|
|
195
|
+
)
|
|
196
|
+
pool_manager = self.pool_manager
|
|
197
|
+
|
|
198
|
+
if self.retries is not None and method in ALLOW_RETRY_METHODS:
|
|
199
|
+
if self.retry_client is None:
|
|
200
|
+
self.retry_client = aiohttp_retry.RetryClient(
|
|
201
|
+
client_session=self.pool_manager,
|
|
202
|
+
retry_options=aiohttp_retry.ExponentialRetry(
|
|
203
|
+
attempts=self.retries,
|
|
204
|
+
factor=2.0,
|
|
205
|
+
start_timeout=0.1,
|
|
206
|
+
max_timeout=120.0
|
|
207
|
+
)
|
|
208
|
+
)
|
|
209
|
+
pool_manager = self.retry_client
|
|
210
|
+
|
|
211
|
+
r = await pool_manager.request(**args)
|
|
212
|
+
|
|
213
|
+
return RESTResponse(r)
|