You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/instruments.md
+44-33Lines changed: 44 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,39 +142,47 @@ such as when passing them to the order factory to create an order.
142
142
143
143
## Margins and fees
144
144
145
-
Margin calculations are handled by the `MarginAccount` class. Let's explore how margins work in our trading system and understand all the key concepts.
145
+
Margin calculations are handled by the `MarginAccount` class. This section explains how margins work and introduces key concepts you need to know.
146
146
147
147
### When margins apply?
148
148
149
-
Each exchange (like CME or Binance) operates with a specific account type that determines whether margin calculations are relevant for your trading. When setting up an exchange connection, you'll specify one of these account types:
-`AccountType.CASH`: Simple accounts where margins don't apply
152
-
-`AccountType.BETTING`: Also doesn't use margin calculations
149
+
Each exchange (e.g., CME or Binance) operates with a specific account types that determine whether margin calculations are applicable.
150
+
When setting up an exchange venue, you'll specify one of these account types:
151
+
152
+
-`AccountType.MARGIN`: Accounts that use margin calculations, which are explained below.
153
+
-`AccountType.CASH`: Simple accounts where margin calculations do not apply.
154
+
-`AccountType.BETTING`: Accounts designed for betting, which also do not involve margin calculations.
153
155
154
156
### Vocabulary
155
157
156
-
Let's start with the key terms you'll need to understand trading on margin:
158
+
To understand trading on margin, let’s start with some key terms:
157
159
158
-
**Notional Value** is the full contract value in base currency. The instrument's notional value represents the total market value of your position. For example, with EUR/USD futures on CME (symbol 6E):
159
-
- Each contract represents 125,000 EUR (EUR is quote currency, USD is base currency)
160
-
-When the current market price is 1.1000, then the notional value equals 125,000 EUR × `1.1000` (price of EUR/USD) = 137,500 USD
160
+
**Notional Value**: The total contract value in the quote currency. It represents the full market value of your position. For example, with EUR/USD futures on CME (symbol 6E).
161
+
- Each contract represents 125,000 EUR (EUR is base currency, USD is quote currency).
162
+
-If the current market price is 1.1000, the notional value equals 125,000 EUR × 1.1000 (price of EUR/USD) = 137,500 USD.
161
163
162
-
**Leverage** (`leverage`) is an attribute of your trading account that defines how much market exposure you can control with your account deposit. For example, with 10× leverage, you can control 10,000 USD worth of positions with just 1,000 USD in your account.
164
+
**Leverage** (`leverage`): The ratio that determines how much market exposure you can control relative to your account deposit. For example, with 10× leverage, you can control 10,000 USD worth of positions with just 1,000 USD in your account.
163
165
164
-
**Initial Margin** (`margin_init`) is the initial margin rate required to open positions. It represents the amount of money that must be available in your account to open new positions. This is just an entry check requirement - no money is actually locked in your account.
166
+
**Initial Margin** (`margin_init`): The margin rate required to open a position. It represents the minimum amount of funds that must be available in your account to open new positions. This is only a pre-check — no funds are actually locked.
165
167
166
-
**Maintenance Margin** (`margin_maint`) is the maintenance margin rate to keep positions open. This is the amount of money that gets locked and must remain in your account to keep positions open. It's always lower than the initial margin, and you can view all blocked funds (sum of maintenance margins) from open positions using `self.portfolio.balances_locked(venue)`in your strategy.
168
+
**Maintenance Margin** (`margin_maint`): The margin rate required to keep a position open. This amount is locked in your account to maintain the position. It is always lower than the initial margin. You can view the total blocked funds (sum of maintenance margins for open positions) using the following in your strategy:
167
169
168
-
**Maker/Taker Fees** describe how exchanges charge trading fees based on how you interact with the market. When you place an order, you're either a "maker" or a "taker" of liquidity:
170
+
```python
171
+
self.portfolio.balances_locked(venue)
172
+
```
169
173
170
-
-**Maker Fee** (`maker_fee`): This is the lower fee you pay when you "make" liquidity by placing orders that sit on the order book. For example, if you place a limit buy order below the current market price, you're adding liquidity to the market and will pay the maker fee when your order eventually fills.
171
-
-**Taker Fee** (`taker_fee`): This is typically a higher fee charged when you "take" liquidity by placing orders that execute immediately against existing orders. For instance, if you place a market buy order or a limit buy above the current price, you're removing liquidity from the market and will pay the taker fee.
174
+
**Maker/Taker Fees**: The fees charged by exchanges based on your order's interaction with the market:
172
175
173
-
Not all exchanges / instruments implement maker/taker fees. In these cases, both `maker_fee` and `taker_fee` should be set to 0 in `Instrument` and all its subclasses (such as `FuturesContract`, `Equity`, `CurrencyPair`, `Commodity`, `Cfd`, `BinaryOption`, `BettingInstrument`, and others).
176
+
- Maker Fee (`maker_fee`): A fee (typically lower) charged when you "make" liquidity by placing an order that remains on the order book. For example, a limit buy order below the current price adds liquidity, and the *maker* fee applies when it fills.
177
+
- Taker Fee (`taker_fee`): A fee (typically higher) charged when you "take" liquidity by placing an order that executes immediately. For instance, a market buy order or a limit buy above the current price removes liquidity, and the *taker* fee applies.
178
+
179
+
:::tip
180
+
Not all exchanges or instruments implement maker/taker fees. If absent, set both `maker_fee` and `taker_fee` to 0 for the `Instrument` (e.g., `FuturesContract`, `Equity`, `CurrencyPair`, `Commodity`, `Cfd`, `BinaryOption`, `BettingInstrument`).
181
+
:::
174
182
175
183
### Margin calculation formula
176
184
177
-
When examining the code in `MarginAccount`, you'll find the margin calculations follow these formulas:
185
+
The `MarginAccount` class calculates margins using the following formulas:
0 commit comments