Enterprise API Reference¶
Multi-Asset¶
financelib.enterprise.multi_asset.Asset(symbol: str, asset_class: AssetClass, name: str = '', currency: str = 'USD', exchange: str = '', metadata: Dict[str, Any] = dict())
dataclass
¶
Unified asset representation across all asset classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Unique identifier (e.g., 'THYAO.IS', 'EURUSD', 'BTC/USDT'). |
required |
asset_class
|
AssetClass
|
Type of asset. |
required |
name
|
str
|
Human-readable name. |
''
|
currency
|
str
|
Denomination currency. |
'USD'
|
exchange
|
str
|
Primary exchange. |
''
|
metadata
|
Dict[str, Any]
|
Additional asset-specific data. |
dict()
|
Example
stock = Asset("THYAO.IS", AssetClass.EQUITY, "Turkish Airlines", "TRY", "BIST") bond = Asset("TR10Y", AssetClass.BOND, "Turkey 10Y Gov Bond", "TRY") fx = Asset("USDTRY", AssetClass.FX, "USD/TRY", "TRY")
financelib.enterprise.multi_asset.AssetClass
¶
Bases: Enum
Supported asset classes.
financelib.enterprise.multi_asset.AssetUniverse()
¶
Manages a collection of assets across all classes.
Provides filtering, grouping, and lookup by symbol or asset class.
Example
universe = AssetUniverse() universe.add(Asset("THYAO.IS", AssetClass.EQUITY, "THY", "TRY", "BIST")) universe.add(Asset("USDTRY", AssetClass.FX, "USD/TRY", "TRY")) equities = universe.filter_by_class(AssetClass.EQUITY)
Source code in financelib/enterprise/multi_asset.py
Functions¶
add(asset: Asset) -> None
¶
add_many(assets: List[Asset]) -> None
¶
filter_by_class(asset_class: AssetClass) -> List[Asset]
¶
filter_by_currency(currency: str) -> List[Asset]
¶
Get all assets denominated in a specific currency.
filter_by_exchange(exchange: str) -> List[Asset]
¶
get(symbol: str) -> Optional[Asset]
¶
group_by_class() -> Dict[str, List[Asset]]
¶
Group all assets by asset class.
Source code in financelib/enterprise/multi_asset.py
remove(symbol: str) -> bool
¶
summary() -> Dict[str, int]
¶
Count of assets per class.
Order Routing¶
financelib.enterprise.order_router.OrderRouter()
¶
Smart order router for multi-exchange trading.
Routes orders to the best available exchange based on asset class, exchange priority, and availability.
Example
router = OrderRouter() router.add_exchange(Exchange("BIST", ["equity"], priority=1)) router.add_exchange(Exchange("BINANCE", ["crypto"], priority=1)) order = router.route("THYAO.IS", "buy", 100, asset_class="equity")
Source code in financelib/enterprise/order_router.py
Functions¶
add_exchange(exchange: Exchange) -> None
¶
find_exchanges(asset_class: str) -> List[Exchange]
¶
Find active exchanges supporting an asset class, sorted by priority.
Source code in financelib/enterprise/order_router.py
route(symbol: str, side: str, quantity: float, price: float = 0.0, order_type: str = 'market', asset_class: str = 'equity', preferred_exchange: Optional[str] = None) -> RoutedOrder
¶
Route an order to the best available exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Asset symbol. |
required |
side
|
str
|
'buy' or 'sell'. |
required |
quantity
|
float
|
Order quantity. |
required |
price
|
float
|
Limit price (0 for market). |
0.0
|
order_type
|
str
|
'market', 'limit', or 'stop'. |
'market'
|
asset_class
|
str
|
Asset class for routing. |
'equity'
|
preferred_exchange
|
Optional[str]
|
Override automatic routing. |
None
|
Returns:
| Type | Description |
|---|---|
RoutedOrder
|
RoutedOrder with exchange assignment and status. |
Source code in financelib/enterprise/order_router.py
financelib.enterprise.order_router.Exchange(name: str, asset_classes: List[str] = list(), priority: int = 0, status: ExchangeStatus = ExchangeStatus.ACTIVE, execute_fn: Optional[Callable] = None, metadata: Dict[str, Any] = dict())
dataclass
¶
Represents a trading exchange/venue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Exchange identifier (e.g., 'BIST', 'BINANCE', 'NYSE'). |
required |
asset_classes
|
List[str]
|
Supported asset classes. |
list()
|
priority
|
int
|
Routing priority (lower = higher priority). |
0
|
status
|
ExchangeStatus
|
Current exchange status. |
ACTIVE
|
execute_fn
|
Optional[Callable]
|
Optional function to execute orders. |
None
|
financelib.enterprise.order_router.RoutedOrder(order_id: str = '', symbol: str = '', side: str = '', quantity: float = 0.0, price: float = 0.0, order_type: str = 'market', exchange: str = '', status: str = 'pending', timestamp: str = (lambda: datetime.now().isoformat())(), fill_price: float = 0.0, fill_quantity: float = 0.0, reject_reason: str = '')
dataclass
¶
Audit Trail¶
financelib.enterprise.audit.AuditTrail()
¶
Thread-safe audit trail for all trading operations.
Records every action with timestamp, user, and details. Entries are immutable once created.
Example
audit = AuditTrail() audit.log("ORDER_PLACED", "alice", {"symbol": "THYAO.IS", "side": "buy"}) audit.log("ORDER_FILLED", "alice", {"symbol": "THYAO.IS", "price": 175.0}) print(audit.query(user_id="alice"))
Source code in financelib/enterprise/audit.py
Functions¶
clear() -> None
¶
export_json() -> str
¶
export_to_file(filepath: str) -> int
¶
Export audit trail to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Output file path. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of entries exported. |
Source code in financelib/enterprise/audit.py
log(action: str, user_id: str = '', details: Optional[Dict] = None) -> AuditEntry
¶
Record an audit entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Action type string. |
required |
user_id
|
str
|
User identifier. |
''
|
details
|
Optional[Dict]
|
Action-specific data. |
None
|
Returns:
| Type | Description |
|---|---|
AuditEntry
|
The created AuditEntry. |
Source code in financelib/enterprise/audit.py
query(action: Optional[str] = None, user_id: Optional[str] = None, since: Optional[str] = None, limit: int = 100) -> List[AuditEntry]
¶
Query audit entries with filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Optional[str]
|
Filter by action type. |
None
|
user_id
|
Optional[str]
|
Filter by user. |
None
|
since
|
Optional[str]
|
Filter entries after this ISO timestamp. |
None
|
limit
|
int
|
Maximum entries to return. |
100
|
Returns:
| Type | Description |
|---|---|
List[AuditEntry]
|
Matching audit entries (newest first). |
Source code in financelib/enterprise/audit.py
financelib.enterprise.audit.AuditEntry(timestamp: str, action: str, user_id: str = '', details: Dict[str, Any] = dict(), entry_id: int = 0)
dataclass
¶
Immutable audit log entry.
Attributes:
| Name | Type | Description |
|---|---|---|
timestamp |
str
|
ISO-format timestamp. |
action |
str
|
Action type (e.g., 'ORDER_PLACED', 'POSITION_OPENED'). |
user_id |
str
|
User who performed the action. |
details |
Dict[str, Any]
|
Action-specific data. |
entry_id |
int
|
Unique entry identifier. |
Compliance¶
financelib.enterprise.compliance.TaxReport(year: int = 2026, currency: str = 'TRY')
¶
Capital gains tax report generator.
Calculates realized gains/losses using FIFO method and generates tax-ready reports.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
Tax year. |
2026
|
currency
|
str
|
Reporting currency. |
'TRY'
|
Example
report = TaxReport(year=2026) report.add_trade(TradeForReport(symbol="THYAO.IS", side="buy", quantity=100, price=170)) report.add_trade(TradeForReport(symbol="THYAO.IS", side="sell", quantity=100, price=180)) summary = report.generate() print(f"Net gain: {summary['net_gain']}")
Source code in financelib/enterprise/compliance.py
Functions¶
generate() -> Dict[str, Any]
¶
Generate capital gains tax report using FIFO.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with total gains, losses, net, and per-symbol breakdown. |
Source code in financelib/enterprise/compliance.py
financelib.enterprise.compliance.MiFIDReport(firm_id: str = '', lei: str = '')
¶
MiFID II transaction reporting.
Generates regulatory transaction reports compliant with MiFID II/MiFIR requirements (simplified).
Example
mifid = MiFIDReport(firm_id="FINLIB001") mifid.add_trade(trade) report = mifid.generate()
Source code in financelib/enterprise/compliance.py
Functions¶
generate() -> List[Dict[str, Any]]
¶
Generate MiFID II transaction reports.
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of transaction report records in MiFID II format. |
Source code in financelib/enterprise/compliance.py
financelib.enterprise.compliance.TradeForReport(trade_id: str = '', symbol: str = '', side: str = '', quantity: float = 0.0, price: float = 0.0, commission: float = 0.0, exchange: str = '', timestamp: str = '', currency: str = 'TRY', counterparty: str = '')
dataclass
¶
Standardized trade record for compliance reporting.
RBAC¶
financelib.enterprise.rbac.RBACManager()
¶
Role-Based Access Control manager.
Manages user-role assignments and permission checks.
Example
rbac = RBACManager() rbac.assign_role("alice", "trader") rbac.assign_role("bob", "viewer") assert rbac.check_permission("alice", Permission.TRADE) is True assert rbac.check_permission("bob", Permission.TRADE) is False
Source code in financelib/enterprise/rbac.py
Functions¶
add_role(role: Role) -> None
¶
assign_role(user_id: str, role_name: str) -> bool
¶
Assign a role to a user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
User identifier. |
required |
role_name
|
str
|
Role name to assign. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if assigned, False if role doesn't exist. |
Source code in financelib/enterprise/rbac.py
check_permission(user_id: str, permission: Permission) -> bool
¶
Check if a user has a specific permission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
User identifier. |
required |
permission
|
Permission
|
Permission to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if allowed. |
Source code in financelib/enterprise/rbac.py
get_user_role(user_id: str) -> Optional[Role]
¶
get_users_with_role(role_name: str) -> List[str]
¶
list_roles() -> List[str]
¶
list_users() -> Dict[str, str]
¶
revoke_role(user_id: str) -> bool
¶
financelib.enterprise.rbac.Role(name: str, permissions: Set[Permission] = set())
dataclass
¶
A named role with a set of permissions.
Example
trader = Role("trader", {Permission.VIEW_PORTFOLIO, Permission.TRADE}) admin = Role("admin", {p for p in Permission})
financelib.enterprise.rbac.Permission
¶
Bases: Enum
Available permissions.
Plugin Architecture¶
financelib.enterprise.plugin.PluginManager()
¶
Manages plugin lifecycle — registration, initialization, and discovery.
Example
manager = PluginManager() manager.register(MyDataPlugin) manager.initialize_all() plugin = manager.get("my_data") manager.shutdown_all()
Source code in financelib/enterprise/plugin.py
Functions¶
get(name: str) -> Optional[BasePlugin]
¶
health_check_all() -> Dict[str, bool]
¶
initialize_all(config: Optional[Dict[str, Dict]] = None) -> None
¶
Initialize all registered plugins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[Dict[str, Dict]]
|
Dict mapping plugin name → config dict. |
None
|
Source code in financelib/enterprise/plugin.py
list_plugins() -> List[Dict[str, str]]
¶
List all registered plugins with name and version.
register(plugin_class: Type[BasePlugin], config: Optional[Dict] = None) -> None
¶
Register and instantiate a plugin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin_class
|
Type[BasePlugin]
|
Plugin class (not instance). |
required |
config
|
Optional[Dict]
|
Optional configuration dict. |
None
|
Source code in financelib/enterprise/plugin.py
shutdown_all() -> None
¶
Shutdown all plugins gracefully.
Source code in financelib/enterprise/plugin.py
unregister(name: str) -> bool
¶
Remove a plugin.
Source code in financelib/enterprise/plugin.py
financelib.enterprise.plugin.BasePlugin
¶
Bases: ABC
Base class for all FinanceLib plugins.
Plugins must implement name, version, initialize, and shutdown.
Example
class MyDataPlugin(BasePlugin): ... @property ... def name(self): return "my_data" ... @property ... def version(self): return "1.0" ... def initialize(self, config): print("Started!") ... def shutdown(self): print("Stopped!")