finatic-server-python 0.1.5__tar.gz → 0.2.1__tar.gz

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 (27) hide show
  1. finatic_server_python-0.2.1/PKG-INFO +489 -0
  2. finatic_server_python-0.2.1/README.md +451 -0
  3. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/pyproject.toml +2 -2
  4. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/__init__.py +8 -0
  5. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/core/api_client.py +767 -620
  6. finatic_server_python-0.2.1/src/finatic_server/core/client.py +1044 -0
  7. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/types/__init__.py +30 -0
  8. finatic_server_python-0.2.1/src/finatic_server/types/broker.py +381 -0
  9. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/types/orders.py +34 -18
  10. finatic_server_python-0.2.1/src/finatic_server/types/webhook.py +21 -0
  11. finatic_server_python-0.2.1/src/finatic_server_python.egg-info/PKG-INFO +489 -0
  12. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server_python.egg-info/SOURCES.txt +1 -0
  13. finatic_server_python-0.1.5/PKG-INFO +0 -330
  14. finatic_server_python-0.1.5/README.md +0 -292
  15. finatic_server_python-0.1.5/src/finatic_server/core/client.py +0 -1263
  16. finatic_server_python-0.1.5/src/finatic_server/types/broker.py +0 -186
  17. finatic_server_python-0.1.5/src/finatic_server_python.egg-info/PKG-INFO +0 -330
  18. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/setup.cfg +0 -0
  19. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/core/__init__.py +0 -0
  20. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/types/auth.py +0 -0
  21. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/types/common.py +0 -0
  22. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/types/portfolio.py +0 -0
  23. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/utils/__init__.py +0 -0
  24. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server/utils/errors.py +0 -0
  25. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server_python.egg-info/dependency_links.txt +0 -0
  26. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server_python.egg-info/requires.txt +0 -0
  27. {finatic_server_python-0.1.5 → finatic_server_python-0.2.1}/src/finatic_server_python.egg-info/top_level.txt +0 -0
@@ -0,0 +1,489 @@
1
+ Metadata-Version: 2.4
2
+ Name: finatic-server-python
3
+ Version: 0.2.1
4
+ Summary: Python SDK for Finatic Server API
5
+ Author-email: Finatic <support@finatic.dev>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/finatic/finatic-server-python
8
+ Project-URL: Documentation, https://docs.finatic.com/python
9
+ Project-URL: Repository, https://github.com/finatic/finatic-server-python
10
+ Project-URL: Issues, https://github.com/finatic/finatic-server-python/issues
11
+ Keywords: finatic,trading,finance,api,sdk
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Office/Business :: Financial
23
+ Requires-Python: >=3.8.1
24
+ Description-Content-Type: text/markdown
25
+ Requires-Dist: requests>=2.28.0
26
+ Requires-Dist: aiohttp>=3.8.0
27
+ Requires-Dist: pydantic>=2.0.0
28
+ Requires-Dist: typing-extensions>=4.0.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
31
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
33
+ Requires-Dist: black>=23.0.0; extra == "dev"
34
+ Requires-Dist: isort>=5.12.0; extra == "dev"
35
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
36
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
37
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
38
+
39
+ # Finatic Server Python SDK
40
+
41
+ A comprehensive Python SDK for integrating with Finatic's server-side trading and portfolio management APIs.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ pip install finatic-server-python
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ```python
52
+ import asyncio
53
+ from finatic_server import FinaticServerClient
54
+
55
+ async def main():
56
+ # Initialize with API key
57
+ client = FinaticServerClient("your-api-key")
58
+
59
+ # Start session
60
+ await client.start_session()
61
+
62
+ # Get portal URL for user authentication
63
+ portal_url = await client.get_portal_url()
64
+ print(f"User should visit: {portal_url}")
65
+
66
+ # After user completes authentication in portal
67
+ # User is now authenticated
68
+ print(f"Authenticated user: {client.get_user_id()}")
69
+
70
+ # Get portfolio data
71
+ brokers = await client.get_broker_list()
72
+ print(f"Available brokers: {len(brokers)}")
73
+
74
+ # Get all orders across all pages
75
+ all_orders = await client.get_all_orders()
76
+ print(f"Total orders: {len(all_orders)}")
77
+
78
+ # Run the example
79
+ asyncio.run(main())
80
+ ```
81
+
82
+ ## Authentication Flow
83
+
84
+ The SDK supports two authentication methods:
85
+
86
+ ### 1. Portal Authentication (User completes auth in browser)
87
+
88
+ ```python
89
+ client = FinaticServerClient("your-api-key")
90
+
91
+ # Start session
92
+ await client.start_session()
93
+
94
+ # Get portal URL for user authentication
95
+ portal_url = await client.get_portal_url()
96
+ print(f"User should visit: {portal_url}")
97
+
98
+ # After user completes authentication in portal
99
+ # User is now authenticated
100
+ print(f"User ID: {client.get_user_id()}")
101
+
102
+ # Now you can make authenticated requests
103
+ brokers = await client.get_broker_list()
104
+ ```
105
+
106
+ ### Server: Get one-time token for Client SDK (additive helper)
107
+
108
+ ```python
109
+ async with FinaticServerClient("your-api-key") as client:
110
+ # Fetch a fresh one-time token without modifying the current server session
111
+ one_time_token = await client.get_token()
112
+
113
+ # Pass this token to the Client SDK on the frontend to start its session
114
+ # e.g., FinaticClient.init({ "token": one_time_token })
115
+ ```
116
+
117
+ Notes:
118
+
119
+ - Requires the client to be initialized (use the async context manager or call **aenter**()).
120
+ - Does not call `/session/start` and does not change `session_id`/`company_id` state.
121
+ - Safe to call multiple times; each call returns a new short-lived token.
122
+
123
+ ### 2. Direct Authentication (Server-side with known user ID)
124
+
125
+ ```python
126
+ client = FinaticServerClient("your-api-key")
127
+
128
+ # Start session with user ID (automatically authenticates)
129
+ await client.start_session(user_id="user123")
130
+
131
+ # Now you can make authenticated requests immediately
132
+ brokers = await client.get_broker_list()
133
+ ```
134
+
135
+ ## Core Features
136
+
137
+ - **API Key Authentication**: Secure server-side authentication
138
+ - **Portal Integration**: Get portal URLs for user authentication with optional theming
139
+ - **Automatic Token Management**: Handles access/refresh tokens automatically
140
+ - **Pagination Support**: Built-in pagination for large datasets
141
+ - **Type-safe API**: Full Pydantic model support
142
+ - **Async/await Support**: Non-blocking operations
143
+ - **Comprehensive Error Handling**: Detailed error types
144
+ - **Convenience Methods**: Helper methods for common data filtering
145
+ - **Asset-Specific Orders**: Simplified order placement for different asset types
146
+
147
+ ## API Reference
148
+
149
+ ### Initialization
150
+
151
+ ```python
152
+ client = FinaticServerClient(
153
+ api_key="your-api-key",
154
+ base_url="https://api.finatic.dev", # Optional
155
+ device_info={ # Optional
156
+ "ip_address": "192.168.1.100",
157
+ "user_agent": "MyApp/1.0.0",
158
+ },
159
+ timeout=30 # Optional
160
+ )
161
+ ```
162
+
163
+ ### Authentication
164
+
165
+ ```python
166
+ # Start session
167
+ await client.start_session()
168
+
169
+ # Start session with user ID (direct auth)
170
+ await client.start_session(user_id="user123")
171
+
172
+ # Check authentication status
173
+ is_authenticated = client.is_authenticated()
174
+
175
+ # Get user information
176
+ user_id = client.get_user_id()
177
+ session_id = client.get_session_id()
178
+ company_id = client.get_company_id()
179
+ ```
180
+
181
+ ### Portal Management
182
+
183
+ ```python
184
+ # Get basic portal URL
185
+ portal_url = await client.get_portal_url()
186
+
187
+ # Get portal URL with theming
188
+ portal_url = await client.get_portal_url(
189
+ theme={"primary_color": "#007bff", "logo_url": "https://example.com/logo.png"},
190
+ brokers=["robinhood", "tasty_trade"],
191
+ email="user@example.com"
192
+ )
193
+ ```
194
+
195
+ ### Broker Data Access
196
+
197
+ ```python
198
+ # Get broker information
199
+ brokers = await client.get_broker_list()
200
+ connections = await client.get_broker_connections()
201
+
202
+ # Get accounts with pagination
203
+ accounts = await client.get_accounts(page=1, per_page=100)
204
+ all_accounts = await client.get_all_accounts()
205
+
206
+ # Get orders with pagination
207
+ orders = await client.get_orders(page=1, per_page=100)
208
+ all_orders = await client.get_all_orders()
209
+
210
+ # Get positions with pagination
211
+ positions = await client.get_positions(page=1, per_page=100)
212
+ all_positions = await client.get_all_positions()
213
+
214
+ # Get balances with pagination
215
+ balances = await client.get_balances(page=1, per_page=100)
216
+ all_balances = await client.get_all_balances()
217
+ ```
218
+
219
+ ### Convenience Filter Methods
220
+
221
+ ```python
222
+ # Get filtered data
223
+ open_positions = await client.get_open_positions()
224
+ filled_orders = await client.get_filled_orders()
225
+ pending_orders = await client.get_pending_orders()
226
+ active_accounts = await client.get_active_accounts()
227
+
228
+ # Get data by symbol
229
+ aapl_orders = await client.get_orders_by_symbol("AAPL")
230
+ aapl_positions = await client.get_positions_by_symbol("AAPL")
231
+
232
+ # Get data by broker
233
+ robinhood_orders = await client.get_orders_by_broker("robinhood")
234
+ robinhood_positions = await client.get_positions_by_broker("robinhood")
235
+ ```
236
+
237
+ ### Trading Operations
238
+
239
+ #### General Order Placement
240
+
241
+ ```python
242
+ from finatic_server.types.orders import BrokerOrderParams
243
+
244
+ # Place a market order
245
+ order_params = BrokerOrderParams(
246
+ broker="robinhood",
247
+ order_type="Market",
248
+ asset_type="equity",
249
+ action="Buy",
250
+ time_in_force="day",
251
+ account_number="123456789",
252
+ symbol="AAPL",
253
+ order_qty=10
254
+ )
255
+
256
+ response = await client.place_order(order_params)
257
+ ```
258
+
259
+ #### Asset-Specific Order Methods
260
+
261
+ ##### Stock Orders
262
+
263
+ ```python
264
+ # Stock market order
265
+ response = await client.place_stock_market_order(
266
+ symbol="AAPL",
267
+ quantity=10,
268
+ side="buy",
269
+ broker="robinhood",
270
+ account_number="123456789"
271
+ )
272
+
273
+ # Stock limit order
274
+ response = await client.place_stock_limit_order(
275
+ symbol="AAPL",
276
+ quantity=10,
277
+ side="buy",
278
+ price=150.00,
279
+ time_in_force="gtc",
280
+ broker="robinhood",
281
+ account_number="123456789"
282
+ )
283
+
284
+ # Stock stop order
285
+ response = await client.place_stock_stop_order(
286
+ symbol="AAPL",
287
+ quantity=10,
288
+ side="sell",
289
+ stop_price=140.00,
290
+ time_in_force="gtc",
291
+ broker="robinhood",
292
+ account_number="123456789"
293
+ )
294
+ ```
295
+
296
+ ##### Crypto Orders
297
+
298
+ ```python
299
+ # Crypto market order
300
+ response = await client.place_crypto_market_order(
301
+ symbol="BTC-USD",
302
+ quantity=0.1,
303
+ side="buy",
304
+ broker="coinbase",
305
+ account_number="123456789"
306
+ )
307
+
308
+ # Crypto limit order
309
+ response = await client.place_crypto_limit_order(
310
+ symbol="BTC-USD",
311
+ quantity=0.1,
312
+ side="buy",
313
+ price=50000.00,
314
+ time_in_force="gtc",
315
+ broker="coinbase",
316
+ account_number="123456789"
317
+ )
318
+ ```
319
+
320
+ ##### Options Orders
321
+
322
+ ```python
323
+ # Options market order
324
+ response = await client.place_options_market_order(
325
+ symbol="AAPL240315C00150000",
326
+ quantity=1,
327
+ side="buy",
328
+ broker="tasty_trade",
329
+ account_number="123456789"
330
+ )
331
+
332
+ # Options limit order
333
+ response = await client.place_options_limit_order(
334
+ symbol="AAPL240315C00150000",
335
+ quantity=1,
336
+ side="buy",
337
+ price=5.00,
338
+ time_in_force="gtc",
339
+ broker="tasty_trade",
340
+ account_number="123456789"
341
+ )
342
+ ```
343
+
344
+ ##### Futures Orders
345
+
346
+ ```python
347
+ # Futures market order
348
+ response = await client.place_futures_market_order(
349
+ symbol="ES",
350
+ quantity=1,
351
+ side="buy",
352
+ broker="ninja_trader",
353
+ account_number="123456789"
354
+ )
355
+
356
+ # Futures limit order
357
+ response = await client.place_futures_limit_order(
358
+ symbol="ES",
359
+ quantity=1,
360
+ side="buy",
361
+ price=4500.00,
362
+ time_in_force="gtc",
363
+ broker="ninja_trader",
364
+ account_number="123456789"
365
+ )
366
+ ```
367
+
368
+ #### Order Management
369
+
370
+ ```python
371
+ # Cancel an order
372
+ response = await client.cancel_order(
373
+ order_id="order-123",
374
+ broker="robinhood",
375
+ connection_id="connection-456"
376
+ )
377
+
378
+ # Modify an order
379
+ response = await client.modify_order(
380
+ order_id="order-123",
381
+ modifications={"price": 155.00, "quantity": 5},
382
+ broker="robinhood",
383
+ connection_id="connection-456"
384
+ )
385
+ ```
386
+
387
+ ### Broker Management
388
+
389
+ ```python
390
+ # Disconnect a company from broker
391
+ response = await client.disconnect_company("connection-123")
392
+ ```
393
+
394
+ ### Error Handling
395
+
396
+ ```python
397
+ from finatic_server.utils.errors import AuthenticationError, ApiError, ValidationError
398
+
399
+ try:
400
+ orders = await client.get_orders()
401
+ except AuthenticationError as e:
402
+ print(f"Authentication failed: {e}")
403
+ except ValidationError as e:
404
+ print(f"Invalid request: {e}")
405
+ except ApiError as e:
406
+ print(f"API error: {e}")
407
+ ```
408
+
409
+ ### Context Manager Usage
410
+
411
+ ```python
412
+ async with FinaticServerClient("your-api-key") as client:
413
+ await client.start_session()
414
+ brokers = await client.get_broker_list()
415
+ # Client automatically closes when exiting context
416
+ ```
417
+
418
+ ### Cleanup
419
+
420
+ ```python
421
+ # Close the client and cleanup resources
422
+ await client.close()
423
+ ```
424
+
425
+ ## Advanced Usage
426
+
427
+ ### Custom Filters
428
+
429
+ ```python
430
+ from finatic_server.types import BrokerDataOptions, OrdersFilter
431
+
432
+ # Get orders with custom filters
433
+ orders = await client.get_orders(
434
+ page=1,
435
+ per_page=50,
436
+ options=BrokerDataOptions(
437
+ broker_name="robinhood",
438
+ account_id="123456789"
439
+ ),
440
+ filters=OrdersFilter(
441
+ status="filled",
442
+ symbol="AAPL"
443
+ )
444
+ )
445
+ ```
446
+
447
+ ### Pagination Navigation
448
+
449
+ ```python
450
+ # Get paginated results with navigation
451
+ orders_page = await client.get_orders(page=1, per_page=100)
452
+
453
+ # Navigate through pages
454
+ if orders_page.has_next:
455
+ next_page = await orders_page.next_page()
456
+
457
+ if orders_page.has_previous:
458
+ prev_page = await orders_page.previous_page()
459
+ ```
460
+
461
+ ## Type Definitions
462
+
463
+ The SDK includes comprehensive type definitions for all data structures:
464
+
465
+ - `BrokerOrder`: Order information
466
+ - `BrokerPosition`: Position information
467
+ - `BrokerAccount`: Account information
468
+ - `BrokerBalance`: Balance information
469
+ - `BrokerInfo`: Broker information
470
+ - `BrokerConnection`: Connection information
471
+ - `OrderResponse`: Order operation responses
472
+ - `PaginatedResult`: Paginated data responses
473
+
474
+ ## Error Types
475
+
476
+ - `AuthenticationError`: Authentication failures
477
+ - `ApiError`: API request failures
478
+ - `ValidationError`: Invalid request parameters
479
+ - `ConnectionError`: Network connectivity issues
480
+
481
+ ## Requirements
482
+
483
+ - Python 3.8+
484
+ - aiohttp
485
+ - pydantic
486
+
487
+ ## License
488
+
489
+ MIT License