Getting Started with Finatic Server SDK
The Finatic Server SDK provides comprehensive broker connectivity, data access, and trading capabilities for your backend applications.
Installation
Install the SDK
pip install finatic-server
# or
pip install finatic-server[dev] # includes development dependencies
Basic Setup
Initialize and Authenticate
from finatic_server import FinaticServerClient
# Initialize the client
client = FinaticServerClient("your-api-key")
# Start a session for user authentication
await client.start_session()
# Get portal URL for user to authenticate
portal_url = await client.get_portal_url()
print(f"User should visit: {portal_url}")
# After user completes authentication
user_info = await client.get_session_user()
print(f"User ID: {user_info['user_id']}")
Authentication Flow
The Server SDK uses a session-based authentication flow:
- Initialize Client: Create a client with your API key
- Start Session: Call
start_session()
to create a new session - Get Portal URL: Use
get_portal_url()
to get the authentication URL - User Authentication: User visits the portal URL and connects their broker
- Get User Info: Use
get_session_user()
to get the authenticated user's information
Data Access
Once authenticated, you can access broker data:
Get Broker Information
# Get available brokers
brokers = await client.get_broker_list()
print(f"Available brokers: {len(brokers)}")
# Get user's broker connections
connections = await client.get_broker_connections()
print(f"User connections: {len(connections)}")
Trading Operations
Place Orders
# Market Order
response = await client.place_stock_market_order(
symbol='AAPL',
quantity=10,
side='buy',
broker='robinhood',
account_number='123456789'
)
# Limit Order
response = await client.place_stock_limit_order(
symbol='TSLA',
quantity=5,
side='sell',
price=250.00,
time_in_force='gtc',
broker='tasty_trade'
)
Best Practices
- Store session IDs: Keep track of session IDs for authenticated users
- Handle session expiration: Implement proper session refresh logic
- Use pagination: For large datasets to avoid memory issues
- Implement error handling: Catch and handle all error types appropriately
- Cache static data: Store broker lists and other infrequently changing data
Next Steps
- Explore Available Methods: Check out the Available Methods page for complete API reference
- Learn about Theming: Customize the authentication portal with Portal Theming