Lux Docs
Regulated

Provider Integration

Connect to 16+ trading venues via the broker provider interface

The luxfi/broker provider system abstracts trading venues behind a unified interface. Each provider implements the same Provider interface, and envconfig.RegisterFromEnv() automatically registers every provider that has credentials in the environment.

The Provider Interface

Every broker backend implements this core interface:

type Provider interface {
    Name() string

    // Accounts
    CreateAccount(ctx context.Context, req *types.CreateAccountRequest) (*types.Account, error)
    GetAccount(ctx context.Context, providerAccountID string) (*types.Account, error)
    ListAccounts(ctx context.Context) ([]*types.Account, error)

    // Portfolio
    GetPortfolio(ctx context.Context, providerAccountID string) (*types.Portfolio, error)

    // Orders
    CreateOrder(ctx context.Context, providerAccountID string, req *types.CreateOrderRequest) (*types.Order, error)
    ListOrders(ctx context.Context, providerAccountID string) ([]*types.Order, error)
    GetOrder(ctx context.Context, providerAccountID, providerOrderID string) (*types.Order, error)
    CancelOrder(ctx context.Context, providerAccountID, providerOrderID string) error

    // Transfers
    CreateTransfer(ctx context.Context, providerAccountID string, req *types.CreateTransferRequest) (*types.Transfer, error)
    ListTransfers(ctx context.Context, providerAccountID string) ([]*types.Transfer, error)

    // Banking
    CreateBankRelationship(ctx context.Context, providerAccountID string, ownerName, accountType, accountNumber, routingNumber string) (*types.BankRelationship, error)
    ListBankRelationships(ctx context.Context, providerAccountID string) ([]*types.BankRelationship, error)

    // Assets & Market Data
    ListAssets(ctx context.Context, class string) ([]*types.Asset, error)
    GetAsset(ctx context.Context, symbolOrID string) (*types.Asset, error)
    GetSnapshot(ctx context.Context, symbol string) (*types.MarketSnapshot, error)
    GetSnapshots(ctx context.Context, symbols []string) (map[string]*types.MarketSnapshot, error)
    GetBars(ctx context.Context, symbol, timeframe, start, end string, limit int) ([]*types.Bar, error)
    GetLatestTrades(ctx context.Context, symbols []string) (map[string]*types.Trade, error)
    GetLatestQuotes(ctx context.Context, symbols []string) (map[string]*types.Quote, error)
    GetClock(ctx context.Context) (*types.MarketClock, error)
    GetCalendar(ctx context.Context, start, end string) ([]*types.MarketCalendarDay, error)
}

Built-in Providers

ProviderAsset ClassesTypeEnv Vars
AlpacaEquities, CryptoBroker-dealer (SEC/FINRA)ALPACA_API_KEY, ALPACA_API_SECRET
Interactive BrokersEquities, Options, Futures, FXPrime brokerIBKR_ACCESS_TOKEN, IBKR_ACCOUNT_ID, IBKR_CONSUMER_KEY
TradierEquities, OptionsBroker-dealerTRADIER_ACCESS_TOKEN, TRADIER_ACCOUNT_ID
CoinbaseCryptoExchange (Advanced Trade)COINBASE_API_KEY, COINBASE_API_SECRET
BinanceCryptoExchangeBINANCE_API_KEY, BINANCE_API_SECRET
KrakenCryptoExchangeKRAKEN_API_KEY, KRAKEN_API_SECRET
GeminiCryptoExchangeGEMINI_API_KEY, GEMINI_API_SECRET
SFOXCryptoPrime dealer / SORSFOX_API_KEY
FalconXCryptoInstitutional RFQFALCON_API_KEY, FALCON_API_SECRET, FALCON_PASSPHRASE
FireblocksCryptoCustody + OTCFIREBLOCKS_API_KEY, FIREBLOCKS_PRIVATE_KEY
BitGoCryptoCustody + PrimeBITGO_ACCESS_TOKEN, BITGO_ENTERPRISE
CircleUSDC / StablecoinsStablecoin infrastructureCIRCLE_API_KEY
CurrencyCloudFX (35+ pairs)Institutional FX (Visa)CURRENCYCLOUD_LOGIN_ID, CURRENCYCLOUD_API_KEY
LMAXFX, Crypto, MetalsInstitutional CLOBLMAX_API_KEY, LMAX_USERNAME, LMAX_PASSWORD
Polygon.ioEquities, FX, CryptoMarket data onlyPOLYGON_API_KEY
FinixPaymentsPayment processingFINIX_USERNAME, FINIX_PASSWORD

Automatic Registration

envconfig.RegisterFromEnv() checks environment variables for all 16 providers and registers whichever ones have credentials:

import (
    "github.com/luxfi/broker/pkg/provider"
    "github.com/luxfi/broker/pkg/provider/envconfig"
)

registry := provider.NewRegistry()
n := envconfig.RegisterFromEnv(registry)
// n = number of providers successfully registered

Set ALPACA_API_KEY and ALPACA_API_SECRET in the environment, and Alpaca is registered. Set COINBASE_API_KEY and COINBASE_API_SECRET, and Coinbase is added. No code changes needed.

Each provider also accepts an optional base URL override for sandbox/testing:

ProviderURL Override VarDefault
AlpacaALPACA_BASE_URLSandbox
IBKRIBKR_GATEWAY_URLDefault gateway
BitGoBITGO_BASE_URLTest
FalconXFALCON_BASE_URLSandbox
FinixFINIX_BASE_URLSandbox
CircleCIRCLE_BASE_URLSandbox
TradierTRADIER_BASE_URLSandbox
LMAXLMAX_BASE_URLSandbox
CurrencyCloudCURRENCYCLOUD_BASE_URLDemo

Production URLs are used by default for: Coinbase, Binance, Kraken, Gemini, SFOX, Fireblocks, Polygon.

Adding a Custom Provider

Implement the Provider interface and register it on the registry:

package myprovider

import (
    "context"
    "github.com/luxfi/broker/pkg/provider"
    "github.com/luxfi/broker/pkg/types"
)

type MyProvider struct {
    apiKey string
}

func New(apiKey string) *MyProvider {
    return &MyProvider{apiKey: apiKey}
}

func (p *MyProvider) Name() string { return "myprovider" }

func (p *MyProvider) CreateAccount(ctx context.Context, req *types.CreateAccountRequest) (*types.Account, error) {
    // Your implementation
}

// ... implement remaining Provider interface methods

Register manually:

registry := provider.NewRegistry()
envconfig.RegisterFromEnv(registry) // built-in providers
registry.Register(myprovider.New(os.Getenv("MY_API_KEY"))) // custom provider

Optional Capability Interfaces

Providers can implement additional interfaces for extended functionality. The broker API detects these at runtime and exposes the additional endpoints only for providers that support them.

InterfaceMethodsUsed By
TradingExtendedReplaceOrder, CancelAllOrders, GetPosition, ClosePosition, CloseAllPositionsAlpaca, IBKR, Tradier
AccountManagerUpdateAccount, CloseAccount, GetAccountActivitiesAlpaca, IBKR
DocumentManagerUploadDocument, ListDocuments, GetDocument, DownloadDocumentAlpaca
JournalManagerCreateJournal, ListJournals, BatchJournal, ReverseBatchJournalAlpaca
TransferExtendedCancelTransfer, DeleteACHRelationship, RecipientBanksAlpaca, IBKR
CryptoDataProviderCryptoBars, CryptoQuotes, CryptoTrades, CryptoSnapshotsCoinbase, Binance, Kraken
EventStreamerStreamTradeEvents, StreamAccountEvents, StreamTransferEventsAlpaca
PortfolioAnalyzerGetPortfolioHistoryAlpaca, IBKR
WatchlistManagerCreateWatchlist, ListWatchlists, CRUD operationsAlpaca

You do not need to implement these. The base Provider interface is sufficient. Add optional interfaces only for capabilities your provider actually supports.

On this page