afp-sdk 0.5.4__py3-none-any.whl → 0.6.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.
- afp/__init__.py +4 -1
- afp/afp.py +11 -0
- afp/api/admin.py +1 -1
- afp/api/base.py +11 -2
- afp/api/margin_account.py +12 -148
- afp/api/product.py +302 -148
- afp/api/trading.py +10 -19
- afp/auth.py +14 -0
- afp/bindings/__init__.py +30 -16
- afp/bindings/admin_facet.py +890 -0
- afp/bindings/clearing_facet.py +356 -773
- afp/bindings/facade.py +9 -6
- afp/bindings/final_settlement_facet.py +258 -99
- afp/bindings/margin_account.py +524 -839
- afp/bindings/margin_account_facet.py +722 -0
- afp/bindings/margin_account_registry.py +184 -310
- afp/bindings/mark_price_tracker_facet.py +74 -16
- afp/bindings/product_registry.py +1577 -541
- afp/bindings/product_registry_facet.py +1467 -0
- afp/bindings/system_viewer.py +592 -369
- afp/bindings/types.py +223 -0
- afp/config.py +4 -0
- afp/constants.py +49 -6
- afp/decorators.py +25 -3
- afp/dtos.py +142 -0
- afp/exceptions.py +10 -0
- afp/exchange.py +10 -8
- afp/hashing.py +7 -5
- afp/ipfs.py +245 -0
- afp/json-schemas/bafyreiaw34o6l3rmatabzbds2i2myazdw2yolevcpsoyd2i2g3ms7wa2eq.json +1 -0
- afp/json-schemas/bafyreibnfg6nq74dvpkre5rakkccij7iadp5rxpim7omsatjnrpmj3y7v4.json +1 -0
- afp/json-schemas/bafyreicgr6dfo5yduixjkcifghiulskfegwojvuwodtouvivl362zndhxe.json +1 -0
- afp/json-schemas/bafyreicheoypx6synljushh7mq2572iyhlolf4nake2p5dwobgnj3r5eua.json +1 -0
- afp/json-schemas/bafyreid35a67db4sqh4fs6boddyt2xvscbqy6nqvsp5jjur56qhkw4ixre.json +1 -0
- afp/json-schemas/bafyreidzs7okcpqiss6ztftltyptqwnw5e5opsy5yntospekjha4kpykaa.json +1 -0
- afp/json-schemas/bafyreifcec2km7hxwq6oqzjlspni2mgipetjb7pqtaewh2efislzoctboi.json +1 -0
- afp/json-schemas/bafyreihn3oiaxffe4e2w7pwtreadpw3obfd7gqlogbcxm56jc2hzfvco74.json +1 -0
- afp/json-schemas/bafyreihur3dzwhja6uxsbcw6eeoj3xmmc4e3zkmyzpot5v5dleevxe5zam.json +1 -0
- afp/schemas.py +227 -177
- afp/types.py +169 -0
- afp/validators.py +218 -8
- {afp_sdk-0.5.4.dist-info → afp_sdk-0.6.0.dist-info}/METADATA +73 -10
- afp_sdk-0.6.0.dist-info/RECORD +50 -0
- afp/bindings/auctioneer_facet.py +0 -752
- afp/bindings/bankruptcy_facet.py +0 -391
- afp/bindings/trading_protocol.py +0 -1158
- afp_sdk-0.5.4.dist-info/RECORD +0 -37
- {afp_sdk-0.5.4.dist-info → afp_sdk-0.6.0.dist-info}/WHEEL +0 -0
- {afp_sdk-0.5.4.dist-info → afp_sdk-0.6.0.dist-info}/licenses/LICENSE +0 -0
afp/ipfs.py
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
from typing import Any, cast
|
|
5
|
+
|
|
6
|
+
import dag_cbor
|
|
7
|
+
import ipld_car # type: ignore (untyped library)
|
|
8
|
+
import multiformats
|
|
9
|
+
import requests
|
|
10
|
+
from requests import Response
|
|
11
|
+
|
|
12
|
+
from . import constants, types
|
|
13
|
+
from .dtos import ComponentLink, ExtendedMetadata, ExtendedMetadataDAG
|
|
14
|
+
from .exceptions import IPFSError, ValidationError
|
|
15
|
+
from .schemas import OracleConfig, OracleFallback, OutcomePoint, OutcomeSpace
|
|
16
|
+
from .types import Model, PinnedModel
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class IPFSClient:
|
|
20
|
+
_api_url: str
|
|
21
|
+
_api_key: str | None
|
|
22
|
+
|
|
23
|
+
def __init__(self, api_url: str, api_key: str | None = None):
|
|
24
|
+
self._api_url = api_url
|
|
25
|
+
self._api_key = api_key
|
|
26
|
+
|
|
27
|
+
def upload_extended_metadata(
|
|
28
|
+
self, extended_metadata: ExtendedMetadata
|
|
29
|
+
) -> types.CID:
|
|
30
|
+
"""Uploads extended metadata as a single CAR file."""
|
|
31
|
+
|
|
32
|
+
# Use mode="json" to convert Decimal & datetime types to strings
|
|
33
|
+
outcome_space_cid, outcome_space_data = self.encode(
|
|
34
|
+
extended_metadata.outcome_space.model_dump(mode="json")
|
|
35
|
+
)
|
|
36
|
+
outcome_point_cid, outcome_point_data = self.encode(
|
|
37
|
+
extended_metadata.outcome_point.model_dump(mode="json")
|
|
38
|
+
)
|
|
39
|
+
oracle_config_cid, oracle_config_data = self.encode(
|
|
40
|
+
extended_metadata.oracle_config.model_dump(mode="json")
|
|
41
|
+
)
|
|
42
|
+
oracle_fallback_cid, oracle_fallback_data = self.encode(
|
|
43
|
+
extended_metadata.oracle_fallback.model_dump(mode="json")
|
|
44
|
+
)
|
|
45
|
+
outcome_space_schema_cid, outcome_space_schema_data = self.encode(
|
|
46
|
+
self._load_schema_json(extended_metadata.outcome_space.SCHEMA_CID)
|
|
47
|
+
)
|
|
48
|
+
outcome_point_schema_cid, outcome_point_schema_data = self.encode(
|
|
49
|
+
self._load_schema_json(extended_metadata.outcome_point.SCHEMA_CID)
|
|
50
|
+
)
|
|
51
|
+
oracle_config_schema_cid, oracle_config_schema_data = self.encode(
|
|
52
|
+
self._load_schema_json(extended_metadata.oracle_config.SCHEMA_CID)
|
|
53
|
+
)
|
|
54
|
+
oracle_fallback_schema_cid, oracle_fallback_schema_data = self.encode(
|
|
55
|
+
self._load_schema_json(extended_metadata.oracle_fallback.SCHEMA_CID)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
self.ensure_cids_match(
|
|
59
|
+
outcome_space_schema_cid, extended_metadata.outcome_space.SCHEMA_CID
|
|
60
|
+
)
|
|
61
|
+
self.ensure_cids_match(
|
|
62
|
+
outcome_point_schema_cid, extended_metadata.outcome_point.SCHEMA_CID
|
|
63
|
+
)
|
|
64
|
+
self.ensure_cids_match(
|
|
65
|
+
oracle_config_schema_cid, extended_metadata.oracle_config.SCHEMA_CID
|
|
66
|
+
)
|
|
67
|
+
self.ensure_cids_match(
|
|
68
|
+
oracle_fallback_schema_cid, extended_metadata.oracle_fallback.SCHEMA_CID
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
extended_metadata_dag = ExtendedMetadataDAG(
|
|
72
|
+
outcome_space=ComponentLink(
|
|
73
|
+
data=str(outcome_space_cid),
|
|
74
|
+
schema_=str(outcome_space_schema_cid),
|
|
75
|
+
),
|
|
76
|
+
outcome_point=ComponentLink(
|
|
77
|
+
data=str(outcome_point_cid),
|
|
78
|
+
schema_=str(outcome_point_schema_cid),
|
|
79
|
+
),
|
|
80
|
+
oracle_config=ComponentLink(
|
|
81
|
+
data=str(oracle_config_cid),
|
|
82
|
+
schema_=str(oracle_config_schema_cid),
|
|
83
|
+
),
|
|
84
|
+
oracle_fallback=ComponentLink(
|
|
85
|
+
data=str(oracle_fallback_cid),
|
|
86
|
+
schema_=str(oracle_fallback_schema_cid),
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
# Use mode="python" to preserve multiformats.CID types so that the DAG-CBOR
|
|
90
|
+
# encoder will convert them into IPLD Link format
|
|
91
|
+
extended_metadata_dag_cid, extended_metadata_dag_data = self.encode(
|
|
92
|
+
extended_metadata_dag.model_dump(mode="python")
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
blocks: list[ipld_car.Block] = [
|
|
96
|
+
(extended_metadata_dag_cid, extended_metadata_dag_data),
|
|
97
|
+
(outcome_space_cid, outcome_space_data),
|
|
98
|
+
(outcome_point_cid, outcome_point_data),
|
|
99
|
+
(oracle_config_cid, oracle_config_data),
|
|
100
|
+
(oracle_fallback_cid, oracle_fallback_data),
|
|
101
|
+
(outcome_space_schema_cid, outcome_space_schema_data),
|
|
102
|
+
(outcome_point_schema_cid, outcome_point_schema_data),
|
|
103
|
+
(oracle_config_schema_cid, oracle_config_schema_data),
|
|
104
|
+
(oracle_fallback_schema_cid, oracle_fallback_schema_data),
|
|
105
|
+
]
|
|
106
|
+
root_cid = self.upload_car(blocks)
|
|
107
|
+
self.ensure_cids_match(root_cid, extended_metadata_dag_cid)
|
|
108
|
+
return root_cid
|
|
109
|
+
|
|
110
|
+
def download_extended_metadata(self, cid: types.CID) -> ExtendedMetadata:
|
|
111
|
+
"""Downloads and assembles extended metadata objects."""
|
|
112
|
+
|
|
113
|
+
extended_metadata_dag = self._download_and_validate_block(
|
|
114
|
+
cid, ExtendedMetadataDAG
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
outcome_space_model = cast(
|
|
118
|
+
type[OutcomeSpace],
|
|
119
|
+
self._find_model_by_schema_cid(extended_metadata_dag.outcome_space.schema_),
|
|
120
|
+
)
|
|
121
|
+
outcome_point_model = cast(
|
|
122
|
+
type[OutcomePoint],
|
|
123
|
+
self._find_model_by_schema_cid(extended_metadata_dag.outcome_point.schema_),
|
|
124
|
+
)
|
|
125
|
+
oracle_config_model = cast(
|
|
126
|
+
type[OracleConfig],
|
|
127
|
+
self._find_model_by_schema_cid(extended_metadata_dag.oracle_config.schema_),
|
|
128
|
+
)
|
|
129
|
+
oracle_fallback_model = cast(
|
|
130
|
+
type[OracleFallback],
|
|
131
|
+
self._find_model_by_schema_cid(
|
|
132
|
+
extended_metadata_dag.oracle_fallback.schema_
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
return ExtendedMetadata(
|
|
137
|
+
outcome_space=self._download_and_validate_block(
|
|
138
|
+
extended_metadata_dag.outcome_space.data, outcome_space_model
|
|
139
|
+
),
|
|
140
|
+
outcome_point=self._download_and_validate_block(
|
|
141
|
+
extended_metadata_dag.outcome_point.data, outcome_point_model
|
|
142
|
+
),
|
|
143
|
+
oracle_config=self._download_and_validate_block(
|
|
144
|
+
extended_metadata_dag.oracle_config.data, oracle_config_model
|
|
145
|
+
),
|
|
146
|
+
oracle_fallback=self._download_and_validate_block(
|
|
147
|
+
extended_metadata_dag.oracle_fallback.data, oracle_fallback_model
|
|
148
|
+
),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def upload_car(self, blocks: list[ipld_car.Block]) -> types.CID:
|
|
152
|
+
root_cid = blocks[0][0]
|
|
153
|
+
data = ipld_car.encode([root_cid], blocks).tobytes()
|
|
154
|
+
|
|
155
|
+
response = self._send_client_request(
|
|
156
|
+
"/api/v0/dag/import",
|
|
157
|
+
params={"pin-roots": "true"},
|
|
158
|
+
files={"file": ("data.car", io.BytesIO(data), "application/vnd.ipld.car")},
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
try:
|
|
162
|
+
response_data = response.json()
|
|
163
|
+
except json.JSONDecodeError as json_error:
|
|
164
|
+
raise IPFSError(
|
|
165
|
+
f"Error decoding IPFS response: {response.text}"
|
|
166
|
+
) from json_error
|
|
167
|
+
|
|
168
|
+
try:
|
|
169
|
+
return response_data["Root"]["Cid"]["/"]
|
|
170
|
+
except (TypeError, KeyError):
|
|
171
|
+
raise IPFSError(f"Unexpected IPFS response format: {response_data}")
|
|
172
|
+
|
|
173
|
+
def _download_and_validate_block[T: Model](
|
|
174
|
+
self, cid: types.CID, model: type[T]
|
|
175
|
+
) -> T:
|
|
176
|
+
codec_name = multiformats.CID.decode(cid).codec.name
|
|
177
|
+
response = self._send_client_request("/api/v0/block/get", params={"arg": cid})
|
|
178
|
+
|
|
179
|
+
if codec_name == "dag-cbor":
|
|
180
|
+
return model.model_validate(dag_cbor.decode(response.content))
|
|
181
|
+
elif codec_name == "dag-json":
|
|
182
|
+
return model.model_validate_json(response.content)
|
|
183
|
+
else:
|
|
184
|
+
raise IPFSError(f"Unsupported codec: {codec_name}")
|
|
185
|
+
|
|
186
|
+
def _send_client_request(self, endpoint: str, **kwargs: Any) -> Response:
|
|
187
|
+
headers: dict[str, str] = {}
|
|
188
|
+
if self._api_key:
|
|
189
|
+
headers["Authorization"] = f"Bearer {self._api_key}"
|
|
190
|
+
|
|
191
|
+
url = f"{self._api_url}{endpoint}"
|
|
192
|
+
try:
|
|
193
|
+
response = requests.post(
|
|
194
|
+
url,
|
|
195
|
+
headers=headers,
|
|
196
|
+
timeout=constants.IPFS_REQUEST_TIMEOUT,
|
|
197
|
+
**kwargs,
|
|
198
|
+
)
|
|
199
|
+
except requests.exceptions.Timeout as timeout_error:
|
|
200
|
+
raise IPFSError(
|
|
201
|
+
f"Request to IPFS client timed out after "
|
|
202
|
+
f"{constants.IPFS_REQUEST_TIMEOUT}s: {url}"
|
|
203
|
+
) from timeout_error
|
|
204
|
+
except requests.exceptions.RequestException as request_exception:
|
|
205
|
+
raise IPFSError(
|
|
206
|
+
f"Failed to send request to IPFS client: {url}"
|
|
207
|
+
) from request_exception
|
|
208
|
+
|
|
209
|
+
try:
|
|
210
|
+
response.raise_for_status()
|
|
211
|
+
except requests.exceptions.HTTPError as http_error:
|
|
212
|
+
raise IPFSError(
|
|
213
|
+
f"IPFS client returned HTTP {response.status_code}: {url}"
|
|
214
|
+
) from http_error
|
|
215
|
+
|
|
216
|
+
return response
|
|
217
|
+
|
|
218
|
+
@staticmethod
|
|
219
|
+
def encode(value: Any) -> tuple[multiformats.CID, bytes]:
|
|
220
|
+
cbor_data = dag_cbor.encode(value)
|
|
221
|
+
digest = multiformats.multihash.digest(cbor_data, "sha2-256")
|
|
222
|
+
cid = multiformats.CID(constants.IPFS_CID_ENCODING, 1, "dag-cbor", digest)
|
|
223
|
+
return (cid, cbor_data)
|
|
224
|
+
|
|
225
|
+
@staticmethod
|
|
226
|
+
def ensure_cids_match(
|
|
227
|
+
actual_cid: types.CID | multiformats.CID,
|
|
228
|
+
computed_cid: types.CID | multiformats.CID,
|
|
229
|
+
) -> None:
|
|
230
|
+
if str(computed_cid) != str(actual_cid):
|
|
231
|
+
raise IPFSError(
|
|
232
|
+
f"Mismatch between computed CID '{computed_cid}' "
|
|
233
|
+
f"and actual CID '{actual_cid}'"
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
@staticmethod
|
|
237
|
+
def _find_model_by_schema_cid(cid: types.CID) -> type[PinnedModel]:
|
|
238
|
+
if cid not in types.CID_MODEL_MAP:
|
|
239
|
+
raise ValidationError(f"Unsupported schema CID: {cid}")
|
|
240
|
+
return types.CID_MODEL_MAP[cid]
|
|
241
|
+
|
|
242
|
+
@staticmethod
|
|
243
|
+
def _load_schema_json(cid: types.CID) -> dict[Any, Any]:
|
|
244
|
+
with open(os.path.join(constants.JSON_SCHEMAS_DIRECTORY, f"{cid}.json")) as f:
|
|
245
|
+
return json.load(f)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$defs":{"ApiSpec":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Abstract base class for API specifications.\n\nDefines the interface for API specifications that can fetch data\nand return standardized data structures. Subclasses implement\nspecific API standards (JSONPath, GraphQL, etc.).","properties":{"spec_variant":{"anyOf":[{"$ref":"#/$defs/SpecVariant"},{"type":"null"}],"default":null,"description":"Semantic purpose of the API response: 'underlying-history' for time series data (multiple date-value pairs), 'product-fsv' for final settlement value (single date-value pair)"},"standard":{"$ref":"#/$defs/ApiStandard","description":"API standard/protocol used (must be overridden by subclasses with specific Literal type)"}},"required":["standard"],"title":"ApiSpec","type":"object","version":"0.2.0"},"ApiSpecJSONPath":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"JSONPath specification for extracting timeseries data from API responses.\n\nThis class provides a flexible way to specify how to extract standardized\ntimeseries data from various JSON APIs using JSONPath expressions.\nSupports both historical timeseries and latest value extraction.","properties":{"auth_param_location":{"$ref":"#/$defs/AuthParamLocation","default":"none","description":"Where to place the authentication parameter, or 'none' for public APIs"},"auth_param_name":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"Name of the authentication parameter (e.g., 'api_key', 'token')","title":"Auth Param Name"},"auth_param_prefix":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"Prefix for auth value in headers (e.g., 'Bearer ', 'API-Key '). Only applicable when auth_param_location is 'header'","title":"Auth Param Prefix"},"continuation_token_param":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"Query parameter name to send continuation token in next request (e.g., 'start_timestamp', 'cursor', 'next')","title":"Continuation Token Param"},"continuation_token_path":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"JSONPath expression to extract continuation token from response for pagination (e.g., '$.result.continuation', '$.next_token')","title":"Continuation Token Path"},"date_format_custom":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"Custom strftime format string (required when date_format_type='custom')","title":"Date Format Custom"},"date_format_type":{"$ref":"#/$defs/DateFormatType","default":"iso_8601","description":"Date format type: 'iso_8601' (ISO 8601: 2023-01-01T12:00:00Z, 2023-01-01, etc.), 'unix_timestamp' (1640995200), or 'custom' (requires date_format_custom)"},"date_path":{"description":"JSONPath expression to extract date/timestamp(s): use array syntax like '$.data[*].timestamp' for multiple values, '$.timestamp' for single value","title":"Date Path","type":"string"},"headers":{"anyOf":[{"additionalProperties":{"type":"string"},"type":"object"},{"type":"null"}],"default":null,"description":"Optional HTTP headers to include in API requests","title":"Headers"},"max_pages":{"anyOf":[{"minimum":1,"type":"integer"},{"type":"null"}],"default":10,"description":"Maximum number of pages to fetch when pagination is enabled (prevents infinite loops)","title":"Max Pages"},"spec_variant":{"anyOf":[{"$ref":"#/$defs/SpecVariant"},{"type":"null"}],"default":null,"description":"Semantic purpose of the API response: 'underlying-history' for time series data (multiple date-value pairs), 'product-fsv' for final settlement value (single date-value pair)"},"standard":{"const":"JSONPath","default":"JSONPath","description":"API standard used (fixed for JSONPath implementations)","title":"Standard","type":"string"},"timestamp_scale":{"default":1,"description":"Scale factor for unix timestamps: 1 for seconds, 1000 for milliseconds, 1000000 for microseconds","minimum":1,"title":"Timestamp Scale","type":"number"},"timezone":{"default":"UTC","description":"IANA timezone identifier (e.g., UTC, America/New_York, Europe/London)","pattern":"^[A-Za-z][A-Za-z0-9_+-]*(/[A-Za-z][A-Za-z0-9_+-]*)*$","title":"Timezone","type":"string"},"url":{"description":"API endpoint URL for data fetching","maxLength":2083,"minLength":1,"title":"Url","type":"string"},"value_path":{"description":"JSONPath expression to extract numeric value(s): use array syntax like '$.data[*].price' for multiple values, '$.price' for single value","title":"Value Path","type":"string"}},"required":["url","date_path","value_path"],"title":"ApiSpecJSONPath","type":"object","version":"0.2.0"},"ApiStandard":{"description":"API standard/protocol.","enum":["JSONPath","GraphQL"],"title":"ApiStandard","type":"string"},"AuthParamLocation":{"description":"Authentication parameter location.","enum":["query","header","none"],"title":"AuthParamLocation","type":"string"},"DateFormatType":{"description":"Date format type.","enum":["iso_8601","unix_timestamp","custom"],"title":"DateFormatType","type":"string"},"OracleConfig":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Base configuration for oracle system operational metadata.\n\nProvides oracle-system-specific configuration separate from universal\ndomain semantics in outcome_space. Subclasses add system-specific fields\nfor different oracle implementations.","properties":{"description":{"description":"Human-readable description of this oracle system","minLength":1,"title":"Description","type":"string"},"project_url":{"anyOf":[{"maxLength":2083,"minLength":1,"type":"string"},{"type":"null"}],"default":null,"description":"Optional URL to oracle system project page or documentation","title":"Project Url"}},"required":["description"],"title":"OracleConfig","type":"object","version":"0.2.0"},"SpecVariant":{"description":"Semantic purpose of the API response.","enum":["underlying-history","product-fsv"],"title":"SpecVariant","type":"string"}},"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"allOf":[{"$ref":"#/$defs/OracleConfig"}],"description":"Oracle configuration for Prototype1 oracle system.\n\nExtends base oracle config with API specification for FSV evaluation.","properties":{"evaluation_api_spec":{"anyOf":[{"$ref":"#/$defs/ApiSpecJSONPath"},{"$ref":"#/$defs/ApiSpec"}],"description":"API specification for fetching final settlement value (FSV) data","title":"Evaluation Api Spec"}},"required":["evaluation_api_spec"],"title":"OracleConfigPrototype1","type":"object","version":"0.2.0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Base class for outcome points.\n\nDefines specific coordinates within an outcome space that identify a particular\nproduct instance. Outcome points specify the exact parameters that distinguish\none product from others in the same outcome space family.","properties":{"fsp_type":{"description":"Type of Final Settlement Price: 'scalar' for continuous values, 'binary' for 0/1 outcomes, 'ternary' for 0/0.5/1 outcomes","enum":["scalar","binary","ternary"],"title":"Fsp Type","type":"string"}},"required":["fsp_type"],"title":"OutcomePoint","type":"object","version":"0.2.0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Fallback mechanism for oracle failure or indeterminate FSP.\n\nSpecifies a fallback final settlement price (FSP) that will be used\nif the oracle has not provided a valid FSP by the fallback_time.\nThis prevents user collateral from being locked indefinitely.\n\nTypically, fallback_time is set significantly after earliestFSPSubmissionTime\n(e.g., weeks or months later) to ensure this mechanism is rarely activated.","properties":{"fallback_fsp":{"description":"Fallback final settlement price (decimal string, may be negative). Used if oracle fails to provide FSP by fallback_time. Must be within product price range [minPrice, maxPrice]. Examples: '0.5', '100.0', '-1.5'","pattern":"^-?\\d+(\\.\\d+)?$","title":"Fallback Fsp","type":"string"},"fallback_time":{"description":"Fallback activation time (UTC datetime in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ). If oracle has not provided FSP by this time, fallback_fsp will be used. Must be significantly after earliestFSPSubmissionTime. Example: '2026-12-31T23:59:59Z'","pattern":"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$","title":"Fallback Time","type":"string"}},"required":["fallback_time","fallback_fsp"],"title":"OracleFallback","type":"object","version":"0.2.0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$defs":{"BaseCaseResolution":{"additionalProperties":false,"description":"Base case FSP resolution criteria.","properties":{"condition":{"description":"Describes what is being evaluated or measured. For scalar products: the question being asked (e.g., 'What will the {reference_date} US CPI-U value be?'). For binary products: the proposition being evaluated (e.g., '{outcome} wins the 2028 Republican Presidential Nomination'). Supports template variables from outcome_point.","minLength":1,"title":"Condition","type":"string"},"fsp_resolution":{"description":"Detailed explanation of how the Final Settlement Price (FSP) is computed or determined in typical circumstances. For scalar products: describe the computation formula. For binary products: describe conditions for FSP=1 (max_price) vs FSP=0 (min_price). Should reference primary data sources.","minLength":1,"title":"Fsp Resolution","type":"string"}},"required":["condition","fsp_resolution"],"title":"BaseCaseResolution","type":"object"},"EdgeCase":{"additionalProperties":false,"description":"Edge case with alternative FSP resolution logic.","properties":{"condition":{"description":"Describes when this edge case applies. Supports template variables from outcome_point.","minLength":1,"title":"Condition","type":"string"},"fsp_resolution":{"description":"How FSP is determined when this condition is met. May specify that oracle does not submit FSP (product remains unsettled), or provide alternative computation logic.","minLength":1,"title":"Fsp Resolution","type":"string"}},"required":["condition","fsp_resolution"],"title":"EdgeCase","type":"object"}},"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Base class for outcome spaces.\n\nDefines a family of related prediction products that share common resolution logic.\nAn outcome space specifies how to evaluate outcomes and determine the Final Settlement\nPrice (FSP) for products within its family. Products in the same family reference the\nsame outcome_space CID and differ only in their outcome_point values.","properties":{"base_case":{"$ref":"#/$defs/BaseCaseResolution","description":"Evaluation criteria for typical circumstances - how FSP is determined under normal conditions"},"description":{"description":"Human-readable description of what this outcome space represents (e.g., 'US Consumer Price Index', 'Who will win the 2028 Republican Presidential Nomination?')","minLength":1,"title":"Description","type":"string"},"edge_cases":{"description":"Exceptional circumstances with alternative FSP resolution logic. Evaluated in order; first matching condition applies.","items":{"$ref":"#/$defs/EdgeCase"},"title":"Edge Cases","type":"array"},"fsp_type":{"description":"Type of Final Settlement Price: 'scalar' for continuous values, 'binary' for 0/1 outcomes, 'ternary' for 0/0.5/1 outcomes","enum":["scalar","binary","ternary"],"title":"Fsp Type","type":"string"}},"required":["fsp_type","description","base_case"],"title":"OutcomeSpace","type":"object","version":"0.2.0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$defs":{"ApiSpec":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Abstract base class for API specifications.\n\nDefines the interface for API specifications that can fetch data\nand return standardized data structures. Subclasses implement\nspecific API standards (JSONPath, GraphQL, etc.).","properties":{"spec_variant":{"anyOf":[{"$ref":"#/$defs/SpecVariant"},{"type":"null"}],"default":null,"description":"Semantic purpose of the API response: 'underlying-history' for time series data (multiple date-value pairs), 'product-fsv' for final settlement value (single date-value pair)"},"standard":{"$ref":"#/$defs/ApiStandard","description":"API standard/protocol used (must be overridden by subclasses with specific Literal type)"}},"required":["standard"],"title":"ApiSpec","type":"object","version":"0.2.0"},"ApiSpecJSONPath":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"JSONPath specification for extracting timeseries data from API responses.\n\nThis class provides a flexible way to specify how to extract standardized\ntimeseries data from various JSON APIs using JSONPath expressions.\nSupports both historical timeseries and latest value extraction.","properties":{"auth_param_location":{"$ref":"#/$defs/AuthParamLocation","default":"none","description":"Where to place the authentication parameter, or 'none' for public APIs"},"auth_param_name":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"Name of the authentication parameter (e.g., 'api_key', 'token')","title":"Auth Param Name"},"auth_param_prefix":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"Prefix for auth value in headers (e.g., 'Bearer ', 'API-Key '). Only applicable when auth_param_location is 'header'","title":"Auth Param Prefix"},"continuation_token_param":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"Query parameter name to send continuation token in next request (e.g., 'start_timestamp', 'cursor', 'next')","title":"Continuation Token Param"},"continuation_token_path":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"JSONPath expression to extract continuation token from response for pagination (e.g., '$.result.continuation', '$.next_token')","title":"Continuation Token Path"},"date_format_custom":{"anyOf":[{"type":"string"},{"type":"null"}],"default":null,"description":"Custom strftime format string (required when date_format_type='custom')","title":"Date Format Custom"},"date_format_type":{"$ref":"#/$defs/DateFormatType","default":"iso_8601","description":"Date format type: 'iso_8601' (ISO 8601: 2023-01-01T12:00:00Z, 2023-01-01, etc.), 'unix_timestamp' (1640995200), or 'custom' (requires date_format_custom)"},"date_path":{"description":"JSONPath expression to extract date/timestamp(s): use array syntax like '$.data[*].timestamp' for multiple values, '$.timestamp' for single value","title":"Date Path","type":"string"},"headers":{"anyOf":[{"additionalProperties":{"type":"string"},"type":"object"},{"type":"null"}],"default":null,"description":"Optional HTTP headers to include in API requests","title":"Headers"},"max_pages":{"anyOf":[{"minimum":1,"type":"integer"},{"type":"null"}],"default":10,"description":"Maximum number of pages to fetch when pagination is enabled (prevents infinite loops)","title":"Max Pages"},"spec_variant":{"anyOf":[{"$ref":"#/$defs/SpecVariant"},{"type":"null"}],"default":null,"description":"Semantic purpose of the API response: 'underlying-history' for time series data (multiple date-value pairs), 'product-fsv' for final settlement value (single date-value pair)"},"standard":{"const":"JSONPath","default":"JSONPath","description":"API standard used (fixed for JSONPath implementations)","title":"Standard","type":"string"},"timestamp_scale":{"default":1,"description":"Scale factor for unix timestamps: 1 for seconds, 1000 for milliseconds, 1000000 for microseconds","minimum":1,"title":"Timestamp Scale","type":"number"},"timezone":{"default":"UTC","description":"IANA timezone identifier (e.g., UTC, America/New_York, Europe/London)","pattern":"^[A-Za-z][A-Za-z0-9_+-]*(/[A-Za-z][A-Za-z0-9_+-]*)*$","title":"Timezone","type":"string"},"url":{"description":"API endpoint URL for data fetching","maxLength":2083,"minLength":1,"title":"Url","type":"string"},"value_path":{"description":"JSONPath expression to extract numeric value(s): use array syntax like '$.data[*].price' for multiple values, '$.price' for single value","title":"Value Path","type":"string"}},"required":["url","date_path","value_path"],"title":"ApiSpecJSONPath","type":"object","version":"0.2.0"},"ApiStandard":{"description":"API standard/protocol.","enum":["JSONPath","GraphQL"],"title":"ApiStandard","type":"string"},"AuthParamLocation":{"description":"Authentication parameter location.","enum":["query","header","none"],"title":"AuthParamLocation","type":"string"},"BaseCaseResolution":{"additionalProperties":false,"description":"Base case FSP resolution criteria.","properties":{"condition":{"description":"Describes what is being evaluated or measured. For scalar products: the question being asked (e.g., 'What will the {reference_date} US CPI-U value be?'). For binary products: the proposition being evaluated (e.g., '{outcome} wins the 2028 Republican Presidential Nomination'). Supports template variables from outcome_point.","minLength":1,"title":"Condition","type":"string"},"fsp_resolution":{"description":"Detailed explanation of how the Final Settlement Price (FSP) is computed or determined in typical circumstances. For scalar products: describe the computation formula. For binary products: describe conditions for FSP=1 (max_price) vs FSP=0 (min_price). Should reference primary data sources.","minLength":1,"title":"Fsp Resolution","type":"string"}},"required":["condition","fsp_resolution"],"title":"BaseCaseResolution","type":"object"},"DateFormatType":{"description":"Date format type.","enum":["iso_8601","unix_timestamp","custom"],"title":"DateFormatType","type":"string"},"EdgeCase":{"additionalProperties":false,"description":"Edge case with alternative FSP resolution logic.","properties":{"condition":{"description":"Describes when this edge case applies. Supports template variables from outcome_point.","minLength":1,"title":"Condition","type":"string"},"fsp_resolution":{"description":"How FSP is determined when this condition is met. May specify that oracle does not submit FSP (product remains unsettled), or provide alternative computation logic.","minLength":1,"title":"Fsp Resolution","type":"string"}},"required":["condition","fsp_resolution"],"title":"EdgeCase","type":"object"},"Frequency":{"description":"Frequency of time series observations.","enum":["daily","weekly","fortnightly","semimonthly","monthly","quarterly","yearly"],"title":"Frequency","type":"string"},"OutcomeSpace":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Base class for outcome spaces.\n\nDefines a family of related prediction products that share common resolution logic.\nAn outcome space specifies how to evaluate outcomes and determine the Final Settlement\nPrice (FSP) for products within its family. Products in the same family reference the\nsame outcome_space CID and differ only in their outcome_point values.","properties":{"base_case":{"$ref":"#/$defs/BaseCaseResolution","description":"Evaluation criteria for typical circumstances - how FSP is determined under normal conditions"},"description":{"description":"Human-readable description of what this outcome space represents (e.g., 'US Consumer Price Index', 'Who will win the 2028 Republican Presidential Nomination?')","minLength":1,"title":"Description","type":"string"},"edge_cases":{"description":"Exceptional circumstances with alternative FSP resolution logic. Evaluated in order; first matching condition applies.","items":{"$ref":"#/$defs/EdgeCase"},"title":"Edge Cases","type":"array"},"fsp_type":{"description":"Type of Final Settlement Price: 'scalar' for continuous values, 'binary' for 0/1 outcomes, 'ternary' for 0/0.5/1 outcomes","enum":["scalar","binary","ternary"],"title":"Fsp Type","type":"string"}},"required":["fsp_type","description","base_case"],"title":"OutcomeSpace","type":"object","version":"0.2.0"},"OutcomeSpaceScalar":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"allOf":[{"$ref":"#/$defs/OutcomeSpace"}],"description":"Base class for scalar outcome spaces.\n\nDefines outcome spaces that track continuous numeric values (as opposed to\ndiscrete binary outcomes). Scalar products can represent economic indicators,\nfinancial data, physical measurements, or any quantifiable metric.","properties":{"fsp_type":{"const":"scalar","description":"Type of Final Settlement Price: must be 'scalar' for scalar outcome spaces","title":"Fsp Type","type":"string"},"source_name":{"description":"Name of the original publisher or authoritative source of the data (e.g., 'Bureau of Labor Statistics', 'Federal Reserve', 'World Bank')","minLength":1,"title":"Source Name","type":"string"},"source_uri":{"description":"URL of the original publisher or authoritative source of the data","maxLength":2083,"minLength":1,"title":"Source Uri","type":"string"},"units":{"description":"Units represented by the scalar values (e.g., 'Percent (annualized)', 'USD', 'Index points', 'Basis points')","minLength":1,"title":"Units","type":"string"}},"required":["fsp_type","units","source_name","source_uri"],"title":"OutcomeSpaceScalar","type":"object","version":"0.2.0"},"SpecVariant":{"description":"Semantic purpose of the API response.","enum":["underlying-history","product-fsv"],"title":"SpecVariant","type":"string"}},"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"allOf":[{"$ref":"#/$defs/OutcomeSpaceScalar"}],"description":"Time series outcome space for economic and financial data published periodically.\n\nDefines a family of prediction products based on time series data (e.g., monthly CPI,\nquarterly GDP, daily closing prices). All products in this family share the same data\nsource and evaluation logic but differ in their temporal coordinates (outcome_point).","properties":{"frequency":{"$ref":"#/$defs/Frequency","description":"Frequency of the underlying time series observations"},"history_api_spec":{"anyOf":[{"$ref":"#/$defs/ApiSpecJSONPath"},{"$ref":"#/$defs/ApiSpec"},{"type":"null"}],"default":null,"description":"Optional API specification for fetching historical timeseries data","title":"History Api Spec"}},"required":["frequency"],"title":"OutcomeSpaceTimeSeries","type":"object","version":"0.2.0","x-outcome-point-schema":"OutcomePointTimeSeries"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$defs":{"OutcomePoint":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Base class for outcome points.\n\nDefines specific coordinates within an outcome space that identify a particular\nproduct instance. Outcome points specify the exact parameters that distinguish\none product from others in the same outcome space family.","properties":{"fsp_type":{"description":"Type of Final Settlement Price: 'scalar' for continuous values, 'binary' for 0/1 outcomes, 'ternary' for 0/0.5/1 outcomes","enum":["scalar","binary","ternary"],"title":"Fsp Type","type":"string"}},"required":["fsp_type"],"title":"OutcomePoint","type":"object","version":"0.2.0"},"TemporalObservation":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"description":"Temporal coordinates identifying a specific time series observation.\n\nA temporal observation is a single point in a time series, characterized by\nwhen the observation occurred (reference_date) and when it was published\n(release_date). This represents one dimension in the outcome space.","properties":{"reference_date":{"description":"Date of the observation period (ISO 8601: YYYY-MM-DD). For monthly data: first day of month. For quarterly: first day of quarter. For yearly: January 1st.","pattern":"^\\d{4}-\\d{2}-\\d{2}$","title":"Reference Date","type":"string"},"release_date":{"description":"Date when the value is officially released/published (ISO 8601: YYYY-MM-DD). Used when products track specific data releases.","pattern":"^\\d{4}-\\d{2}-\\d{2}$","title":"Release Date","type":"string"}},"required":["reference_date","release_date"],"title":"TemporalObservation","type":"object","version":"0.2.0"}},"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"allOf":[{"$ref":"#/$defs/OutcomePoint"}],"description":"Outcome point for time series outcome spaces.\n\nSpecifies which temporal observation this product tracks. This is a\none-dimensional outcome point where the dimension is temporal.","properties":{"fsp_type":{"const":"scalar","description":"Type of Final Settlement Price: must be 'scalar' for time series outcome points","title":"Fsp Type","type":"string"},"observation":{"$ref":"#/$defs/TemporalObservation","description":"The temporal observation being tracked (one dimension)"}},"required":["fsp_type","observation"],"title":"OutcomePointTimeSeries","type":"object","version":"0.2.0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Base configuration for oracle system operational metadata.\n\nProvides oracle-system-specific configuration separate from universal\ndomain semantics in outcome_space. Subclasses add system-specific fields\nfor different oracle implementations.","properties":{"description":{"description":"Human-readable description of this oracle system","minLength":1,"title":"Description","type":"string"},"project_url":{"anyOf":[{"maxLength":2083,"minLength":1,"type":"string"},{"type":"null"}],"default":null,"description":"Optional URL to oracle system project page or documentation","title":"Project Url"}},"required":["description"],"title":"OracleConfig","type":"object","version":"0.2.0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$defs":{"BaseCaseResolution":{"additionalProperties":false,"description":"Base case FSP resolution criteria.","properties":{"condition":{"description":"Describes what is being evaluated or measured. For scalar products: the question being asked (e.g., 'What will the {reference_date} US CPI-U value be?'). For binary products: the proposition being evaluated (e.g., '{outcome} wins the 2028 Republican Presidential Nomination'). Supports template variables from outcome_point.","minLength":1,"title":"Condition","type":"string"},"fsp_resolution":{"description":"Detailed explanation of how the Final Settlement Price (FSP) is computed or determined in typical circumstances. For scalar products: describe the computation formula. For binary products: describe conditions for FSP=1 (max_price) vs FSP=0 (min_price). Should reference primary data sources.","minLength":1,"title":"Fsp Resolution","type":"string"}},"required":["condition","fsp_resolution"],"title":"BaseCaseResolution","type":"object"},"EdgeCase":{"additionalProperties":false,"description":"Edge case with alternative FSP resolution logic.","properties":{"condition":{"description":"Describes when this edge case applies. Supports template variables from outcome_point.","minLength":1,"title":"Condition","type":"string"},"fsp_resolution":{"description":"How FSP is determined when this condition is met. May specify that oracle does not submit FSP (product remains unsettled), or provide alternative computation logic.","minLength":1,"title":"Fsp Resolution","type":"string"}},"required":["condition","fsp_resolution"],"title":"EdgeCase","type":"object"},"OutcomeSpace":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Base class for outcome spaces.\n\nDefines a family of related prediction products that share common resolution logic.\nAn outcome space specifies how to evaluate outcomes and determine the Final Settlement\nPrice (FSP) for products within its family. Products in the same family reference the\nsame outcome_space CID and differ only in their outcome_point values.","properties":{"base_case":{"$ref":"#/$defs/BaseCaseResolution","description":"Evaluation criteria for typical circumstances - how FSP is determined under normal conditions"},"description":{"description":"Human-readable description of what this outcome space represents (e.g., 'US Consumer Price Index', 'Who will win the 2028 Republican Presidential Nomination?')","minLength":1,"title":"Description","type":"string"},"edge_cases":{"description":"Exceptional circumstances with alternative FSP resolution logic. Evaluated in order; first matching condition applies.","items":{"$ref":"#/$defs/EdgeCase"},"title":"Edge Cases","type":"array"},"fsp_type":{"description":"Type of Final Settlement Price: 'scalar' for continuous values, 'binary' for 0/1 outcomes, 'ternary' for 0/0.5/1 outcomes","enum":["scalar","binary","ternary"],"title":"Fsp Type","type":"string"}},"required":["fsp_type","description","base_case"],"title":"OutcomeSpace","type":"object","version":"0.2.0"}},"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"allOf":[{"$ref":"#/$defs/OutcomeSpace"}],"description":"Base class for scalar outcome spaces.\n\nDefines outcome spaces that track continuous numeric values (as opposed to\ndiscrete binary outcomes). Scalar products can represent economic indicators,\nfinancial data, physical measurements, or any quantifiable metric.","properties":{"fsp_type":{"const":"scalar","description":"Type of Final Settlement Price: must be 'scalar' for scalar outcome spaces","title":"Fsp Type","type":"string"},"source_name":{"description":"Name of the original publisher or authoritative source of the data (e.g., 'Bureau of Labor Statistics', 'Federal Reserve', 'World Bank')","minLength":1,"title":"Source Name","type":"string"},"source_uri":{"description":"URL of the original publisher or authoritative source of the data","maxLength":2083,"minLength":1,"title":"Source Uri","type":"string"},"units":{"description":"Units represented by the scalar values (e.g., 'Percent (annualized)', 'USD', 'Index points', 'Basis points')","minLength":1,"title":"Units","type":"string"}},"required":["fsp_type","units","source_name","source_uri"],"title":"OutcomeSpaceScalar","type":"object","version":"0.2.0"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"$defs":{"OutcomePoint":{"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"description":"Base class for outcome points.\n\nDefines specific coordinates within an outcome space that identify a particular\nproduct instance. Outcome points specify the exact parameters that distinguish\none product from others in the same outcome space family.","properties":{"fsp_type":{"description":"Type of Final Settlement Price: 'scalar' for continuous values, 'binary' for 0/1 outcomes, 'ternary' for 0/0.5/1 outcomes","enum":["scalar","binary","ternary"],"title":"Fsp Type","type":"string"}},"required":["fsp_type"],"title":"OutcomePoint","type":"object","version":"0.2.0"}},"$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":true,"allOf":[{"$ref":"#/$defs/OutcomePoint"}],"description":"Discrete outcome for event outcome spaces.\n\nSpecifies which specific event outcome this binary or ternary prediction product represents.","properties":{"fsp_type":{"description":"Type of Final Settlement Price: 'binary' for 0/1 outcomes, 'ternary' for 0/0.5/1 outcomes","enum":["binary","ternary"],"title":"Fsp Type","type":"string"},"outcome":{"description":"The specific outcome being predicted (e.g., candidate name, yes/no answer)","minLength":1,"title":"Outcome","type":"string"}},"required":["fsp_type","outcome"],"title":"OutcomePointEvent","type":"object","version":"0.2.0"}
|