Closed ravi14390 closed 3 years ago
@ravi14390 Thanks for reporting there is an issue in alphatrade.py
at line 1059
and 1085
- remove those lines in your local system and it should work.
I will fix the api itself to directly take input as scrip instead of exchange and symbol.
@ravi14390 issue is fixed but you will have to install form github repo.
python -m pip install git+https://github.com/algo2t/alphatrade.git
@ravi14390 I tried to fix this but seems like it is not supported by the platform. Will keep this issue open till I get a solution
The only bypass for your is below code which needs yfinance
import yfinance as yf
ivix = yf.download('^INDIAVIX', period='5d', interval='15m')
print(ivix)
bnf = yf.download('^NSEBANK', period='5d', interval='15m')
print(bnf)
nf = yf.download('^NSEI', period='5d', interval='15m')
print(nf)
@ravi14390 Hi, are you still facing issue? I am working on this API? does it worth time ?
Yes still we cannot download data from GET, it gives empty dataframe.
I removed the following line 1059 # symbol = symbol.upper() from /usr/local/lib/python3.8/site-packages/alphatrade/alphatrade.py
bash-3.2$ python3 historical_data.py Instrument(exchange='NSE', token=26009, symbol='Nifty Bank', name='Nifty Bank', expiry=None, lot_size=None) Instrument(exchange='NSE', token=26009, symbol='Nifty Bank', name='Nifty Bank', expiry=None, lot_size=None) Empty DataFrame Columns: [open, high, low, close, volume] Index: [] bash-3.2$
@rsamikan as already stated alpha web platform doesn't support this so better go for yfinance
Closing this issue as platform does not support it, will reopen if any pull requests are there.
I could make this work by changing the params (exchange: NSE_INDICES & name: instrument.name) and removing the token. Introduced a new method (copy of the get_historical_candles() with changed PARAMS) -
def get_indices_historical_candles(self, exchange, symbol, start_time, end_time, interval=5):
exchange = exchange.upper()
divider = 100
if exchange == 'CDS':
divider = 1e7
# symbol = symbol.upper()
instrument = self.get_instrument_by_symbol(exchange, symbol)
print(instrument)
start_time = int(start_time.timestamp())
end_time = int(end_time.timestamp())
PARAMS = {
'candletype': 1,
'data_duration': interval,
'starttime': start_time,
'endtime': end_time,
'exchange': 'NSE_INDICES',
'type': 'historical',
'name': instrument.name
}
r = self.reqsession.get(
'https://alpha.sasonline.in/api/v1/charts', params=PARAMS, headers=self.__headers)
data = r.json()
return self.__format_candles(data, divider)
@ravi14390 issue is fixed but you will have to install form github repo.
python -m pip install git+https://github.com/algo2t/alphatrade.git
i reinstalled but it is still not coming for the Indices. Any help is highly appreciated.
I could make this work by changing the params (exchange: NSE_INDICES & name: instrument.name) and removing the token. Introduced a new method (copy of the get_historical_candles() with changed PARAMS) -
def get_indices_historical_candles(self, exchange, symbol, start_time, end_time, interval=5): exchange = exchange.upper() divider = 100 if exchange == 'CDS': divider = 1e7 # symbol = symbol.upper() instrument = self.get_instrument_by_symbol(exchange, symbol) print(instrument) start_time = int(start_time.timestamp()) end_time = int(end_time.timestamp()) PARAMS = { 'candletype': 1, 'data_duration': interval, 'starttime': start_time, 'endtime': end_time, 'exchange': 'NSE_INDICES', 'type': 'historical', 'name': instrument.name } r = self.reqsession.get( 'https://alpha.sasonline.in/api/v1/charts', params=PARAMS, headers=self.__headers) data = r.json() return self.__format_candles(data, divider)
thanks it worked.
I came across the resolution to this issue which states that SAS Alpha Web platform does not support historical/intraday data. However, this does not seem to be true.
I think I have figured out what should be used for different indices and FNOs for the 'exchange' and 'symbol' names.
Eg: For indices, we need to have the following in the 'PARAMS' in the functions that get the historical and intra-day data:
exchange: NSE_INDICES symbol: 'Bank Nifty' / 'Nifty 50' / 'Nifty IT' / 'Nifty Auto' etc => Note that there are spaces and it is case sensitive
For FUT, we need to have the following in the 'PARAMS': exchanbe: FNO symbol: 'BANKNIFTY21DECFUT' / 'BANKNIFTY21DEC37800CE' / 'BANKNIFTY21D0937300PE' etc => Note that there are no spaces in between
Can this package be updated to handle the above?
I am trying to get historical and intraday candle data for nifty and bank nifty index but it is giving me error that symbol not found. It is working fine for stocks. Below is my code and error
sas.get_historical_candles('NSE', 'Nifty Bank', start_time, end_time, 5)
ERROR: Cannot find symbol NSE NIFTY BANK in master contract