This example shows how to generate and submit a buy order for a Mexican market instrument usingDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/markzuckerbergas/gbmplus-api-python/llms.txt
Use this file to discover all available pages before exploring further.
gbm.orders.generateOrderObject() and gbm.orders.submitOrder(). The two-step approach — first building an order object, then submitting it — gives you the chance to inspect the order payload before it hits the exchange, which is useful for logging and validation.
Prerequisites
Before running this example, make sure you have:- An authenticated GBM+ session (valid email, password, and
client_id) - The exact name of the investment strategy you want to trade under (e.g.
'Swensen') - The issuer ticker of the instrument you want to buy (e.g.
'FUNO 11') - Your strategy’s
legacy_contract_id— available in the account object returned bygetAccount()
Full example
Step-by-step walkthrough
Instantiate the client
Create a
GBMPlusAPI instance. The SDK authenticates your session immediately on construction using credentials from environment variables or constructor arguments.Retrieve the strategy account by name
Use This is a convenience wrapper around
gbm.accounts.getAccount() to fetch your strategy account object in a single call. Replace "Swensen" with the exact name of the strategy you want to trade under.getAccounts() that returns the first matching account object or None if the name isn’t found.Extract the legacy_contract_id
Orders on the Mexican market require the
legacy_contract_id — an older contract identifier used by the GBM homebroker API. It lives inside the account object.Generate the order object
generateOrderObject() builds and returns a Python dict describing the order. No order has been submitted yet — you can print and validate it before proceeding.Order parameters explained
The ticker or issuer string for the instrument you want to trade. For Mexican market instruments this typically includes the series suffix — e.g.
'FUNO 11', 'AMXL', 'FEMSAUBD'.The number of shares or units to buy or sell. Must be a positive integer.
Direction of the order. Use the
gbmplus.OrderTypes enum:| Value | Meaning |
|---|---|
gbmplus.OrderTypes.Buy | Purchase the instrument |
gbmplus.OrderTypes.Sell | Sell the instrument |
Execution style of the order. Use the
gbmplus.TradingTypes enum:| Value | Meaning |
|---|---|
gbmplus.TradingTypes.Market | Fill at the current market price |
gbmplus.TradingTypes.Limited | Fill only at price or better |
The market segment the instrument trades on. Use the
gbmplus.InstrumentTypes enum:| Value | Meaning |
|---|---|
gbmplus.InstrumentTypes.IPC | BMV IPC (Mexican blue-chips) |
gbmplus.InstrumentTypes.SIC | SIC (foreign-listed securities traded on BMV) |
Limit price per unit. Required when
trading_type is TradingTypes.Limited; omit for market orders. Passing a price with a market order is also accepted and will be included in the order object.Limited price order
To place a limit order instead of a market order, settrading_type to gbmplus.TradingTypes.Limited and supply the price argument. The order will only execute if the market reaches your specified price.