简体   繁体   中英

how to read the variable value in the statement in python

data = alice.get_instrument_by_symbol(Exchange, EMA) in this command Exchange and EMA both are able to read the data from varialble.

but in the below command data = alice.get_instrument_for_fno(symbol = 'BANKNIFTY', expiry_date=datetime.date(2020, 10, 29), is_fut=False, strike=23200, is_CE = True) ---- working

data = alice.get_instrument_for_fno(symbol = 'Exchange', expiry_date=datetime.date(2020, 10, 29), is_fut=False, strike=23200, is_CE = True) ---- not working ------

if i try to pass the same variable(Excahnge) it is not recognizing it.

looks like i am making some format issue in the python. requesting for the help.

In the first example ( data = alice.get_instrument_by_symbol(Exchange, EMA) ), Exchange and EMA are variables. The Python interpreter replaces them with their values at runtime (ie if Exchange = 'BANKNIFTY' is somewhere previous, EXCHANGE will be replaced with BANKNIFTY ).

In the second example, the symbol keyword argument is getting passed in as a "string literal", meaning you explicitly say 'BANKNIFTY' .

In the third example, you want to still use the Exchange variable (from the first example) as the symbol keyword argument to get_instrument_for_fno :

data = alice.get_instrument_for_fno(
    symbol = Exchange,  # Notice the lack of quotes
    expiry_date = datetime.date(2020, 10, 29),
    is_fut = False,
    strike = 23200,
    is_CE = True,
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM