Exemplo n.º 1
0
         strike_price=ce_value['strikePrice'],
         option_type='CE',
         expiry_date=ce_value['expiryDate'],
         identifier=ce_value['identifier'],
         open_interest=ce_value['openInterest'],
         change_in_oi=ce_value['changeinOpenInterest'],
         percent_change_in_oi=ce_value['pchangeinOpenInterest'],
         total_traded_volume=ce_value['totalTradedVolume'],
         implied_volatility=ce_value['impliedVolatility'],
         last_price=ce_value['lastPrice'],
         change=ce_value['change'],
         total_buy_quantity=ce_value['totalBuyQuantity'],
         total_sell_quantity=ce_value['totalSellQuantity'],
         underlying_value=ce_value['underlyingValue'])
     # print(stock_ce_option)
     session.add(stock_ce_option)
 if 'PE' in option_data:
     pe_value = option_data['PE']
     stock_pe_option = NseStockOptionDaily(
         stock_id=stock.stock_id,
         trade_date=trade_date,
         stock_code=stock.stock_code,
         strike_price=pe_value['strikePrice'],
         option_type='PE',
         expiry_date=pe_value['expiryDate'],
         identifier=pe_value['identifier'],
         open_interest=pe_value['openInterest'],
         change_in_oi=pe_value['changeinOpenInterest'],
         percent_change_in_oi=pe_value['pchangeinOpenInterest'],
         total_traded_volume=pe_value['totalTradedVolume'],
         implied_volatility=pe_value['impliedVolatility'],
                        stock_code=stock_ohlc_data["Symbol"][ind],
                        series=stock_ohlc_data["Series"][ind],
                        prev_close=stock_ohlc_data["Prev Close"][ind],
                        open=stock_ohlc_data["Open"][ind],
                        high=stock_ohlc_data["High"][ind],
                        low=stock_ohlc_data["Low"][ind],
                        close=stock_ohlc_data["Close"][ind],
                        volume=stock_ohlc_data["Volume"][ind].item(),
                        vwap=stock_ohlc_data["VWAP"][ind],
                        trades=stock_ohlc_data["Trades"][ind].item(),
                        deliverable_volume=stock_ohlc_data[
                            "Deliverable Volume"][ind].item(),
                        percentage_delivery=stock_ohlc_data["%Deliverble"]
                        [ind])
                    # print(nseDaily)
                    session.add(nseDaily)
                    print("END: Inserted into DB......")
                except Exception as ex:
                    print("ERROR: while Create NSEDAILY Object:")
                    print(ex)

        try:
            session.commit()
            session.query(StockList).filter(
                StockList.stock_code == stock.stock_code).update(
                    {StockList.cash_updated: todaysDate},
                    synchronize_session=False)
            session.commit()
        except Exception as ex:
            print("ERROR: while Commiting Last Session Data......")
            print(ex)
Exemplo n.º 3
0
                        expiry_date=expiry_date,
                        open=stock_ohlc_data["Open"][ind],
                        high=stock_ohlc_data["High"][ind],
                        low=stock_ohlc_data["Low"][ind],
                        close=stock_ohlc_data["Close"][ind],
                        last_price=stock_ohlc_data["Last"][ind],
                        settle_price=stock_ohlc_data["Settle Price"][ind],
                        no_of_contracts=stock_ohlc_data["Number of Contracts"]
                        [ind].item(),
                        open_interest=stock_ohlc_data["Open Interest"]
                        [ind].item(),
                        change_in_oi=stock_ohlc_data["Change in OI"]
                        [ind].item(),
                        underlying=stock_ohlc_data["Underlying"][ind])
                    # print(nseFNODaily)
                    session.add(nseFNODaily)
                # print("END: Inserted into DB......")

            try:
                session.commit()
                session.query(StockList).filter(
                    StockList.stock_code == stock.stock_code).update(
                        {StockList.fno_updated: todaysDate},
                        synchronize_session=False)
                session.commit()
            except Exception as ex:
                print("Error while committing transaction...")
                print(ex)

# session.query(StockList).update({StockList.downloaded:False},synchronize_session=False)
# session.commit()