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 client handles authentication entirely on your behalf — you never need to manually manage tokens or session headers. When you instantiate the client, it immediately calls session.authenticate(), which sends your credentials to https://auth.gbm.com/api/v1/session/user and receives a Bearer access token in return. That token is then automatically attached as an Authorization: Bearer <token> header on every subsequent request for the lifetime of the session.
Required credentials
The SDK requires three pieces of information to authenticate. You can supply them as environment variables (recommended) or pass them directly to the constructor.The email address associated with your GBM+ account — the same one you use to log in to the GBM+ web portal.
The password for your GBM+ account.
A client identifier tied to your GBM+ session. This is not your contract number or account number — it is a separate identifier used by the GBM+ authentication endpoint.
Finding your CLIENT_ID
TheCLIENT_ID is not displayed prominently in the GBM+ user interface, but it is straightforward to locate.
Open the GBM+ login page in your browser and open the browser developer tools (press F12 or Cmd+Option+I on macOS). Navigate to the Network tab, then proceed to log in. Watch for the POST request sent to
auth.gbm.com. Click on that request and inspect its Payload or Request Body — the clientid field is your CLIENT_ID. The project README includes a screenshot that shows exactly where to find it in the GBM+ login dashboard.Setting credentials
1. Environment variables (recommended)
Supplying credentials through environment variables keeps secrets out of your source code and is the approach used in the project’s own examples.- Linux / macOS
- Windows PowerShell
USER_EMAIL, USER_PASSWORD, and CLIENT_ID from the environment automatically via os.getenv().
2. Passing credentials directly to the constructor
You can also pass your credentials as keyword arguments when creating theGBMPlusAPI instance:
3. Mixed: environment variables with constructor overrides
Constructor arguments take precedence over environment variables. You can rely on environment variables for most credentials while overriding a specific one at runtime:How authentication works
The following sequence happens automatically insideGBMPlusAPI.__init__() every time you create a new client instance:
-
Credential resolution — the SDK checks constructor arguments first, then falls back to
os.getenv()for any missing values. If any of the three credentials is still missing, aUserErroris raised immediately. -
Session authentication —
session.authenticate()sends a POST request tohttps://auth.gbm.com/api/v1/session/userwith a JSON payload containingclientid,user, andpassword. On success, the response includes anaccessToken. -
Token injection — the access token is stored in
session._access_tokenand the session-level headerAuthorization: Bearer <token>is set on the underlyingrequests.Session. All subsequent HTTP calls carry this header automatically. -
Contract resolution —
session.getMainContract()sends a GET request tohttps://api.gbm.com/v1/contractsto retrieve your primary contract ID. This ID is stored assession._main_contract_idand is required by the majority of subsequent API endpoints.
accounts, orders, transfers, and tradingUSA module objects are initialized and ready to use.
Authentication errors
If authentication fails, the SDK raises one of two exceptions:UserError
Raised when one or more of the three required credentials (
USER_EMAIL, USER_PASSWORD, CLIENT_ID) are missing — either not passed to the constructor and not set as environment variables.Message: "User email, password and client_id need to be defined"AuthenticationError
Raised when the credentials are present but the GBM+ auth endpoint rejects them — for example, due to a wrong password or an invalid
CLIENT_ID.Message: "There was an authentication error. Verify that email, password and client_id are correct"try/except block to handle these gracefully:
For a full reference of all exceptions the SDK can raise — including
APIError and OrderFormatError — see the Exceptions reference.