finatic-server-python 0.1.4__tar.gz → 0.1.6__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 (26) hide show
  1. finatic_server_python-0.1.6/PKG-INFO +472 -0
  2. finatic_server_python-0.1.6/README.md +434 -0
  3. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/pyproject.toml +2 -2
  4. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/__init__.py +8 -0
  5. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/core/api_client.py +653 -620
  6. finatic_server_python-0.1.6/src/finatic_server/core/client.py +1028 -0
  7. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/types/__init__.py +10 -0
  8. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/types/broker.py +61 -25
  9. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/types/orders.py +34 -18
  10. finatic_server_python-0.1.6/src/finatic_server/types/webhook.py +21 -0
  11. finatic_server_python-0.1.6/src/finatic_server_python.egg-info/PKG-INFO +472 -0
  12. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server_python.egg-info/SOURCES.txt +1 -0
  13. finatic_server_python-0.1.4/PKG-INFO +0 -330
  14. finatic_server_python-0.1.4/README.md +0 -292
  15. finatic_server_python-0.1.4/src/finatic_server/core/client.py +0 -1263
  16. finatic_server_python-0.1.4/src/finatic_server_python.egg-info/PKG-INFO +0 -330
  17. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/setup.cfg +0 -0
  18. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/core/__init__.py +0 -0
  19. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/types/auth.py +0 -0
  20. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/types/common.py +0 -0
  21. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/types/portfolio.py +0 -0
  22. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/utils/__init__.py +0 -0
  23. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server/utils/errors.py +0 -0
  24. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server_python.egg-info/dependency_links.txt +0 -0
  25. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server_python.egg-info/requires.txt +0 -0
  26. {finatic_server_python-0.1.4 → finatic_server_python-0.1.6}/src/finatic_server_python.egg-info/top_level.txt +0 -0
@@ -0,0 +1,472 @@
1
+ Metadata-Version: 2.4
2
+ Name: finatic-server-python
3
+ Version: 0.1.6
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
+ ### 2. Direct Authentication (Server-side with known user ID)
107
+
108
+ ```python
109
+ client = FinaticServerClient("your-api-key")
110
+
111
+ # Start session with user ID (automatically authenticates)
112
+ await client.start_session(user_id="user123")
113
+
114
+ # Now you can make authenticated requests immediately
115
+ brokers = await client.get_broker_list()
116
+ ```
117
+
118
+ ## Core Features
119
+
120
+ - **API Key Authentication**: Secure server-side authentication
121
+ - **Portal Integration**: Get portal URLs for user authentication with optional theming
122
+ - **Automatic Token Management**: Handles access/refresh tokens automatically
123
+ - **Pagination Support**: Built-in pagination for large datasets
124
+ - **Type-safe API**: Full Pydantic model support
125
+ - **Async/await Support**: Non-blocking operations
126
+ - **Comprehensive Error Handling**: Detailed error types
127
+ - **Convenience Methods**: Helper methods for common data filtering
128
+ - **Asset-Specific Orders**: Simplified order placement for different asset types
129
+
130
+ ## API Reference
131
+
132
+ ### Initialization
133
+
134
+ ```python
135
+ client = FinaticServerClient(
136
+ api_key="your-api-key",
137
+ base_url="https://api.finatic.dev", # Optional
138
+ device_info={ # Optional
139
+ "ip_address": "192.168.1.100",
140
+ "user_agent": "MyApp/1.0.0",
141
+ },
142
+ timeout=30 # Optional
143
+ )
144
+ ```
145
+
146
+ ### Authentication
147
+
148
+ ```python
149
+ # Start session
150
+ await client.start_session()
151
+
152
+ # Start session with user ID (direct auth)
153
+ await client.start_session(user_id="user123")
154
+
155
+ # Check authentication status
156
+ is_authenticated = client.is_authenticated()
157
+
158
+ # Get user information
159
+ user_id = client.get_user_id()
160
+ session_id = client.get_session_id()
161
+ company_id = client.get_company_id()
162
+ ```
163
+
164
+ ### Portal Management
165
+
166
+ ```python
167
+ # Get basic portal URL
168
+ portal_url = await client.get_portal_url()
169
+
170
+ # Get portal URL with theming
171
+ portal_url = await client.get_portal_url(
172
+ theme={"primary_color": "#007bff", "logo_url": "https://example.com/logo.png"},
173
+ brokers=["robinhood", "tasty_trade"],
174
+ email="user@example.com"
175
+ )
176
+ ```
177
+
178
+ ### Broker Data Access
179
+
180
+ ```python
181
+ # Get broker information
182
+ brokers = await client.get_broker_list()
183
+ connections = await client.get_broker_connections()
184
+
185
+ # Get accounts with pagination
186
+ accounts = await client.get_accounts(page=1, per_page=100)
187
+ all_accounts = await client.get_all_accounts()
188
+
189
+ # Get orders with pagination
190
+ orders = await client.get_orders(page=1, per_page=100)
191
+ all_orders = await client.get_all_orders()
192
+
193
+ # Get positions with pagination
194
+ positions = await client.get_positions(page=1, per_page=100)
195
+ all_positions = await client.get_all_positions()
196
+
197
+ # Get balances with pagination
198
+ balances = await client.get_balances(page=1, per_page=100)
199
+ all_balances = await client.get_all_balances()
200
+ ```
201
+
202
+ ### Convenience Filter Methods
203
+
204
+ ```python
205
+ # Get filtered data
206
+ open_positions = await client.get_open_positions()
207
+ filled_orders = await client.get_filled_orders()
208
+ pending_orders = await client.get_pending_orders()
209
+ active_accounts = await client.get_active_accounts()
210
+
211
+ # Get data by symbol
212
+ aapl_orders = await client.get_orders_by_symbol("AAPL")
213
+ aapl_positions = await client.get_positions_by_symbol("AAPL")
214
+
215
+ # Get data by broker
216
+ robinhood_orders = await client.get_orders_by_broker("robinhood")
217
+ robinhood_positions = await client.get_positions_by_broker("robinhood")
218
+ ```
219
+
220
+ ### Trading Operations
221
+
222
+ #### General Order Placement
223
+
224
+ ```python
225
+ from finatic_server.types.orders import BrokerOrderParams
226
+
227
+ # Place a market order
228
+ order_params = BrokerOrderParams(
229
+ broker="robinhood",
230
+ order_type="Market",
231
+ asset_type="equity",
232
+ action="Buy",
233
+ time_in_force="day",
234
+ account_number="123456789",
235
+ symbol="AAPL",
236
+ order_qty=10
237
+ )
238
+
239
+ response = await client.place_order(order_params)
240
+ ```
241
+
242
+ #### Asset-Specific Order Methods
243
+
244
+ ##### Stock Orders
245
+
246
+ ```python
247
+ # Stock market order
248
+ response = await client.place_stock_market_order(
249
+ symbol="AAPL",
250
+ quantity=10,
251
+ side="buy",
252
+ broker="robinhood",
253
+ account_number="123456789"
254
+ )
255
+
256
+ # Stock limit order
257
+ response = await client.place_stock_limit_order(
258
+ symbol="AAPL",
259
+ quantity=10,
260
+ side="buy",
261
+ price=150.00,
262
+ time_in_force="gtc",
263
+ broker="robinhood",
264
+ account_number="123456789"
265
+ )
266
+
267
+ # Stock stop order
268
+ response = await client.place_stock_stop_order(
269
+ symbol="AAPL",
270
+ quantity=10,
271
+ side="sell",
272
+ stop_price=140.00,
273
+ time_in_force="gtc",
274
+ broker="robinhood",
275
+ account_number="123456789"
276
+ )
277
+ ```
278
+
279
+ ##### Crypto Orders
280
+
281
+ ```python
282
+ # Crypto market order
283
+ response = await client.place_crypto_market_order(
284
+ symbol="BTC-USD",
285
+ quantity=0.1,
286
+ side="buy",
287
+ broker="coinbase",
288
+ account_number="123456789"
289
+ )
290
+
291
+ # Crypto limit order
292
+ response = await client.place_crypto_limit_order(
293
+ symbol="BTC-USD",
294
+ quantity=0.1,
295
+ side="buy",
296
+ price=50000.00,
297
+ time_in_force="gtc",
298
+ broker="coinbase",
299
+ account_number="123456789"
300
+ )
301
+ ```
302
+
303
+ ##### Options Orders
304
+
305
+ ```python
306
+ # Options market order
307
+ response = await client.place_options_market_order(
308
+ symbol="AAPL240315C00150000",
309
+ quantity=1,
310
+ side="buy",
311
+ broker="tasty_trade",
312
+ account_number="123456789"
313
+ )
314
+
315
+ # Options limit order
316
+ response = await client.place_options_limit_order(
317
+ symbol="AAPL240315C00150000",
318
+ quantity=1,
319
+ side="buy",
320
+ price=5.00,
321
+ time_in_force="gtc",
322
+ broker="tasty_trade",
323
+ account_number="123456789"
324
+ )
325
+ ```
326
+
327
+ ##### Futures Orders
328
+
329
+ ```python
330
+ # Futures market order
331
+ response = await client.place_futures_market_order(
332
+ symbol="ES",
333
+ quantity=1,
334
+ side="buy",
335
+ broker="ninja_trader",
336
+ account_number="123456789"
337
+ )
338
+
339
+ # Futures limit order
340
+ response = await client.place_futures_limit_order(
341
+ symbol="ES",
342
+ quantity=1,
343
+ side="buy",
344
+ price=4500.00,
345
+ time_in_force="gtc",
346
+ broker="ninja_trader",
347
+ account_number="123456789"
348
+ )
349
+ ```
350
+
351
+ #### Order Management
352
+
353
+ ```python
354
+ # Cancel an order
355
+ response = await client.cancel_order(
356
+ order_id="order-123",
357
+ broker="robinhood",
358
+ connection_id="connection-456"
359
+ )
360
+
361
+ # Modify an order
362
+ response = await client.modify_order(
363
+ order_id="order-123",
364
+ modifications={"price": 155.00, "quantity": 5},
365
+ broker="robinhood",
366
+ connection_id="connection-456"
367
+ )
368
+ ```
369
+
370
+ ### Broker Management
371
+
372
+ ```python
373
+ # Disconnect a company from broker
374
+ response = await client.disconnect_company("connection-123")
375
+ ```
376
+
377
+ ### Error Handling
378
+
379
+ ```python
380
+ from finatic_server.utils.errors import AuthenticationError, ApiError, ValidationError
381
+
382
+ try:
383
+ orders = await client.get_orders()
384
+ except AuthenticationError as e:
385
+ print(f"Authentication failed: {e}")
386
+ except ValidationError as e:
387
+ print(f"Invalid request: {e}")
388
+ except ApiError as e:
389
+ print(f"API error: {e}")
390
+ ```
391
+
392
+ ### Context Manager Usage
393
+
394
+ ```python
395
+ async with FinaticServerClient("your-api-key") as client:
396
+ await client.start_session()
397
+ brokers = await client.get_broker_list()
398
+ # Client automatically closes when exiting context
399
+ ```
400
+
401
+ ### Cleanup
402
+
403
+ ```python
404
+ # Close the client and cleanup resources
405
+ await client.close()
406
+ ```
407
+
408
+ ## Advanced Usage
409
+
410
+ ### Custom Filters
411
+
412
+ ```python
413
+ from finatic_server.types import BrokerDataOptions, OrdersFilter
414
+
415
+ # Get orders with custom filters
416
+ orders = await client.get_orders(
417
+ page=1,
418
+ per_page=50,
419
+ options=BrokerDataOptions(
420
+ broker_name="robinhood",
421
+ account_id="123456789"
422
+ ),
423
+ filters=OrdersFilter(
424
+ status="filled",
425
+ symbol="AAPL"
426
+ )
427
+ )
428
+ ```
429
+
430
+ ### Pagination Navigation
431
+
432
+ ```python
433
+ # Get paginated results with navigation
434
+ orders_page = await client.get_orders(page=1, per_page=100)
435
+
436
+ # Navigate through pages
437
+ if orders_page.has_next:
438
+ next_page = await orders_page.next_page()
439
+
440
+ if orders_page.has_previous:
441
+ prev_page = await orders_page.previous_page()
442
+ ```
443
+
444
+ ## Type Definitions
445
+
446
+ The SDK includes comprehensive type definitions for all data structures:
447
+
448
+ - `BrokerOrder`: Order information
449
+ - `BrokerPosition`: Position information
450
+ - `BrokerAccount`: Account information
451
+ - `BrokerBalance`: Balance information
452
+ - `BrokerInfo`: Broker information
453
+ - `BrokerConnection`: Connection information
454
+ - `OrderResponse`: Order operation responses
455
+ - `PaginatedResult`: Paginated data responses
456
+
457
+ ## Error Types
458
+
459
+ - `AuthenticationError`: Authentication failures
460
+ - `ApiError`: API request failures
461
+ - `ValidationError`: Invalid request parameters
462
+ - `ConnectionError`: Network connectivity issues
463
+
464
+ ## Requirements
465
+
466
+ - Python 3.8+
467
+ - aiohttp
468
+ - pydantic
469
+
470
+ ## License
471
+
472
+ MIT License