Skip to content

Authentication

Authentication creates a logged-in SDK session that can be reused across instruments, market data, portfolio, and trading classes.

Use this page when you need to:

  • initialize the SDK in UAT or PROD
  • log in with OTP and MPIN
  • set up and use TOTP login
  • use .env values for repeatable local workflows
  • reset or disable an existing auth setup

LLM guidance

Treat authentication as a process-level prerequisite, not a per-request action. Initialize the SDK once, then reuse the authenticated client across instruments, market data, and trading workflows.

Basic Usage

The default login flow uses your phone number, OTP, and MPIN.

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv

# Use NubraEnv.UAT for testing and NubraEnv.PROD for production.
nubra = InitNubraSdk(NubraEnv.UAT, env_creds=True)

# Reuse the authenticated client across modules.
# Example:
# instruments = InstrumentData(nubra)
# market_data = MarketData(nubra)
# trader = NubraTrader(nubra, version="V2")

If you want to fully reset the session:

nubra.logout()

SDK Surface

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv

InitNubraSdk(
    env: NubraEnv,
    totp_login: bool = False,
    env_creds: bool = False,
    insti_login: bool = False,
)

Session helpers exposed on the initialized client include:

  • logout()
  • totp_generate_secret()
  • totp_enable()
  • totp_disable()

Authentication Modes

Mode Trigger User inputs Best use case
OTP login totp_login=False phone number, OTP, MPIN default onboarding flow
TOTP login totp_login=True phone number, TOTP, MPIN repeated or semi-automated usage
.env assisted env_creds=True env vars plus OTP or TOTP where needed local scripts and repeatable dev flows

OTP Login

The standard OTP flow requires:

  1. your registered phone number
  2. the OTP received on that number
  3. your MPIN
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv

nubra = InitNubraSdk(NubraEnv.PROD)

After initialization, the SDK will prompt for the required login inputs.

TOTP Login

TOTP is useful for repeated or more automation-friendly login flows.

TOTP Setup and Login Flow

This is a complete multi-step setup flow. Do not stop after generating the secret.

Step 1. Generate TOTP Secret

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv

setup_client = InitNubraSdk(NubraEnv.PROD)
secret = setup_client.totp_generate_secret()
print("TOTP Secret:", secret)

Add the returned secret to your authenticator app.

Step 2. Enable TOTP

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv

setup_client = InitNubraSdk(NubraEnv.PROD)
setup_client.totp_enable()

This flow prompts for the TOTP value and MPIN.

Step 3. Login Using TOTP

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv

nubra = InitNubraSdk(NubraEnv.PROD, totp_login=True)

The SDK will prompt for the phone number, TOTP, and MPIN, then create the authenticated session.

Step 4. Disable TOTP

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv

nubra = InitNubraSdk(NubraEnv.PROD)
nubra.totp_disable()

Using .env Variables

For local scripts, you can keep the phone number and MPIN in a .env file instead of hardcoding them in code.

Example .env:

PHONE_NO="0000000000"
MPIN="0000"

Login with .env values enabled:

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv

nubra = InitNubraSdk(NubraEnv.PROD, env_creds=True)

Session Behavior

Authentication creates a reusable session for the initialized client.

  • Reuse the same nubra client across SDK modules
  • Avoid re-initializing authentication for every small task
  • Use logout() when you intentionally want to clear the active session

Important Rules

  • Use NubraEnv.UAT for testing and NubraEnv.PROD for live usage.
  • Keep the environment explicit in code. Do not rely on assumptions about the active environment.
  • logout() resets the active session, so the next initialization may require the full authentication flow again.
  • OTP and TOTP login are session-setup flows, not per-request actions.
  • Do not hardcode phone numbers, MPIN values, or TOTP secrets in source code.
  • Prefer env_creds=True for local repeatable workflows where .env is available.
  • After authentication, reuse the initialized client across reference-data, market-data, portfolio, and trading modules.

After authentication, the most common next pages are:

  1. Get Instruments
  2. Current Price
  3. Place Order
  4. UAT Environment
NEO Assistant