basana.backtesting.lending¶
Lending strategies are used by the backtesting exchange to support different lending schemes, or no lending at all.
Margin calls are not yet implemented.
- class basana.backtesting.lending.LoanInfo(id: str, is_open: bool, borrowed_symbol: str, borrowed_amount: decimal.Decimal, outstanding_interest: Dict[str, decimal.Decimal], paid_interest: Dict[str, decimal.Decimal])¶
- Parameters:
id (str)
is_open (bool)
borrowed_symbol (str)
borrowed_amount (Decimal)
outstanding_interest (Dict[str, Decimal])
paid_interest (Dict[str, Decimal])
- borrowed_amount: Decimal¶
The amount being borrowed.
- borrowed_symbol: str¶
The symbol being borrowed.
- id: str¶
The loan id.
- is_open: bool¶
True if the loan is open, False otherwise.
- outstanding_interest: Dict[str, Decimal]¶
The outstanding interest. Only valid for open loans.
- paid_interest: Dict[str, Decimal]¶
The paid interest. Only valid for closed loans.
- class basana.backtesting.lending.NoLoans¶
Bases:
LendingStrategyLending not supported.
- class basana.backtesting.lending.MarginLoanConditions(interest_symbol: str, interest_percentage: decimal.Decimal, interest_period: datetime.timedelta, min_interest: decimal.Decimal)¶
- Parameters:
interest_symbol (str)
interest_percentage (Decimal)
interest_period (timedelta)
min_interest (Decimal)
- interest_percentage: Decimal¶
The interest percentage.
- interest_period: timedelta¶
The interest period.
- interest_symbol: str¶
The symbol for the interest.
- min_interest: Decimal¶
The minimum interest to charge.
- class basana.backtesting.lending.MarginLoans(quote_symbol, margin_requirement, default_conditions=None)¶
Bases:
LendingStrategyThis strategy will use the accounts assets as collateral for the loans.
- Parameters:
quote_symbol (str) – The symbol to use to normalize balances.
margin_requirement (Decimal) – Minimum threshold for the value of the collateral relative to the total position.
default_conditions (MarginLoanConditions | None) – The default margin loan conditions.
- get_conditions(symbol)¶
Returns the lending conditions for a given symbol.
- Parameters:
symbol (str) – The symbol.
- Return type:
- property margin_level: Decimal¶
The current margin level.
- set_conditions(symbol, conditions)¶
Set the lending conditions for a given symbol.
- Parameters:
symbol (str) – The symbol whose conditions are being set.
conditions (MarginLoanConditions) – The lending conditions.
- set_exchange_context(loan_mgr, exchange_context)¶
This method will be called during exchange initialization to give lending strategies a chance to later use those services.
- Parameters:
loan_mgr (LoanManager)
exchange_context (ExchangeContext)