TheDocumentation 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.
GBMPlusAPI class is the single entry point to the entire gbmplus SDK. Instantiating it validates your credentials, configures logging, establishes an authenticated RestSession, resolves your main contract ID, and wires up the four API modules (accounts, transfers, orders, and tradingUSA) as direct attributes. Every subsequent API call flows through one of those module attributes using the pattern client.scope.operation(params).
GBMPlusAPI constructor
Parameters
Your GBM+ account e-mail address. If
None, the SDK falls back to the USER_EMAIL environment variable.Your GBM+ account password. If
None, the SDK falls back to the USER_PASSWORD environment variable.Your GBM+ client identifier. If
None, the SDK falls back to the CLIENT_ID environment variable.Maximum number of seconds to wait for any individual API call before timing out.
Number of times the session will retry a request after a server-side (5XX) error or a JSON-decode failure before raising
APIError.When
True, 4XX responses will also be retried (up to maximum_retries times) instead of raising APIError immediately.Maximum number of seconds to wait between 4XX retries. The actual wait is a random integer in the range
[1, retry_4xx_error_wait_time].When
True, log output is written to a timestamped file on disk alongside console output.Directory path for the log file. Defaults to the working directory of the calling script when left empty.
Prefix for the log filename. The SDK appends
_log__<YYYY-MM-DD_HH-MM-SS>.log automatically.When
True, INFO-level log messages are streamed to stdout in addition to the log file.When
True, all logging is disabled entirely — no file, no console output. The internal _logger attribute is set to None.Initialization sequence
Every call toGBMPlusAPI() runs the following steps automatically before returning the client object.
Credential validation
Each of
user_email, user_password, and client_id is resolved from the argument or the corresponding environment variable (USER_EMAIL, USER_PASSWORD, CLIENT_ID). If any value is still missing after the fallback, a UserError is raised immediately.Logging configuration
Unless
suppress_logging=True, a Python logging.Logger is created at DEBUG level. If output_log=True, a FileHandler writes to a timestamped .log file under log_path. If print_console=True, a StreamHandler emits INFO-and-above messages to the console.RestSession creation and header setup
A
RestSession instance is constructed with the supplied credentials and retry settings. The underlying requests.Session is configured with Content-Type: application/json. The SDK resolves your current IP geolocation via geocoder.ip('me') and injects the device-latitude and device-longitude headers required by GBM+ POST endpoints.Authentication — `authenticate()`
RestSession.authenticate() posts your credentials to https://auth.gbm.com/api/v1/session/user. On success the response’s accessToken is extracted and stored, and the session header Authorization: Bearer <token> is set for all subsequent requests. An AuthenticationError is raised if the response is empty or invalid.Main contract lookup — `getMainContract()`
RestSession.getMainContract() performs a GET request to https://api.gbm.com/v1/contracts and stores the first entry’s contract_id as _main_contract_id on the session. This ID is used internally by many order and account endpoints.Module attributes
After construction, all API functionality is accessed through the four module attributes below.gbm.accounts
Accounts & strategies — retrieve portfolio positions, account balances, and investment strategies.
gbm.orders
Orders & trading — generate order objects and submit buy/sell orders on the Mexican exchange.
gbm.transfers
Fund transfers — initiate and track cash transfers between your GBM+ accounts.
gbm.tradingUSA
US market trading — access trading operations for US-listed instruments through GBM+.
API call pattern
All operations follow the same three-part pattern:client— yourGBMPlusAPIinstance.scope— one of the four module attributes (accounts,orders,transfers,tradingUSA).operation— the specific method provided by that module.
Version
The current SDK version is exposed as a module-level constant:RestSession log entry for diagnostic purposes.