Skip to main content

Firstock Connect API Python Client

The official Python library for the Firstock Connect API, providing a seamless interaction with Firstock's trading and financial data services. This library has been designed for developers to easily integrate Firstock's advanced trading capabilities into their Python applications.

Features

  • HTTP calls are converted to methods.
  • JSON responses are wrapped into Python-compatible objects.
  • The handling of WebSocket connections is automated.

Installation

This module is installed via pip:

pip install firstock

Getting started with API

The API consists of five major section

  • Login & Profile
  • Orders & Report
  • Market Connect

Login

For the Login process we require to generate the appkey and vendor code by logging in with the firstock credentials in the give link Key Generation.

from firstock import firstock

login = firstock.login(
    userId="{{userID}}",
    password="{{Password}}",
    TOTP="{{TOTP}}",
    vendorCode="{{vendorCode}}",
    apiKey="{{apiKey}}",
  )

Logout

from firstock import firstock

logout = firstock.logout(userId="{{userId}}")

User Details

from firstock import firstock

userDetails = firstock.userDetails(userId="{{userId}}")

Place Order

from firstock import firstock

placeOrder = firstock.placeOrder(
    userId="{{userId}}",
    exchange="NSE",
    tradingSymbol="ITC-EQ",
    quantity="1",
    price="300",
    product="I",
    transactionType="B",
    priceType="LMT",
    retention="DAY",
    triggerPrice="0",
    remarks="Python Package Order"
)

Order Margin

from firstock import firstock

orderMargin = firstock.orderMargin(
    userId="{{userId}}",
    exchange="NSE",
    tradingSymbol="ITC-EQ",
    quantity="1",
    priceType="LMT",
    product="C",
    price="350",
    transactionType="B"
)

Order Book

from firstock import firstock

orderBook = firstock.orderBook(userId="{{userId}}")

Cancel Order

from firstock import firstock

cancelOrder = firstock.cancelOrder(
    userId="{{userId}}",
    orderNumber="25063000011862"
)

Modify Order

from firstock import firstock

modifyOrder = firstock.modifyOrder(
    userId="{{userId}}",
    orderNumber="25070100015934",
    quantity="1",
    price="418",
    triggerPrice="0",
    tradingSymbol="IDEA-EQ",
    priceType="LMT",
    retention="DAY",
    mkt_protection="0.5",
    product="C"
)

Single Order History

from firstock import firstock

singleOrderHistory = firstock.singleOrderHistory(
    userId="{{userId}}",
    orderNumber="25063000011911"
)

Trade Book

from firstock import firstock

tradeBook = firstock.tradeBook(userId="{{userId}}")

Position Book

from firstock import firstock

positionBook = firstock.positionBook(userId="{{userId}}")

Convert Product

from firstock import firstock

convertProduct = firstock.productConversion(
    userId="{{userId}}",
    transactionType="B",
    tradingSymbol="ITC-EQ",
    quantity="1",
    product="C",
    previousProduct="I",
    positionType="DAY",
    exchange="NSE"
)

Holdings

from firstock import firstock

holdings = firstock.holdings(userId="{{userId}}")

Limits

from firstock import firstock

limits = firstock.limit(userId="{{userId}}")

Basket Margin

from firstock import firstock

basketMargin = firstock.basketMargin(
    userId="{{userId}}",
    exchange="NSE",
    transactionType="B",
    product="C",
    tradingSymbol="RELIANCE-EQ",
    quantity="1",
    priceType="MKT",
    price="0",
    BasketList_Params=[
        {
            "exchange": "NSE",
            "tradingSymbol": "IDEA-EQ",
            "quantity": "1",
            "transactionType": "B",
            "price": "0",
            "product": "C",
            "priceType": "MKT"
        }
    ]
)

Get Security Info

from firstock import firstock

getSecurityInfo = firstock.securityInfo(
    userId="{{userId}}",
    exchange="NSE",
    tradingSymbol="NIFTY"
)

Get Quote

from firstock import firstock

getQuotes = firstock.getQuote(
    userId="{{userId}}",
    exchange="NSE",
    tradingSymbol="NIFTY"
)

Get Index List

from firstock import firstock

getIndexList = firstock.indexList(userId="{{userId}}")

Option Chain

from firstock import firstock

optionChain = firstock.optionChain(
    userId="{{userId}}",
    exchange="NFO",
    symbol="NIFTY",
    strikePrice="23150",
    expiry="03JUL25",
    count="5"
)

Option Chain Greeks

from firstock import firstock

optionChainGreeks = firstock.optionChainGreeks(
    userId=userId,
    exchange="",
    symbol="",
    expiry="",
    count="",
    strikePrice=""
)

Search Scrips

from firstock import firstock

searchScrips = firstock.searchScrips(
    userId="{{userId}}",
    stext="ITC"
)

Get Quote LTP

from firstock import firstock

getQuoteLtp = firstock.getQuoteltp(
    userId="{{userId}}",
    exchange="NSE",
    tradingSymbol="RELIANCE-EQ"
)

Get Multi Quote

from firstock import firstock

multiQuote = firstock.getMultiQuotes(
    userId="{{userId}}",
    dataToken=[
        {
            "exchange": "NSE",
            "tradingSymbol": "Nifty 50"
        },
        {
            "exchange": "NFO",
            "tradingSymbol": "NIFTY03APR25C23500"
        }
    ]
)

Get Multi Quote LTP

from firstock import firstock

multiQuoteLtp = firstock.getMultiQuotesltp(
    userId="{{userId}}",
    dataToken=[
        {
            "exchange": "NSE",
            "tradingSymbol": "Nifty 50"
        },
        {
            "exchange": "NSE",
            "tradingSymbol": "Nifty Bank"
        }
    ]
)

Brokerage Calculator

from firstock import firstock

brokerageCalc = firstock.brokerageCalculator(
    userId="{{userId}}",
    exchange="NFO",
    tradingSymbol="RELIANCE27FEB25F",
    transactionType="B",
    product="M",
    quantity="500",
    price="125930",
    strike_price="0",
    inst_name="FUTSTK",
    lot_size="1"
)

Get Expiry

from firstock import firstock

getExpiry = firstock.getExpiry(
    userId="{{userId}}",
    exchange="NSE",
    tradingSymbol="NIFTY"
)

Time Price Series

from firstock import firstock

timePriceSeries = firstock.TimePriceSeries(
    userId="{{userId}}",
    exchange="NSE",
    tradingSymbol="Nifty 50",
    startTime="13/02/2023 09:45:45",
    endTime="13/12/2023 13:56:34",
    interval="30"
)

Get Holdings Details

from firstock import firstock

holdings_details = firstock.getHoldingsDetails(
    userId="{{userId}}"
)

Place Gtt order

from firstock import firstock
 
place_gtt = firstock.placeGtt(
    userId={{userId}},
    jKey={{Jkey}},
    tradingSymbol="IDEA-EQ",
    exchange="NSE",
    validity="GTT",
    value="8.15",
    remarks="GTT",
    OrderParams={
        "exchange": "NSE",
        "retention": "DAY",
        "product": "C",
        "priceType": "SL-LMT",
        "tradingSymbol": "IDEA-EQ",
        "transactionType": "B",
        "price": "8.90",
        "triggerPrice": "8.15",
        "quantity": "10",
        "remarks": "Test"
    }
)

Modify Gtt order

from firstock import firstock
 
modifyGtt = firstock.modifyGtt(
    userId={{userId}},
    jKey={{jkey}},
    tradingSymbol="IDEA-EQ",
    exchange="NSE",
    validity="GTT",
    GTTid="26032500000094",
    remarks="GTT",
    OrderParams={
        "exchange": "NSE",
        "retention": "DAY",
        "product": "C",
        "priceType": "SL-LMT",
        "tradingSymbol": "IDEA-EQ",
        "transactionType": "B",
        "price": "8.90",
        "triggerPrice": "8.27",
        "quantity": "10",
        "remarks": "Test"
    }
)

Cancel Gtt order

from firstock import firstock

cancel_gtt = firstock.cancelGtt(
    userId={{userId}},
    jKey={{jkey}},
    GTTid="26032500000008"
)

Gtt order book

from firstock import firstock
 
gtt_orders  = firstock.getGtt(
    userId={{userId}},
    jKey={{jkey}}
)

Place AMO

from firstock import firstock

placeAMO = firstock.placeAMO(
    userId=userId,
    exchange="",
    tradingSymbol="",
    quantity="",
    price="",
    product="",
    transactionType="",
    priceType="",
    retention="",
    triggerPrice="",
    remarks=""
)

Modify AMO

from firstock import firstock

modifyAMO = firstock.modifyAMO(
    userId=userId,
    orderNumber="",
    quantity="",
    price="",
    priceType="",
    product="",
    triggerPrice=""
)

Place OCO Order

placeOcoOrder = firstock.placeOcoOrder(
  userId="{{userId}}",
  exchange= "NSE",
  tradingSymbol= "VIKASECO-EQ",
  validity= "GTT",
  OrderParamsLeg1= {
    "transactionType": "S",
    "priceType": "LMT",
    "product": "C",
    "retention": "DAY",
    "triggerPrice": "0.95",
    "quantity": "1",
    "price": "0.94"
  },
  OrderParamsLeg2= {
    "transactionType": "S",
    "priceType": "LMT",
    "product": "C",
    "retention": "DAY",
    "triggerPrice": "1.18",
    "quantity": "1",
    "targetPrice": "1.20"
  }
)

print(placeOcoOrder)

Modify OCO Order

modifyOcoOrderData = firstock.modifyOcoOrder(
  userId="{{userId}}",
  OCOid="{{OCOid}}",
  exchange= "NSE",
  tradingSymbol= "VIKASECO-EQ",
  OrderParamsLeg1= {
    "transactionType": "S",
    "priceType": "LMT",
    "product": "C",
    "retention": "DAY",
    "triggerPrice": "0.95",
    "quantity": "1",
    "price": "0.94"
  },
  OrderParamsLeg2= {
    "transactionType": "S",
    "priceType": "LMT",
    "product": "C",
    "retention": "DAY",
    "triggerPrice": "1.18",
    "quantity": "1",
    "targetPrice": "1.20"
  }
)

print(modifyOcoOrderData)

Cancel OCO Order

cancelOcoOrderData = firstock.cancelOcoOrder(
  userId="{{userId}}",
  OCOid="26100800000040"
)

print(cancelOcoOrderData)

Refer to the Firstock Connect Documentation for the complete list of supported methods.

Changelog

  • The Python package has been updated to automatically convert passwords into SHA256 hashes prior to submission to the login URL.

  • The package now includes a multi-login feature, enabling simultaneous login for multiple users, with each user's session being individually stored.

  • For all APIs, it is now required to pass the userId. The corresponding jKey session linked to the userId will be utilized for executing the API.

  • The following methods have been updated to require trading symbols instead of tokens:

    • Get Multi Quotes LTP
    • Get Multi Quotes
    • Day Interval Time Price Series
    • Time Price Series
    • Security Info
    • Get Quotes
  • The method for accessing the websocket has been entirely revamped. Detailed information will be available in an upcoming blog post. Additionally, sample code illustrating the new method can be found in the examples section.

[1.1.3] - 2026-01-31

Changed

  • Minor version bump for compatibility updates.

Metadata

Release files for firstock 1.2.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for firstock 1.2.11
File Size Uploaded
firstock-1.2.11.tar.gz 36.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for firstock 1.2.11
File Interpreter ABI Platform
firstock-1.2.11-py3-none-any.whl Python 3 none any Details

Total release size: 157.1 kB

Release files / firstock-1.2.11.tar.gz

Download URL firstock-1.2.11.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b3f737d0f13d1ad044c71b8d188f42dce8ab4a49cf206876d7a45f8c6e3fa19b
BLAKE2b-256 checksum
How to use checksums
6787a8c13a301f55c08c4ad1977673c59bd826d9119c0d9bf0bb47e812f6c0ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.4

Release files / firstock-1.2.11-py3-none-any.whl

Download URL firstock-1.2.11-py3-none-any.whl
Size 120.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2dda62e18ae2e755c60d645148cf32b693e27823cbd8ff67299eae9c1caf9004
BLAKE2b-256 checksum
How to use checksums
fb2303c8a6eabd03b6f40fb1dfa08bd0f0280ea424919aa23b151bbf8c7a64a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.2.11 This release

2 release files

1.1.11

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page