- Solve real problems with our hands-on interface
- Progress from basic puts and calls to advanced strategies

Posted October 22, 2026 at 10:58 am
The article “Trading Futures with IBridgePy: ES, MES, and NQ Complete Guide” was originally published on IBridgePy blog.
The author of this article and the open-source package IBridgePy are not affiliated with Interactive Brokers. IBridgePy is not endorsed or approved by Interactive Brokers or any of its affiliates. The software is provided without any warranty and should not be used for actual trading unless the user can read and understand its source code. The IBKR API team does not support this software.
Futures contracts like ES (S&P 500 E-mini), MES (Micro E-mini S&P 500), and NQ (Nasdaq 100 E-mini) are among the most liquid instruments in the world. With IBridgePy, you can automate futures trading strategies using Python and execute them through Interactive Brokers with just a few lines of code.
Unlike stocks, futures require additional parameters: the expiry date and the exchange. IBridgePy uses superSymbol() to define futures contracts:
# Define an ES futures contract (December 2026 expiry)
es_contract = superSymbol(secType='FUT', symbol='ES', currency='USD',
exchange='CME', expiry='20261218')
# Define an MES micro futures contract
mes_contract = superSymbol(secType='FUT', symbol='MES', currency='USD',
exchange='CME', expiry='20261218')
# Define an NQ futures contract
nq_contract = superSymbol(secType='FUT', symbol='NQ', currency='USD',
exchange='CME', expiry='20261218')The expiry parameter uses the format YYYYMMDD and should match the contract expiration date on the CME.
Once you have defined the contract, placing orders works the same as with stocks:
def handle_data(context, data):
mes = superSymbol(secType='FUT', symbol='MES', currency='USD',
exchange='CME', expiry='20261218')
# Buy 1 MES contract at market
order_id = order(mes, 1)
order_status_monitor(order_id, 'Filled', waitingTimeInSeconds=30)
fill_price = get_order(order_id).avgFillPrice
print(f'Bought 1 MES at {fill_price}')A critical difference between stocks and futures in IBridgePy is how get_position().cost_basis works. For futures, Interactive Brokers returns the dollar-multiplied value, not the raw price.
| Contract | Multiplier | Fill Price | cost_basis Value |
|---|---|---|---|
| MES | $5 | 5,400 | 27,000 |
| ES | $50 | 5,400 | 270,000 |
| MNQ | $2 | 19,500 | 39,000 |
| NQ | $20 | 19,500 | 390,000 |
To convert cost_basis back to the actual entry price, divide by the multiplier:
# Get entry price for MES position
mes_position = get_position(mes_contract)
entry_price = mes_position.cost_basis / 5 # MES multiplier is 5
print(f'MES entry price: {entry_price}')
# For ES
es_position = get_position(es_contract)
es_entry = es_position.cost_basis / 50 # ES multiplier is 50The third-party code below is not investment or trading advice, and is for proof-of-concept, educational, and illustrative purposes only. IBKR makes no representations or warranty regarding its accuracy or completeness. Users are solely responsible for conducting their own independent testing and due diligence before applying any code or concepts in a live or production environment.
def initialize(context):
context.mes = superSymbol(secType='FUT', symbol='MES', currency='USD',
exchange='CME', expiry='20261218')
context.in_position = False
def handle_data(context, data):
if not context.in_position:
# Enter long position
order_id = order(context.mes, 1)
order_status_monitor(order_id, 'Filled', waitingTimeInSeconds=30)
# Use avgFillPrice for precise stop/target levels
fill_price = get_order(order_id).avgFillPrice
# Place bracket: 20-point stop, 40-point target
stop_price = fill_price - 20
target_price = fill_price + 40
order(context.mes, -1, style=StopOrder(stop_price))
order(context.mes, -1, style=LimitOrder(target_price))
context.in_position = True
print(f'Entry: {fill_price} | Stop: {stop_price} | Target: {target_price}')expiry parameter before the contract rolls (typically the Thursday before the third Friday of March, June, September, or December for index futures).get_position(contract).amount returns the number of contracts held, positive for long and negative for short.For more on order types and position management, visit the IBridgePy documentation or explore our tutorials.
Already an Interactive Brokers Client?
New to Interactive Brokers?
Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.
This material is from IBridgePy and is being posted with its permission. The views expressed in this material are solely those of the author and/or IBridgePy and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.
Futures are not suitable for all investors. The amount you may lose may be greater than your initial investment. Before trading futures, please read the CFTC Risk Disclosure. A copy and additional information are available at ibkr.com.
Trading on margin is only for experienced investors with high risk tolerance. You may lose more than your initial investment. For additional information regarding margin loan rates, see ibkr.com/interest
The third-party code discussed within this article is not investment or trading advice, and is for proof-of-concept, educational, and illustrative purposes only. IBKR makes no representations or warranty regarding its accuracy or completeness. Users are solely responsible for conducting their own independent testing and due diligence before applying any code or concepts in a live or production environment
Please keep in mind that the examples discussed in this material are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.
The order types available through Interactive Brokers LLC's trading platforms are designed to help you limit your loss and/or lock in a profit. Market conditions and other factors may affect execution. In general, orders guarantee a fill or guarantee a price, but not both. In extreme market conditions, an order may either be executed at a different price than anticipated or may not be filled in the marketplace.
Join The Conversation
For specific platform feedback and suggestions, please submit it directly to our team using these instructions.
If you have an account-specific question or concern, please reach out to Client Services.
We encourage you to look through our FAQs before posting. Your question may already be covered!