NubraNubra API
Back to Blogs
API IntegrationTrading AutomationBroker Switching

Code Switching: Other brokers to Nubra for Common Trading APIs

Akshay Navin: Algo Trader & Content DeveloperDecember 1, 20257 min

Switching brokers does not have to mean rewriting your entire trading stack. This guide shows quick, direct code switches between Zerodha (Kite Connect), Dhan, Upstox, and Nubra for the most common workflows.

What changes most:

  • Instrument identifiers (Zerodha uses instrument_token, Dhan uses security_id, Upstox uses instrument_key, Nubra uses ref_id or symbols)
  • Method names and parameter keys
  • Realtime streaming classes and subscription formats

Below are the most used workflows and the smallest code you need to switch between brokers.

1) Market Order#

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.trading.trading_data import NubraTrader
from nubra_python_sdk.refdata.instruments import InstrumentData

nubra = InitNubraSdk(NubraEnv.PROD)
trade = NubraTrader(nubra, version="V2")
instruments = InstrumentData(nubra)

ref_id = instruments.get_instrument_by_symbol("HDFCBANK", exchange="NSE").ref_id

result = trade.create_order({
  "ref_id": ref_id,
  "order_side": "ORDER_SIDE_BUY",
  "order_type": "ORDER_TYPE_REGULAR",
  "price_type": "MARKET",
  "order_qty": 1,
  "validity_type": "IOC",
  "order_delivery_type": "ORDER_DELIVERY_TYPE_CNC",
  "exchange": "NSE",
  "tag": "Market_example"
})

print(result.order_id)
Zerodha
Dhan
Upstox

Tip: Instrument IDs differ by broker: Zerodha uses instrument_token, Dhan uses security_id, Upstox uses instrument_key, and Nubra uses ref_id or symbol + exchange. Fetch the right ID first, then place the order.


2) Historical Data (Candles)#

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.marketdata.market_data import MarketData

nubra = InitNubraSdk(NubraEnv.PROD)
md = MarketData(nubra)
result = md.historical_data({
  "exchange": "NSE",
  "type": "STOCK",
  "values": ["HDFCBANK"],
  "fields": ["open", "high", "low", "close", "cumulative_volume"],
  "startDate": "2025-01-01T03:45:00.000Z",
  "endDate": "2025-01-31T10:00:00.000Z",
  "interval": "1d",
  "intraDay": False,
  "realTime": False
})
print(result)
Zerodha
Dhan
Upstox

Tip: Historical APIs all need a broker-specific instrument ID and a date range. The payload shape differs, but the workflow is the same: resolve ID → pass dates/interval → read candles.


3) Realtime Data (Streaming)#

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.ticker import websocketdata

def on_index_data(msg):
  print(msg)

def on_connect(msg):
  print(msg)

def on_close(reason):
  print(reason)

def on_error(err):
  print(err)

nubra = InitNubraSdk(NubraEnv.PROD)

socket = websocketdata.NubraDataSocket(
  client=nubra,
  on_index_data=on_index_data,
  on_connect=on_connect,
  on_close=on_close,
  on_error=on_error
)

socket.connect()
socket.subscribe(["NIFTY", "HDFCBANK"], data_type="index", exchange="NSE")
socket.keep_running()
Zerodha
Dhan
Upstox

Tip: Streaming subscriptions are not portable. Zerodha and Upstox subscribe by instrument ID, Dhan uses exchange + security_id, and Nubra uses exchange + symbol/type (or index codes).


4) Get Instruments#

from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
from nubra_python_sdk.refdata.instruments import InstrumentData

nubra = InitNubraSdk(NubraEnv.PROD)
instruments = InstrumentData(nubra)

instruments_df = instruments.get_instruments_dataframe()
print(len(instruments_df))

hdfc = instruments.get_instrument_by_symbol("HDFCBANK", exchange="NSE")
print(hdfc.ref_id)
Zerodha
Dhan
Upstox

Learn more about the Nubra Python SDK and APIs here: Nubra API Docs

Use our integrated chatbot to ask questions and get help switching from other broker codes as well.