architect-py 5.0.0b3__py3-none-any.whl → 5.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.
Files changed (75) hide show
  1. architect_py/__init__.py +432 -5
  2. architect_py/async_client.py +77 -43
  3. architect_py/client.py +11 -4
  4. architect_py/client.pyi +504 -0
  5. architect_py/common_types/__init__.py +2 -1
  6. architect_py/common_types/time_in_force.py +94 -0
  7. architect_py/common_types/tradable_product.py +9 -0
  8. architect_py/graphql_client/__init__.py +1 -216
  9. architect_py/graphql_client/client.py +2 -1043
  10. architect_py/graphql_client/enums.py +0 -72
  11. architect_py/graphql_client/fragments.py +4 -152
  12. architect_py/grpc/__init__.py +0 -143
  13. architect_py/grpc/client.py +6 -1
  14. architect_py/grpc/models/Core/RestartCptyRequest.py +40 -0
  15. architect_py/grpc/models/Core/RestartCptyResponse.py +20 -0
  16. architect_py/grpc/models/Marketdata/Liquidation.py +0 -1
  17. architect_py/grpc/models/Marketdata/Ticker.py +14 -1
  18. architect_py/grpc/models/Marketdata/TickersRequest.py +38 -12
  19. architect_py/grpc/models/Marketdata/Trade.py +0 -1
  20. architect_py/grpc/models/Oms/Order.py +33 -24
  21. architect_py/grpc/models/Oms/PlaceOrderRequest.py +33 -24
  22. architect_py/grpc/models/__init__.py +113 -2
  23. architect_py/grpc/models/definitions.py +2 -32
  24. architect_py/grpc/utils.py +1 -4
  25. architect_py/tests/test_order_entry.py +2 -3
  26. architect_py/tests/test_orderflow.py +1 -1
  27. architect_py/utils/pandas.py +4 -3
  28. architect_py-5.1.0.dist-info/METADATA +66 -0
  29. {architect_py-5.0.0b3.dist-info → architect_py-5.1.0.dist-info}/RECORD +48 -67
  30. {architect_py-5.0.0b3.dist-info → architect_py-5.1.0.dist-info}/WHEEL +1 -1
  31. examples/book_subscription.py +1 -2
  32. examples/candles.py +1 -3
  33. examples/common.py +1 -2
  34. examples/external_cpty.py +2 -2
  35. examples/funding_rate_mean_reversion_algo.py +9 -6
  36. examples/order_sending.py +29 -9
  37. examples/stream_l1_marketdata.py +1 -2
  38. examples/stream_l2_marketdata.py +1 -2
  39. examples/trades.py +1 -2
  40. examples/tutorial_async.py +6 -8
  41. examples/tutorial_sync.py +6 -7
  42. scripts/add_imports_to_inits.py +146 -0
  43. scripts/correct_sync_interface.py +143 -0
  44. scripts/postprocess_grpc.py +57 -11
  45. scripts/preprocess_grpc_schema.py +2 -0
  46. scripts/prune_graphql_schema.py +187 -0
  47. architect_py/client_interface.py +0 -63
  48. architect_py/common_types/scalars.py +0 -25
  49. architect_py/graphql_client/cancel_all_orders_mutation.py +0 -17
  50. architect_py/graphql_client/cancel_order_mutation.py +0 -23
  51. architect_py/graphql_client/create_jwt.py +0 -17
  52. architect_py/graphql_client/get_account_history_query.py +0 -27
  53. architect_py/graphql_client/get_account_query.py +0 -23
  54. architect_py/graphql_client/get_account_summaries_query.py +0 -27
  55. architect_py/graphql_client/get_account_summary_query.py +0 -25
  56. architect_py/graphql_client/get_candle_snapshot_query.py +0 -27
  57. architect_py/graphql_client/get_fills_query.py +0 -69
  58. architect_py/graphql_client/get_historical_orders_query.py +0 -27
  59. architect_py/graphql_client/get_l_1_book_snapshot_query.py +0 -21
  60. architect_py/graphql_client/get_l_1_book_snapshots_query.py +0 -23
  61. architect_py/graphql_client/get_l_2_book_snapshot_query.py +0 -25
  62. architect_py/graphql_client/get_market_status_query.py +0 -25
  63. architect_py/graphql_client/get_open_orders_query.py +0 -25
  64. architect_py/graphql_client/list_accounts_query.py +0 -23
  65. architect_py/graphql_client/place_order_mutation.py +0 -23
  66. architect_py/graphql_client/subscribe_candles.py +0 -16
  67. architect_py/graphql_client/subscribe_orderflow.py +0 -100
  68. architect_py/graphql_client/subscribe_trades.py +0 -27
  69. architect_py/graphql_client/user_email_query.py +0 -17
  70. architect_py/internal_utils/__init__.py +0 -0
  71. architect_py/internal_utils/no_pandas.py +0 -3
  72. architect_py-5.0.0b3.dist-info/METADATA +0 -123
  73. scripts/generate_sync_interface.py +0 -226
  74. {architect_py-5.0.0b3.dist-info → architect_py-5.1.0.dist-info}/licenses/LICENSE +0 -0
  75. {architect_py-5.0.0b3.dist-info → architect_py-5.1.0.dist-info}/top_level.txt +0 -0
@@ -1,226 +0,0 @@
1
- import argparse
2
- import collections.abc
3
- import inspect
4
- import types
5
- from decimal import Decimal
6
- from enum import Enum
7
- from typing import Annotated, Any, Sequence, Union, get_args, get_origin
8
-
9
- from architect_py.async_client import AsyncClient
10
- from architect_py.graphql_client.base_model import UnsetType
11
-
12
-
13
- def format_type_hint_with_generics(type_hint) -> str:
14
- """
15
- Format a type hint to a string representation with support for generic types like list[str].
16
- """
17
-
18
- if type_hint == inspect.Parameter.empty:
19
- return "Any"
20
-
21
- origin = get_origin(type_hint)
22
-
23
- if origin is Annotated:
24
- annotated_args = get_args(type_hint)
25
- if annotated_args:
26
- return format_type_hint_with_generics(annotated_args[0])
27
- return "Any"
28
-
29
- # Handle `|` unions (Python 3.10+)
30
- if isinstance(
31
- type_hint, types.UnionType
32
- ): # `types.UnionType` represents `|` unions
33
- args = get_args(type_hint)
34
- if type(None) in args:
35
- if len(args) == 2:
36
- # Handle Optional[X]
37
- non_none_type = args[0] if args[1] is type(None) else args[1]
38
- return f"Optional[{format_type_hint_with_generics(non_none_type)}]"
39
- return (
40
- f"Union[{', '.join(format_type_hint_with_generics(arg) for arg in args)}]"
41
- )
42
-
43
- if origin is Union:
44
- args = get_args(type_hint)
45
- if type(None) in args:
46
- if len(args) == 2:
47
- # Handle Optional[X]
48
- non_none_type = args[0] if args[1] is type(None) else args[1]
49
- return f"Optional[{format_type_hint_with_generics(non_none_type)}]"
50
- return (
51
- f"Union[{', '.join(format_type_hint_with_generics(arg) for arg in args)}]"
52
- ).replace("NoneType", "None")
53
-
54
- elif origin in (Sequence, collections.abc.Sequence):
55
- args = get_args(type_hint)
56
- if args:
57
- return f"Sequence[{format_type_hint_with_generics(args[0])}]"
58
- return "Sequence[Any]"
59
-
60
- elif origin is list:
61
- args = get_args(type_hint)
62
- if args:
63
- return f"list[{format_type_hint_with_generics(args[0])}]"
64
- return "list[Any]"
65
-
66
- elif origin is dict:
67
- args = get_args(type_hint)
68
- if len(args) == 2:
69
- return f"dict[{format_type_hint_with_generics(args[0])}, {format_type_hint_with_generics(args[1])}]"
70
- return "dict[Any, Any]"
71
-
72
- elif origin is tuple:
73
- args = get_args(type_hint)
74
- if args:
75
- return f"tuple[{', '.join(format_type_hint_with_generics(arg) for arg in args)}]"
76
- return "tuple[Any, ...]"
77
-
78
- try:
79
- if type_hint.__module__ == "pandas" or type_hint.__module__.startswith(
80
- "pandas."
81
- ):
82
- return f"pd.{type_hint.__name__}"
83
- else:
84
- return type_hint.__name__
85
- except AttributeError:
86
- return str(type_hint)
87
-
88
-
89
- def autogenerate_protocol(cls, protocol_name: str) -> str:
90
- """
91
- Autogenerate a Protocol for the given class for use in static typing.
92
- Args:
93
- cls: The class to generate a Protocol for.
94
- protocol_name: The name of the Protocol to generate.
95
- Returns:
96
- A string representing the Protocol definition.
97
- """
98
- methods: dict[str, inspect.Signature] = {}
99
- method_decorators: dict[str, list[str]] = {}
100
- attributes: dict[str, Any] = {}
101
-
102
- # Inspect class members
103
- for name, member in inspect.getmembers(cls):
104
- if name.startswith("_"):
105
- continue
106
- if callable(member):
107
- # Collect methods
108
- signature = inspect.signature(member)
109
- methods[name] = signature
110
-
111
- raw_member = inspect.getattr_static(cls, name)
112
- decorators = []
113
- if isinstance(raw_member, staticmethod):
114
- decorators.append("@staticmethod")
115
- elif isinstance(raw_member, classmethod):
116
- decorators.append("@classmethod")
117
- method_decorators[name] = decorators
118
- elif not inspect.isroutine(member):
119
- # Collect attributes
120
- attributes[name] = getattr(cls, name, Any)
121
-
122
- def format_default(value) -> str:
123
- """
124
- Format the default value for parameters. Handles special types.
125
- """
126
- if isinstance(value, Enum):
127
- return f"{value.__class__.__name__}.{value.name}"
128
- elif isinstance(value, (int, float, str, bool, type(None))):
129
- return repr(value)
130
- elif isinstance(value, Decimal):
131
- return f"Decimal('{value}')"
132
- elif isinstance(value, UnsetType):
133
- return "UNSET"
134
- return type(value).__name__
135
-
136
- protocol_lines = [
137
- "# fmt: off\n",
138
- "# mypy: ignore-errors\n",
139
- "# Autogenerated from generate_sync_interface.py\n",
140
- "# If you are here for function definitions, please refer to architect_py/async_client.py",
141
- "# This file is so that the sync client has good type hinting",
142
- "# It is not used for anything else",
143
- "# For maintainers: ensure that the types in this file are correct for correct type hinting",
144
- "\n",
145
- # "from architect_py.grpc_client.definitions import *",
146
- "from typing import Any, Union",
147
- "from .graphql_client import *",
148
- "from .async_client import *",
149
- "from .grpc.models.definitions import *",
150
- f"class {protocol_name}:",
151
- ]
152
-
153
- # # Add attributes
154
- # for attr_name, attr_type in attributes.items():
155
- # protocol_lines.append(
156
- # f" {attr_name}: {format_type_hint_with_generics(attr_type)}"
157
- # )
158
-
159
- # Add methods
160
- for name, signature in methods.items():
161
- if any(
162
- keyword in name
163
- for keyword in ("subscribe", "stream", "unsubscribe", "connect")
164
- ):
165
- continue
166
-
167
- if "async" in str(signature).lower():
168
- continue
169
-
170
- # for decorators like @staticmethod and @classmethod
171
- if name in method_decorators:
172
- for deco in method_decorators[name]:
173
- protocol_lines.append(f" {deco}")
174
-
175
- params = []
176
- keyword_only = False
177
- for param_name, param in signature.parameters.items():
178
- if param_name == "self":
179
- params.append("self")
180
- continue
181
-
182
- param_type = format_type_hint_with_generics(param.annotation)
183
- if param.kind == inspect.Parameter.POSITIONAL_ONLY:
184
- params.append(f"{param_name}: {param_type}")
185
- elif param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD:
186
- if param.default != inspect.Parameter.empty:
187
- params.append(
188
- f"{param_name}: {param_type} = {format_default(param.default)}"
189
- )
190
- else:
191
- params.append(f"{param_name}: {param_type}")
192
- elif param.kind == inspect.Parameter.VAR_POSITIONAL:
193
- params.append(f"*{param_name}: {param_type}")
194
- elif param.kind == inspect.Parameter.KEYWORD_ONLY:
195
- if not keyword_only:
196
- params.append("*") # Indicate start of keyword-only arguments
197
- keyword_only = True
198
- if param.default != inspect.Parameter.empty:
199
- params.append(
200
- f"{param_name}: {param_type} = {format_default(param.default)}"
201
- )
202
- else:
203
- params.append(f"{param_name}: {param_type}")
204
- elif param.kind == inspect.Parameter.VAR_KEYWORD:
205
- params.append(f"**{param_name}: {param_type}")
206
-
207
- params_str = ", ".join(params)
208
- return_type = format_type_hint_with_generics(signature.return_annotation)
209
- protocol_lines.append(f" def {name}({params_str}) -> {return_type}: ...")
210
-
211
- return "\n".join(protocol_lines)
212
-
213
-
214
- if __name__ == "__main__":
215
- parser = argparse.ArgumentParser(description="Process gRPC service definitions")
216
- parser.add_argument(
217
- "--file_path",
218
- type=str,
219
- default="architect_py/grpc_client",
220
- help="Path to the Python folder with the gRPC service definitions",
221
- )
222
- args = parser.parse_args()
223
- protocol: str = autogenerate_protocol(AsyncClient, "ClientProtocol")
224
-
225
- with open(args.file_path, "w") as f:
226
- f.write(protocol)