Giter Site home page Giter Site logo

intraday-stocks-data's Introduction

Intraday Stocks Data 2017 onwards

This code allows you to retrieve data for specific tickers. You can read the pickle file to obtain data for different timeframes such as 1, 2, 5, 10, and 15 minutes for both individual stocks and NIFTY/BANKNIFTY data. The code is flexible and can be extended to fetch data for any symbols of your choice.

The data can be stored in a pickle file, which is a dictionary containing keys in the format (timeframe, Stock).

# Example: Get data for a specific stock and timeframe
import pandas as pd
import pickle

# Example usage:
pickle_file_path = 'MasterDictionary.pkl'

# Read the pickle file to get the data
with open(pickle_file_path, 'rb') as file:
    intraday_data = pickle.load(file)

stock_symbol = 'SBIN'
selected_timeframe = 5  # Replace with the desired timeframe

try:
    data_for_stock = intraday_data[(selected_timeframe, stock_symbol)]
    print(f"Intraday data for {stock_symbol} with {selected_timeframe}-minute timeframe:")
    print(data_for_stock.head())
except KeyError:
    print(f"No data found for {stock_symbol} with {selected_timeframe}-minute timeframe.")

To fetch any symbol from the SQLite DB use this function

def get_dataframe(stockname, timeframe, conn):
    # Use parameterized query to handle special characters in table name
    table_name = f'"{stockname}_{timeframe}"'
    query = f"SELECT Datetime, Close FROM {table_name}"
    
    # Specify the database connection in the function parameters
    df = pd.read_sql_query(query, conn)
    
    # Convert 'Datetime' column to datetime type
    df['Datetime'] = pd.to_datetime(df['Datetime'])
    
    # Set 'Datetime' as the index
    #df.set_index('Datetime', inplace=True)
    
    # Rename 'Close' column to the stock name
    df.rename(columns={'Close': stockname}, inplace=True)
    
    return df

intraday-stocks-data's People

Contributors

sohum-25 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.