nsetools package

Submodules

nsetools.bases module

The MIT License (MIT)

Copyright (c) 2014 Vivek Jha

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class nsetools.bases.AbstractBaseExchange

Bases: object

get_quote(code)
Parameters:code – a stock code
Returns:a dictionary which contain detailed stock code.
get_stock_codes()
Returns:list of tuples with stock code and stock name
get_top_gainers()
Returns:a sorted list of codes of top gainers
get_top_losers()
Returns:a sorted list of codes of top losers
is_valid_code(code)
Returns:True, if it is a valid stock code, else False

nsetools.nse module

The MIT License (MIT)

Copyright (c) 2014 Vivek Jha

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class nsetools.nse.Nse

Bases: nsetools.bases.AbstractBaseExchange

class which implements all the functionality for National Stock Exchange

build_url_for_quote(code)

builds a url which can be requested for a given stock code :param code: string containing stock code. :return: a url object

clean_server_response(resp_dict)
cleans the server reponse by replacing:
‘-‘ -> None ‘1,000’ -> 1000
Parameters:resp_dict
Returns:dict with all above substitution
get_advances_declines(as_json=False)
Returns:a list of dictionaries with advance decline data
Raises:URLError, HTTPError
get_index_list(as_json=False)

get list of indices and codes params:

as_json: True | False

returns: a list | json of index codes

get_index_quote(code, as_json=False)
params:
code : string index code as_json: True|False
returns:
a dict | json quote for the given index
get_quote(code, as_json=False)

gets the quote for a given stock code :param code: :return: dict or None :raises: HTTPError, URLError

get_stock_codes(cached=True, as_json=False)

returns a dictionary with key as stock code and value as stock name. It also implements cache functionality and hits the server only if user insists or cache is empty :return: dict

get_top_gainers(as_json=False)
Returns:a list of dictionaries containing top gainers of the day
get_top_losers(as_json=False)
Returns:a list of dictionaries containing top losers of the day
is_valid_code(code)
Parameters:code – a string stock code
Returns:Boolean
is_valid_index(code)

returns: True | Flase , based on whether code is valid

nse_headers()

Builds right set of headers for requesting http://nseindia.com :return: a dict with http headers

nse_opener()

builds opener for urllib2 :return: opener object

render_response(data, as_json=False)

nsetools.setup module

Module contents

The MIT License (MIT)

Copyright (c) 2014 Vivek Jha

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.