Nubra Python SDK
Project description
Nubra Python SDK
Nubra API is your gateway to seamless integration with Nubra's trading infrastructure.
Installation
pip install nubra-sdk
Dependencies
-
Python 3.7+
-
pandas
-
websockets
-
requests
Core Features
Market Data
-
Historical Data: Access OHLCV (Open, High, Low, Close, Volume) data with customizable time intervals
-
Market Quotes: Real-time quotes including LTP, LTQ, market depth, and volume
-
Option Chain: Complete option chain data with Greeks, OI, and price information
WebSocket Feeds
-
Ticker Feed: Real-time price updates
-
Market Depth Feed: Live order book updates
-
Option Chain Feed: Real-time option chain updates
Instruments Reference Data
-
Instrument Master: Complete list of tradable instruments
-
Automatic Caching: Daily refresh of instrument data
-
Quick Lookup: Efficient instrument search by various parameters
Example Implementations
Market Data Examples
from nubra_python_sdk.marketdata.market_data import MarketData
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
# Initialize SDK
nubra = InitNubraSdk(NubraEnv.STAGING)
md = MarketData(nubra)
# Get historical data
historical_data = md.historical_data({
"exchange": "NSE",
"type": "STOCK",
"values": ["HDFCBANK"],
"fields": ["close", "high", "low", "open", "volume"],
"startDate": "2024-01-01T00:00:00.000Z",
"endDate": "2024-01-31T23:59:59.000Z",
"interval": "1d"
})
# Get market quotes
quote = md.quote(ref_id=69353, levels=20)
# Get option chain
option_chain = md.option_chain("NIFTY")
WebSocket Examples
from nubra_python_sdk.ticker.websocketdata import TickerData
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
# Initialize SDK client
nubra = InitNubraSdk(NubraEnv.STAGING)
ticker_data = TickerData(nubra)
# Subscribe to price ticker
for msg in ticker_data.on_index_data("NIFTY"):
print(f"Symbol: {msg.indexname}")
print(f"Price: {msg.index_value}")
print(f"Volume: {msg.volume}")
print(f"Change: {msg.changepercent}%")
# Subscribe to option chain
for msg in ticker_data.on_optionchain_data("AARTIIND", "20250529"):
print(f"Asset: {msg.asset}")
print(f"Current Price: {msg.currentprice}")
print(f"ATM Strike: {msg.atm}")
# Access call options
for ce in msg.ce:
print(f"CE Strike: {ce.sp}, LTP: {ce.ltpchg}")
print(f"Greeks - Delta: {ce.delta}, Gamma: {ce.gamma}")
# Access put options
for pe in msg.pe:
print(f"PE Strike: {pe.sp}, LTP: {pe.ltpchg}")
print(f"Greeks - Delta: {pe.delta}, Gamma: {pe.gamma}")
# Subscribe to market depth
for msg in ticker_data.on_orderbook_data(351672):
print(f"LTP: {msg.ltp}, Volume: {msg.volume}")
# Access bid orders
for bid in msg.bids:
print(f"Bid - Price: {bid.price}, Quantity: {bid.quantity}")
# Access ask orders
for ask in msg.asks:
print(f"Ask - Price: {ask.price}, Quantity: {ask.quantity}")
Instrument Data Examples
from nubra_python_sdk.refdata.instruments import InstrumentData
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
# Initialize the Nubra SDK client
nubra = InitNubraSdk(NubraEnv.STAGING)
# Initialize instruments master data with the client
instruments = InstrumentData(nubra)
# Get all instruments as a pandas DataFrame
instruments_df = instruments.get_instruments_dataframe()
# Get instrument by reference ID. Internal Reference ID from Nubra.
instrument = instruments.get_instrument_by_ref_id(69694)
# Get instrument by instrument trading symbol eg: HDFCBANK25MAY2380CE, TATAMOTORS, NIFTY2550822400PE
instrument = instruments.get_instrument_by_symbol("HDFCBANK")
# Get instrument by nubra defined name of instrument eg: STOCK_HDFCBANK.NSECM
instrument = instruments.get_instrument_by_nubra_name("STOCK_HDFCBANK.NSECM")
# Fetch multiple instruments matching the pattern passed
instruments = instruments.get_instruments_by_pattern([{
"exchange": "NSE",
"asset": "NIFTY",
"derivative_type": "OPT",
"expiry":"20250522",
"strike_price": "24000",
"option_type": "CE",
"asset_type": "INDEX_FO"
}]
)
Portfolio Data
from nubra_python_sdk.portfolio.portfolio_data import NubraPortfolio
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
# Initialize the Nubra SDK client
nubra = InitNubraSdk(NubraEnv.STAGING)
#Initialize the portfolio
portfolio= NubraPortfolio(nubra)
#Get the Positions of Portfolio
portfolio.positions()
#Get the holding of Portfolio
portfolio.holdings()
#Get the funds of your Portfolio
portfolio.funds()
Making Trades Through API Call
from nubra_python_sdk.trading.trading_data import NubraTrader
from nubra_python_sdk.start_sdk import InitNubraSdk, NubraEnv
#Initialize the Nubra Sdk Client
nubra = InitNubraSdk(NubraEnv.STAGING)
#Initialize the Nubra Tradong Class
trade= NubraTrader(nubra)
#Create Order
result_create_order= trade.create_order({
"ref_id": 70075,
"request_type": "ORDER_REQUEST_NEW",
"order_type": "ORDER_TYPE_LIMIT",
"order_qty": 1,
"order_price": 720,
"order_side": "ORDER_SIDE_BUY",
"order_delivery_type":"ORDER_DELIVERY_TYPE_IDAY",
"execution_type": "STRATEGY_TYPE_MARKET"
})
#Basket Order
result_basket_order= trade.basket_order([{
"ref_id": 70075,
"request_type": "ORDER_REQUEST_NEW",
"order_type": "ORDER_TYPE_LIMIT",
"order_qty": 1,
"order_price": 720,
"order_side": "ORDER_SIDE_BUY",
"order_delivery_type":"ORDER_DELIVERY_TYPE_IDAY",
"execution_type": "STRATEGY_TYPE_MARKET"
},
{
"ref_id": 70075,
"request_type": "ORDER_REQUEST_NEW",
"order_type": "ORDER_TYPE_LIMIT",
"order_qty": 1,
"order_price": 715,
"order_side": "ORDER_SIDE_BUY",
"order_delivery_type":"ORDER_DELIVERY_TYPE_IDAY",
"execution_type": "STRATEGY_TYPE_MARKET"
}
])
#Modify order
trade.modify_order(order_id=999, order_qty=1, order_price= 1300)
#Get All order
all_orders= trade.orders()
#Get Order by order Id
get_order_by_id= trade.get_order(795)
#Cancel Order
cancel_order= trade.cancel_orders([794, 797])
#Cancel Order by Id
cancel_order_by_id= trade.cancel_order_by_id(999)
Support
If you encounter any issues or have questions, please reach out to Nubra Support at support@nubra.io
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nubra_sdk-0.4.0-py3-none-any.whl.
File metadata
- Download URL: nubra_sdk-0.4.0-py3-none-any.whl
- Upload date:
- Size: 77.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe31224ef8b32e208286e2f6fbc6f4ef41c107341b8c2c5e08d97162669f3bbe
|
|
| MD5 |
b01bc2946e56cbb7b6436c0707c9dc29
|
|
| BLAKE2b-256 |
31ff31e6a87ec4f75817f556806ad2bbdd6e9a934ff8b4543dc6ecc52f48c1ee
|