Giter VIP home page Giter VIP logo

apicostfree-zerodha-trade's Introduction

APICostFree Zerodha Trade

An unofficial python library for zerodha trade !!!

Python supported

  • Python >= 3.7

Dependencies

  • requests >= 2.28.1 pip install requests
  • pyotp >= 2.8.0 pip install pyotp
  • pandas >= 1.5.0 pip install pandas
  • selenium >= 4.10.0 pip install selenium
  • webdriver_manager >= 4.10.0 pip install selenium

Requirments

How to use

Update Config.ini USERINFO
[USERINFO]
userid = VIKAS
password = Vikas@123
totpkey = ABCDRFGHIJKLMNOPQRSTUVWXYZ

[ENCTOKEN]
enctoken = abcdefghijklmnopqrstuvwxyz==

Notes - While Using Pykite You can only use Zerodha kite App on Mobile and BrowserView.py

Usages

Creating an instance

from PyKite import pykite
kite = pykite()

Accounts and trades details

# Get user profile details.
print(kite.profile())

# Get account balance and cash margin.
print(kite.margins())

# Fetch all orders
print(kite.orders())

# Fetch all trades
print(kite.trades())

# Fetch all position
print(kite.positions())

# Get order history for particular order
print(kite.order_history('order_id'))

# Get trades history particular order
print(kite.order_trades('order_id'))

Order placing and modify

# Place an order
print(kite.place_order(variety=kite.VARIETY_REGULAR, 
                       exchange=kite.EXCHANGE_NSE, 
                       tradingsymbol="SBIN", 
                       transaction_type=kite.TRANSACTION_TYPE_BUY, 
                       quantity=10, 
                       product=kite.PRODUCT_CNC, 
                       order_type=kite.ORDER_TYPE_LIMIT, 
                       price=500))


# Modify an order
print(kite.modify_order(variety=kite.VARIETY_REGULAR, 
                        order_id='order_id', 
                        quantity="10", 
                        price=550, 
                        order_type=kite.ORDER_TYPE_LIMIT))

# Cancel an order
print(kite.cancel_order(variety=kite.VARIETY_REGULAR, 
                        order_id='order_id', 
                        parent_order_id='parent_order_id'))


# Convert position
print(kite.convert_position(exchange=kite.EXCHANGE_NSE,
                            tradingsymbol="SBIN",
                            transaction_type=kite.TRANSACTION_TYPE_BUY,
                            position_type=kite.POSITION_TYPE_DAY,
                            quantity=10,
                            old_product=kite.PRODUCT_CNC,
                            new_product=kite.PRODUCT_NRML))

Calculate margin required of orders

list_of_order = [{'exchange': 'NFO',
                  'tradingsymbol': 'BANKNIFTY2361544000CE',
                  'transaction_type': 'SELL',
                  'variety': 'regular',
                  'product': 'MIS',
                  'order_type': 'MARKET',
                  'quantity': 25,
                  'price': 0,
                  'trigger_price': 0,
                  'squareoff': 0,
                  'stoploss': 0},
                 {'exchange': 'NFO',
                  'tradingsymbol': 'BANKNIFTY2361544000PE',
                  'transaction_type': 'SELL',
                  'variety': 'regular',
                  'product': 'MIS',
                  'order_type': 'MARKET',
                  'quantity': 25,
                  'price': 0,
                  'trigger_price': 0,
                  'squareoff': 0,
                  'stoploss': 0}]

# Calculate margins considering the existing positions and open orders
print(kite.order_margins(list_of_order).json()['data'])

# Calculate total margins required including margin benefits
print(kite.basket_order_margins(list_of_order).json()['data'])

Market Quotes

instrument_list = ["NSE:SBIN", "NSE:HDFC", "NSE:RELIANCE"]

# Retrieve quote for list of instruments.
print(kite.quotes(instrument_list))

# Retrieve OHLC for list of instruments for current day.
print(kite.ohlc(instrument_list))

# Retrieve Last trade price for list of instruments.
print(kite.ltp(instrument_list))

Instruments data

# fetch all instruments
instrument_all = kite.instruments_data()
print(instrument_all)

# Fetch instrument for particular exchange
instrument_nse = kite.instruments_data("NSE")
print(instrument_nse)

# fetch and download instrument file to disk
instrument_nfo = kite.instruments_data("NFO", download=True, download_path="./instrument_nfo.csv")
print(instrument_nfo)

Historical data

instrument_nse = kite.instruments_data("NSE")
sbin_instrument_token = instrument_nse[instrument_nse['tradingsymbol']=="SBIN"]['instrument_token'].iloc[0]

json_data = kite.historical_data(sbin_instrument_token, 
                                 from_date="2021-01-01 00:00:00", 
                                 to_date="2023-01-01 00:00:00", 
                                 interval='day')

print(json_data['data']['candles'])

apicostfree-zerodha-trade's People

Contributors

vikassharma545 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

apicostfree-zerodha-trade's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.