krishnavelu / alice_blue

Official Python library for Alice Blue API trading
GNU General Public License v3.0
133 stars 82 forks source link

SILVERMIC fetch data #493

Closed gousKDT closed 1 year ago

gousKDT commented 1 year ago

Hi Krishna,

How do reuse your code to get the SILVERMIC futu data

symbol_cepe = alice.get_instrument_for_fno(symbol = 'SILVERMIC', expiry_date=datetime.date(yy, mm, dd), is_fut=True, strike=None, is_CE = False)

It throws below erro: Unable to understand. Could you please help.

raise TypeError("Required parameter instrument is not of type Instrument") TypeError: Required parameter instrument is not of type Instrument

srinidhihebbar260297 commented 1 year ago

Expiry date of the future contract needs to be mentioned.

gousKDT commented 1 year ago

Mentioned but yet, it throws error mentioned above

srinidhihebbar260297 commented 1 year ago

What is the end goal, is it a semi algo ? also, which is the expiry you are trying to trade ?

gousKDT commented 1 year ago

SILVERMIC23FEBFUT

srinidhihebbar260297 commented 1 year ago

`alice=AliceBlue(username = name, session_id = session_id, master_contracts_to_download=['MCX','NFO']) all_scripts =pd.DataFrame( alice.search_instruments('MCX', 'silver')) fut=all_scripts.loc[all_scripts['symbol'].str[-3:]=='FUT'].sort_values(by='expiry') silverfut=alice.get_instrument_for_fno(symbol = fut.iloc[0]['symbol'], expiry_date=fut.iloc[0]['expiry'], is_fut=True,strike=None, is_CE = False)

`

Fetching the nearest expiry, use the Iloc to change expiries

gousKDT commented 1 year ago

alice=AliceBlue(username = name, session_id = session_id, master_contracts_to_download=['MCX','NFO']) all_scripts =pd.DataFrame( alice.search_instruments('MCX', 'silver')) fut=all_scripts.loc[all_scripts['symbol'].str[-3:]=='FUT'].sort_values(by='expiry') silverfut=alice.get_instrument_for_fno(symbol = fut.iloc[0]['symbol'], expiry_date=fut.iloc[0]['expiry'], is_fut=True,strike=None, is_CE = False)

Let me test it today and provide my output/reponse

srinidhihebbar260297 commented 1 year ago

Are you able to download FNO contracts ?

srinidhihebbar260297 commented 1 year ago

Use the below code, it will fetch just silver MIC contracts and select the nearest expiry

'alice=AliceBlue(username = name, session_id = session_id, master_contracts_to_download=['MCX']) all_scripts =pd.DataFrame( alice.search_instruments('MCX', 'silver')) fut=all_scripts.loc[all_scripts['symbol'].str[-3:]=='FUT'].sort_values(by='expiry') fut=fut.loc[fut['lot_size']=='1'] silverfut=alice.get_instrument_for_fno(symbol = fut.iloc[0]['symbol'], expiry_date=fut.iloc[0]['expiry'], is_fut=True,strike=None, is_CE = False)

'

gousKDT commented 1 year ago

Use the below code, it will fetch just silver MIC contracts and select the nearest expiry

'alice=AliceBlue(username = name, session_id = session_id, master_contracts_to_download=['MCX']) all_scripts =pd.DataFrame( alice.search_instruments('MCX', 'silver')) fut=all_scripts.loc[all_scripts['symbol'].str[-3:]=='FUT'].sort_values(by='expiry') fut=fut.loc[fut['lot_size']=='1'] silverfut=alice.get_instrument_for_fno(symbol = fut.iloc[0]['symbol'], expiry_date=fut.iloc[0]['expiry'], is_fut=True,strike=None, is_CE = False)

'

Sure, I will test this in the evening and surely will send my experience and response. Appreciate your inputs

gousKDT commented 1 year ago

alice = AliceBlue(username = "xxxxxx", session_id = session_id, master_contracts_to_download=['NFO', 'MCX'])

all_scripts =pd.DataFrame( alice.search_instruments('MCX', 'silver')) fut=all_scripts.loc[all_scripts['symbol'].str[-3:]=='FUT'].sort_values(by='expiry') print(fut.iloc[0]['symbol']) print(fut.iloc[0]['expiry'])

gave me the below output SILVERMIC23FEBFUT 2023-02-28

Next call is: symbol_fno = alice.get_instrument_for_fno(symbol=fut.iloc[0]['symbol'], expiry_date=fut.iloc[0]['expiry'], is_fut=True, strike=None, is_CE=False)

print(symbol_fno) is returning None

Any idea what am I missing here?

srinidhihebbar260297 commented 1 year ago

Are you able to download the master FNO Contracts?

The official wrapper is throwing an error for me , I switched to the official SDK

gousKDT commented 1 year ago

fut=all_scripts.loc[all_scripts['symbol'].str[-3:]=='FUT'].sort_values(by='expiry') print(fut)

Resulted: exchange token ... expiry lot_size 668 MCX 242738 ... 2023-02-28 1 1849 MCX 239260 ... 2023-02-28 5 1848 MCX 239259 ... 2023-03-03 30 838 MCX 245470 ... 2023-04-28 1 899 MCX 241934 ... 2023-04-28 5 898 MCX 241933 ... 2023-05-05 30 867 MCX 247931 ... 2023-06-30 1 950 MCX 244732 ... 2023-06-30 5 949 MCX 244731 ... 2023-07-05 30 897 MCX 250060 ... 2023-08-31 1 1236 MCX 247117 ... 2023-08-31 5 1235 MCX 247116 ... 2023-09-05 30 708 MCX 248401 ... 2023-11-30 5 205 MCX 250882 ... 2023-12-05 30

[14 rows x 6 columns]

gousKDT commented 1 year ago

Getting following error as related issue:

raise TypeError("Required parameter instrument is not of type Instrument") TypeError: Required parameter instrument is not of type Instrument

alice.subscribe(symbol_fno, LiveFeedType.TICK_DATA) Is there something wrong in the statement?

Detailed error as below File "C:\Users\Administrator\Documents\alice_blue\alice_blue\alice_blue.py", line 782, in subscribe raise TypeError("Required parameter instrument is not of type Instrument") TypeError: Required parameter instrument is not of type Instrument

srinidhihebbar260297 commented 1 year ago

Please place the code as well.

krishnavelu commented 1 year ago

@gousKDT I'm able to get results using this.

print(alice.get_instrument_for_fno(symbol = 'SILVERMIC', expiry_date=datetime.date(2023, 2, 28), is_fut=True, strike=None, is_CE = False, exchange = "MCX"))

Result Instrument(exchange='MCX', token=242738, symbol='SILVERMIC23FEBFUT', name='SILVERMIC 28FEB23 FUT', expiry=datetime.date(2023, 2, 28), lot_size='1')

krishnavelu commented 1 year ago

While posting the sample code use the actual dates you gave. Otherwise how will I know which dates you are trying?

image
krishnavelu commented 1 year ago

Closing this issue, reopen if needed.

gousKDT commented 1 year ago

symbol = 'SILVERMIC' , yes this change is working for me as well.