Search This Blog

Friday, August 30, 2019

Python Schedule at every specific Time Interval

1. Install schedule plugin
2. use the below sample

schedulers.py

# Schedule Library imported
import schedule
import time
import datetime

def doScheduler ():
    print ( "Schedule starts @ ", datetime.datetime.now() );

# Task scheduling
# After every 10mins doScheduler () is called. 
schedule.every(10).minutes.do(doScheduler )
  
# After every hour doScheduler () is called.
schedule.every().hour.do(doScheduler )
  
# Every day at 12am or 00:00 time doScheduler () is called.
schedule.every().day.at("00:00").do(doScheduler )
  
# After every 5 to 10mins in between run doScheduler ()
schedule.every(5).to(10).minutes.do(doScheduler )
  
# Every monday doScheduler () is called
schedule.every().monday.do(doScheduler )
  
# Every tuesday at 18:00 doScheduler () is called
schedule.every().tuesday.at("18:00").do(doScheduler )

if __name__ == "__main__": schedule.every( 3 ).minutes.do( doScheduler )   
# Loop so that the scheduling task
# keeps on running all time.
while True:
  
     # Checks whether a scheduled task 
     # is pending to run or not
     schedule.run_pending()
     time.sleep(1)



#Enjoy !

Python Code to pull NSE Option Derivative HTML to JSON on Every N minutes

1. Install Python, PIP
2. type the below command from your python sample folder [ by pip or pip3 cmd ].
     pip install beautifulsoup
     OR
     pip install BeautifulSoup4
     pip install requests
     pip install schedule
     python nse_options.py

-- ENJOY

nse_options.py

# author - dr. vijay
# email - drvijayy2k2@gmail.com
# date - 30-08-2019 7:30 PM

# install plugin
# pip install BeautifulSoup

import sys
import json
import requests
# Schedule Library imported
import schedule
import time
import datetime

from bs4 import BeautifulSoup

base_url = 'https://www.nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbol=';


def doScheduler ():
    print ( "Schedule starts @ ", datetime.datetime.now() );
    result = parseNseOptions ( 'NIFTY' );
    # result = parseNseOptions ( 'INFY' );
    f = open( 'D:/nseOptionst.txt', 'a' )
    f.write( str(result) + "\n" );
    print ( "Done !" );
 

def parseNseOptions ( scrip='NIFTY' ):
    url = base_url + scrip;
    response = response = requests.get( url ) 
    if( response != None and response.ok ):
        optionScripListHtml = response.content
        # print ( optionScripListHtml );
        soup = BeautifulSoup( optionScripListHtml, "html.parser" )
        tableHtml = soup.find( "table", id="octable" )
        f1 = tableHtml.findAll( "thead" )[0].findAll( 'tr' )
     
        callDataColumnEndsAt = 11
        optionStrikePriceColumnAt = ( 12 - 1 )
        putDataColumnEndsAt = 23
        headers = {}
        headersOnIndex = {}
        h1 = f1[1].findAll( "th" )
        for index, h in enumerate( h1, start=0 ):
            if ( index < callDataColumnEndsAt ):
                headers["call-" + h.text] = h.get( "title", "" )
                headersOnIndex[index] = "call-" + h.text 
            elif ( index == optionStrikePriceColumnAt ):
                 headers[h.text] = h.get( "title", "" )
                 headersOnIndex[index] = h.text 
            elif ( index < putDataColumnEndsAt ):
                headers["put-" + h.text] = h.get( "title", "" )
                headersOnIndex[index] = "put-" + h.text 
        # print(headersOnIndex)
     
        fnoDataRows = tableHtml.findAll( "tr" )
        tempMap = {}
        totalOptionPCOI = {}
        tempMapWithStrikePriceAsKey = {}
        startingRow = 3
        endingRow = len( fnoDataRows )
        callOIChangeCol = 2
        callTotalChangeInOIValue = 0
        putOIChangeCol = 20
        putTotalChangeInOIValue = 0
        index = 1
        colIndex = 1
        recordFound = False
     
        for rowIndex, x in enumerate( fnoDataRows, start=0 ):
            if ( rowIndex == endingRow - 1 ):
                xx = x.findAll( "td" )
                totalOptionPCOI = {"callTotalOI": xx[1].text, "callTotalChangeInOI": xx[2].text, "callTotalVolume": xx[3].text, "putTotalVolume": xx[5].text, "putTotalChangeInOI": xx[6].text, "putTotalOI": xx[7].text }
                # break the entire loop as we got all the information
                break;
            for colIndex, c in enumerate( x.findAll( "td" ), start=0 ):
                value = c.text.strip()
                if value == "" or value == "-":
                    value = "0"
                else:
                    value = value.replace( ",", "" )
             
                if ( colIndex == callOIChangeCol ):
                    callTotalChangeInOIValue = callTotalChangeInOIValue + int( value )
                if ( colIndex == putOIChangeCol ):
                    putTotalChangeInOIValue = putTotalChangeInOIValue + int( value )
                     
                tempMap[ headersOnIndex[colIndex]] = value
                recordFound = True
             
            if recordFound == True:
                tempMapWithStrikePriceAsKey[tempMap[headersOnIndex[optionStrikePriceColumnAt]]] = tempMap.copy()
                strikePrice = tempMap["Strike Price"]
                tempMap.clear()   

            recordFound = False
     
        return dict( { "resultFetchTime": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), "totalOptionPCOI":totalOptionPCOI, "mapWithStrikePriceAsKey":tempMapWithStrikePriceAsKey} )


if __name__ == "__main__":
 
    schedule.every( 3 ).minutes.do( doScheduler )
    while True:
        schedule.run_pending()
        time.sleep( 1 )


OUTPUT

{
'mapWithStrikePriceAsKey': {
//..... other strike prices
'10850.00': {
'call-Chart': '0',
'call-OI': '49950',
'call-Chng in OI': '26475',
'call-Volume': '10689',
'call-IV': '14.71',
'call-LTP': '210.75',
'call-Net Chng': '29.00',
'call-BidQty': '300',
'call-BidPrice': '208.85',
'call-AskPrice': '215.95',
'call-AskQty': '75',
'Strike Price': '10850.00',
'put-BidQty': '300',
'put-BidPrice': '19.50',
'put-AskPrice': '20.45',
'put-AskQty': '600',
'put-Net Chng': '-25.55',
'put-LTP': '20.45',
'put-IV': '14.92',
'put-Volume': '134223',
'put-Chng in OI': '261600',
'put-OI': '399750',
'put-Chart': '0'
},
'10900.00': {
'call-Chart': '0',
'call-OI': '574650',
'call-Chng in OI': '198600',
'call-Volume': '157457',
'call-IV': '14.15',
'call-LTP': '169.05',
'call-Net Chng': '26.85',
'call-BidQty': '4350',
'call-BidPrice': '169.05',
'call-AskPrice': '170.85',
'call-AskQty': '75',
'Strike Price': '10900.00',
'put-BidQty': '150',
'put-BidPrice': '27.45',
'put-AskPrice': '28.20',
'put-AskQty': '525',
'put-Net Chng': '-33.60',
'put-LTP': '28.20',
'put-IV': '14.22',
'put-Volume': '396350',
'put-Chng in OI': '894450',
'put-OI': '1796100',
'put-Chart': '0'
}
  //..... other strike prices
},
'totalOptionPCOI': {
'callTotalOI': ' 12,057,225',
'callTotalChangeInOI': '',
'callTotalVolume': ' 2,231,841',
'putTotalVolume': ' 1,883,484',
'putTotalChangeInOI': '',
'putTotalOI': ' 12,479,775'
}

}

Tuesday, August 27, 2019

Telegram - Broadcast or Send Message through Programming Java Python C# VB

1. Create a bot token through @botfather.
           1.1 Install Telegram
           1.2 Login to telegram
           1.3 on Search window type @botfather and select
           1.4 type one by one until you see Done !, Congratulations , your token
                     /start
                     /newbot
                    drvautobot     (username)
                   
                   Done !, ...
                   token    123456:dsfd..

2. Copy this token and keep it.
   
3. Open telegram and create new channel.
     Ex: autobot
     3.1 open autobot channel window
     3.2 click on top to see administrators , click
     3.3 search @drvautobot (bot username), select
     3.4 assign as administrator

Thats it.
Now use browser or programing with GET method.

browser
https://api.telegram.org/bot/sendMessage?chat_id=@&text=hello

ex: https://api.telegram.org/bot123456:dsfdadsfsdfdsfahgjhgsfd/sendMessage?chat_id=@autobot&text=hello

response 
{"ok":true,"result":{"message_id":2,"chat":{"id":-1001493064021,"title":"Autobot","username":"infovijay","type":"channel"},"date":1566909775,"text":"hello"}}




open your channel window and see the text hello.


Enjoy

Thursday, August 22, 2019

Install Python 3.x 3.7 in Ubuntu 18 from Bundle

Steps

1.   Donwload the tar - Python-3.7.4.tar.xz
2.  cd /home/ubuntu/
3.  tar xf Python-3.7.4.tar.xz
4   chmod 775 Python-3.7.4
5   chown -R root Python-3.7.4
6   chown -R root Python-3.7.4
7   cd Python-3.7.4/
8   ./configure
9   ./configure --enable-optimizations
10  make
11  make test
12  sudo make install
13  python3 --version
14  pip3
15  which python3


Your Sample Rest Application
1  cd /opt/stock/stockautobot
2  pip3 install -r requirements.txt
3  python3 app.py


Any package/module missed. please use below command to add
1  pip3 install requests


RUN
1 wget http://127.0.0.1:5002/
2 curl http://localhost:5002/


Monday, August 19, 2019

Friday, August 16, 2019

Tuesday, August 13, 2019

Python : websocket-client 0.56.0 error: [Errno 2] No such file or directory: script.tmpl

1. Create a file script.tmpl under C:\Users\xxx\AppData\Roaming\Python\Python37\site-packages

2. paste the below code

# EASY-INSTALL-SCRIPT: %(spec)r,%(script_name)r
__requires__ = %(spec)r
__import__('pkg_resources').run_script(%(spec)r, %(script_name)r)


3. run your setup again
py setup.py install


-- Enjoy



Thursday, August 8, 2019

AngularJS setup in Linux

1. Remove the older NPM / NODE / NG modules
    sudo apt purge ng-common ng-latin
    sudo apt purge node
    sudo apt purge npm
    sudo apt-get update

2. Install new version
     curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash - sudo 
OR
     curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash
      apt-get install -y nodejs
OR
     sudo apt-get update  
     apt-cache policy nodejs  
     sudo apt install nodejs
     sudo npm install -g @angular/cli

   npm --version
   node --version

3. Go to your folder
    npm install

4. type
    ng serve --host=ip

 OR to run in background
    nohup ng serve --host=ip &


RUN = http://ip:4200

Friday, August 2, 2019

Post Market Nifty View - 04-06-2019

#. Today FII are net buyers involves major money. and nifty totally surge to 12050k + mark.

#. Day Candle - Nifty forms strong bullish candle. But it has near to the major resistance of 12146, once it break and closed. then we have a strong upwards and next major hurdle at 12411 +.

#. wednesday is holiday and thursday monetary policy, hope repo rate will cut by 0.25% and that creates BN volatility ..

#. Short 32100 CE and planning to hedge by tomorrow evening if it close above 31800.

#. Short nifty PE heavily and hedge nifty future and short CE with less qty. I need this expiry to end below 12150 and I can get decent money.


Happy Trading..

Post Market Analysis :: NSE Nifty Report - 15-05-2019

#. Vix - 26.48 (0.16%) increased  and it will cause major impact in the market,

#. US $ - 69.57 (0.2%) decreased, Still it has to decrease and come below 69 INR, so we can expect more FII investment.

#. Day Candle -  Nifty forms bearish engulfing pattern in day candle, next support at 11470, 11440 levels on upper side 11549 needs to break to go 11570 levels.

#. SBI result on friday, so weekly expiry wont get impact with this result event.

#. Hdfcbank split options is on may 22 nd.

#. Upto election result, we will expect the volatility in the market.





- Vijay

Cors - Cross Site - Angular 2 7 8 Spring boot

1. Create a java file, add spring security jar in pom.xml
2. Angular just set what you want as custom header

SecurityConfig.java

package com.product.rpa.api.config;

import java.util.Arrays;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

/**
 * @author drvijay
 * @description main class
 * @version 1.0
 * @date 02-08-2019 1:30 PM
 */

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter
{

/* (non-Javadoc)
* @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity)
*/
@Override
protected void configure ( HttpSecurity http ) throws Exception
{
http.cors ().and ().csrf ().disable ();
}

/**
* Cors configuration source.
*
* @return the cors configuration source
*/
@Bean
CorsConfigurationSource corsConfigurationSource ()
{
CorsConfiguration configuration = new CorsConfiguration ();
configuration.setAllowedOrigins ( Arrays.asList ( "*" ) );
configuration.setAllowedMethods ( Arrays.asList ( "*" ) );
configuration.setAllowedHeaders ( Arrays.asList ( "*" ) );
configuration.setAllowCredentials ( true );
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
source.registerCorsConfiguration ( "/**", configuration );
return source;
}

}



Angular JS

DataTableComponent.ts

import { HttpHeaders } from  '@angular/common/http';

export class DataTableComponent implements OnInit {
    public tableData;

 
    public baseURL = "http://localhost:8080/";

    constructor(private _httphelperService: HttphelperService) { }

    ngOnInit() {
        this.loadData();
    }

    loadData() {
        console.log("loadData calling");

        let jsonBody = {                     
            "key": "value"
        }

        let headers = new HttpHeaders({
            "Access-Control-Allow-Origin": "*",
            "Content-Type": "application/json",
            "appToken": "abcde12345"
        })

        let response = this._httphelperService.performPOST(this.baseURL + "/api", jsonBody , headers)
            .subscribe(data => {
                this.tableData = data;
                //alert (JSON.stringify(this.tableData));
            },
            err => {
                console.log(err.message);
            }
            );
        //console.log(response);
    }
}



HttphelperService.ts

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from  '@angular/common/http';
import { CustomPromisify } from 'util';
import { Observable } from 'rxjs/Observable';
import { catchError, map } from "rxjs/operators";

@Injectable()
export class HttphelperService {
    public httpOptions: any;

    constructor(private _http: HttpClient) {
        //Http Headers Options
        this.httpOptions = {
            headers: new HttpHeaders(
                {
                    "Access-Control-Allow-Origin": "*",
                    "Content-Type": "application/json"
                })
        }
    }

    public performPOST(baseUrl: string, inputBody: any, apiHeaders: any) {
        if (apiHeaders === "" || apiHeaders === null || typeof apiHeaders === "undefined") {
            return this._http.post(baseUrl, inputBody, this.httpOptions);
        }
        else {
            console.log (apiHeaders);
            return this._http.post(baseUrl, inputBody, { headers: apiHeaders });
        }
    }


    public performGET(baseUrl: string, apiHeaders: any) {
        if (apiHeaders === "" || apiHeaders === null || typeof apiHeaders === "undefined") {
            return this._http.get(baseUrl, this.httpOptions);
        }
        else {
            return this._http.get(baseUrl, { headers: apiHeaders });
        }
    }

}



ENJOY


Hit Counter


View My Stats