Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Algorithmic Trading Cookbook

You're reading from   Python Algorithmic Trading Cookbook All the recipes you need to implement your own algorithmic trading strategies in Python

Arrow left icon
Product type Paperback
Published in Aug 2020
Publisher Packt
ISBN-13 9781838989354
Length 542 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Pushpak Dagade Pushpak Dagade
Author Profile Icon Pushpak Dagade
Pushpak Dagade
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Handling and Manipulating Date, Time, and Time Series Data 2. Stock Markets - Primer on Trading FREE CHAPTER 3. Fetching Financial Data 4. Computing Candlesticks and Historical Data 5. Computing and Plotting Technical Indicators 6. Placing Regular Orders on the Exchange 7. Placing Bracket and Cover Orders on the Exchange 8. Algorithmic Trading Strategies - Coding Step by Step 9. Algorithmic Trading - Backtesting 10. Algorithmic Trading - Paper Trading 11. Algorithmic Trading - Real Trading 12. Other Books You May Enjoy Appendix I
1. Appendix II
2. Appendix III

Querying a list of instruments

Once the broker_connection handle is ready, it can be used to query the list containing all the financial instruments provided by the broker.

Getting ready

Make sure the broker_connection object is available in your Python namespace. Refer to the previous recipe in this chapter to set up this object.

How to do it…

We execute the following steps to complete this recipe:

  1. Display all the instruments:
>>> instruments = broker_connection.get_all_instruments()
>>> instruments

You will get an output similar to the following. The exact output may differ for you:

  instrument_token exchange_token tradingsymbol name last_price expiry strike tick_size lot_size instrument_type segment exchange
0 267556358 1045142 EURINR20AUGFUT EURINR 0.0 2020-08-27 0.0 0.0025 1 FUT BCD-FUT BCD
1 268660998 1049457 EURINR20DECFUT EURINR 0.0 2020-12-29 0.0 0.0025 1 FUT BCD-FUT BCD
2 266440966 1040785 EURINR20JULFUT EURINR 0.0 2020-07-29 0.0 0.0025 1 FUT BCD-FUT BCD
3 266073606 1039350 EURINR20JUNFUT EURINR 0.0 2020-06-26 0.0 0.0025 1 FUT BCD-FUT BCD
4 265780742 1038206 EURINR20MAYFUT EURINR 0.0 2020-05-27 0.0 0.0025 1 FUT BCD-FUT BCD
... ... ... ... ... ... ... ... ... ... ... ... ...
64738 978945 3824 ZODJRDMKJ ZODIAC JRD-MKJ 0.0 0.0 0.0500 1 EQ NSE NSE
64739 2916865 11394 ZOTA ZOTA HEALTH CARE 0.0 0.0 0.0500 1 EQ NSE NSE
64740 7437825 29054 ZUARI-BE ZUARI AGRO CHEMICALS 0.0 0.0 0.0500 1 EQ NSE NSE
64741 979713 3827 ZUARIGLOB ZUARI GLOBAL 0.0 0.0 0.0500 1 EQ NSE NSE
64742 4514561 17635 ZYDUSWELL ZYDUS WELLNESS 0.0 0.0 0.0500 1 EQ NSE NSE

64743 rows × 12 columns
  1. Print the total number of instruments:
>>> print(f'Total instruments: {len(instruments)}')

We get the following output (your output may differ):

Total instruments: 64743

How it works…

The first step fetches all the available financial instruments using the get_all_instruments() method of broker_connection. This method returns a pandas.DataFrame object. This object is assigned to a new variable, instruments, which is shown in the output of step 1. This output may differ for you as new financial instruments are frequently added and existing ones expire regularly. The final step shows the total number of instruments provided by the broker.

An explanation of the data that was returned by the preceding API call will be discussed in depth in Chapter 3, Analyzing Financial Data. For this recipe, it suffices to know the method for fetching the list of instruments.
You have been reading a chapter from
Python Algorithmic Trading Cookbook
Published in: Aug 2020
Publisher: Packt
ISBN-13: 9781838989354
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image