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:

  1. Initialize Client: Create a client with your API key
  2. Start Session: Call start_session() to create a new session
  3. Get Portal URL: Use get_portal_url() to get the authentication URL
  4. User Authentication: User visits the portal URL and connects their broker
  5. 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

  1. Store session IDs: Keep track of session IDs for authenticated users
  2. Handle session expiration: Implement proper session refresh logic
  3. Use pagination: For large datasets to avoid memory issues
  4. Implement error handling: Catch and handle all error types appropriately
  5. Cache static data: Store broker lists and other infrequently changing data

Next Steps

  1. Explore Available Methods: Check out the Available Methods page for complete API reference
  2. Learn about Theming: Customize the authentication portal with Portal Theming