コード例 #1
0
def cleanOlderData():
    session.query(NseCashDaily).filter(
        NseCashDaily.trade_date < (todaysDate - timedelta(days=365))).delete()
    session.commit()
コード例 #2
0
todaysDate = datetime.today().date()


# Clean Cash data older than 365 days
def cleanOlderData():
    session.query(NseCashDaily).filter(
        NseCashDaily.trade_date < (todaysDate - timedelta(days=365))).delete()
    session.commit()


cleanOlderData()

# print("Starting Data Download from :" + str(fromDate) + " to :" + str(toDate))

start_time = time.time()
stocks = session.query(StockList)
for stock in stocks:
    print("######################## Running for Stock:" + stock.stock_code)
    if stock.cash_updated < todaysDate:
        print("START : Getting History......")
        stock_ohlc_data = get_history_wrapper(symbol=stock.stock_code,
                                              start=stock.cash_updated,
                                              end=todaysDate)
        print("END : Got History......")
        for ind in stock_ohlc_data.index:
            if stock_ohlc_data.index.values.size > 0:
                try:
                    print("START: Inserting into DB......")
                    trade_date = ind
                    # print(type(stock_ohlc_data["Volume"][ind].item()))
                    print(stock_ohlc_data["Volume"][ind].item())
コード例 #3
0
def cleanupOldFnOData():
    session.query(NseStockOptionDaily).filter(
        NseStockOptionDaily.expiry_date < todaysDate).delete()
    session.commit()
コード例 #4
0
import json

todaysDate = datetime.today().date()
trade_date = nse_utils.getLastUpdateOptionDate()


# Remove data expiry < todays Date
def cleanupOldFnOData():
    session.query(NseStockOptionDaily).filter(
        NseStockOptionDaily.expiry_date < todaysDate).delete()
    session.commit()


cleanupOldFnOData()

stocks = session.query(StockList).filter(StockList.fno == True,
                                         StockList.indices == False)
for stock in stocks:

    if stock.stock_opt_updated < todaysDate:
        print("######################## Running for Stock:" + stock.stock_code)
        option_chain = nse_urls.get_equities_opt_chain_url(
            stock.stock_code).text
        option_chain_json = json.loads(option_chain)
        # print(option_chain_json)
        # ce_values = [ceData for ceData in option_chain_json["filtered"]["data"][1]["CE"]]
        # session.bulk_insert_mappings()
        for option_data in option_chain_json["records"]["data"]:
            if 'CE' in option_data:
                ce_value = option_data['CE']
                # print(ce_value)
                stock_ce_option = NseStockOptionDaily(
コード例 #5
0
def cleanupOldFnOData():
    session.query(NseFNODaily).filter(
        NseFNODaily.expiry_date < todaysDate).delete()
    session.commit()


cleanupOldFnOData()

# get Next 3 Expiry data for today
expiry_dates = nse_utils.findNextExpiryDatesForStocks()

# #with pd.option_context('display.max_rows', None, 'display.max_columns', None):  # more options can be specified also
# #    print(stock_ohlc_data)
#

indices = session.query(StockList).filter(StockList.indices == True)
indices_list = [ind.stock_code for ind in indices]

stocks = session.query(StockList).filter(StockList.fno == True)

for stock in stocks:
    print("######################## Running for Stock:" + stock.stock_code)
    if stock.fno_updated < todaysDate:
        for expiry_date in expiry_dates:

            stock_ohlc_data = get_history(
                symbol=stock.stock_code,
                start=stock.fno_updated,
                end=todaysDate,
                expiry_date=expiry_date,
                futures=True,
コード例 #6
0
def cleanupOldFnOData():
    session.query(NseIndicesOptionDaily.expiry_date < trade_date).delete()
    session.commit()