BotRepository API Reference
tradingbot.utils.bot_repository.BotRepository
Handles database operations for Bot entities.
create_or_get_bot(name: str) -> BotModel
staticmethod
Create or retrieve bot from database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Bot name |
required |
Returns:
| Type | Description |
|---|---|
Bot
|
BotModel instance (detached from session but with attributes loaded) |
Source code in tradingbot/utils/bot_repository.py
log_trade(bot_name: str, symbol: str, quantity: float, price: float, is_buy: bool, profit: Optional[float] = None) -> Trade
staticmethod
Log a trade to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bot_name
|
str
|
Name of the bot executing the trade |
required |
symbol
|
str
|
Trading symbol |
required |
quantity
|
float
|
Number of shares/units |
required |
price
|
float
|
Price per unit |
required |
is_buy
|
bool
|
True for buy, False for sell |
required |
profit
|
Optional[float]
|
Profit from the trade (for sells) |
None
|
Returns:
| Type | Description |
|---|---|
Trade
|
Created Trade object |