-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
abtexp
committed
Jul 11, 2021
0 parents
commit 7169bdd
Showing
12 changed files
with
83,305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__pycache__ | ||
config.cfg | ||
rules.jpg |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .utils import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import streamlit as st | ||
|
||
import time | ||
import random | ||
import numpy as np | ||
import pandas as pd | ||
import plotly.express as px | ||
|
||
st.title('Trader Dashboard') | ||
|
||
st.write('Here Goes The Table Of Scores : ') | ||
|
||
chart_data = pd.DataFrame( | ||
np.random.randn(20, 3), | ||
columns=['a', 'b', 'c']) | ||
|
||
st.line_chart(chart_data) | ||
|
||
|
||
dynamic_area = st.empty() | ||
|
||
def update_dashboard(values): | ||
df = pd.DataFrame(dict( | ||
r=[random.randint(0,22), | ||
random.randint(0,22), | ||
random.randint(0,22), | ||
random.randint(0,22), | ||
random.randint(0,22)], | ||
theta=['processing cost','mechanical properties','chemical stability', | ||
'thermal stability', 'device integration'])) | ||
fig = px.line_polar(df, r='r', theta='theta', line_close=True) | ||
dynamic_area.write(fig) | ||
|
||
while True: | ||
update_dashboard(10) | ||
time.sleep(0.5) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Imports | ||
import sys | ||
import json | ||
import requests | ||
import datetime | ||
import configparser | ||
from utils import * | ||
from selenium import webdriver | ||
from streamlit import cli as stcli | ||
from selenium.webdriver.chrome.options import Options | ||
from kiteconnect import KiteConnect, KiteTicker | ||
from webdriver_manager.chrome import ChromeDriverManager | ||
|
||
|
||
# GET INFO ABOUT : VWAP, RSI(MA), VOLUME(MA), OPENINTEREST(MA) | ||
|
||
class TRADER: | ||
def __init__(self): | ||
config = configparser.RawConfigParser() | ||
config.read('config.cfg') | ||
self.creds = dict(config.items('creds')) | ||
self.instruments = dict(config.items('instruments')) | ||
self.endpoints = dict(config.items('api_endpoints')) | ||
self.app_vars = dict(config.items('app_vars')) | ||
self.app = KiteConnect(self.creds['api_key']) | ||
self.login_url = self.app.login_url() | ||
self.goto_browser() | ||
self.access_token = self.app.generate_session(self.request_token, api_secret=self.creds['secret_key'])['access_token'] | ||
self.app.set_access_token(self.access_token) | ||
self.ticker = TICKER(self.instruments, self.creds['api_key'], self.access_token) | ||
self.ticker.connect_indices() | ||
|
||
def launch_app(self, driver): | ||
sys.argv = ["streamlit", "run", self.app_vars['app_file'], '--server.port', self.app_vars['port']] | ||
stcli.main() | ||
driver.get(self.endpoints['app_endpoint']+self.app_vars['port']) | ||
|
||
def goto_browser(self): | ||
try: | ||
chrome_options = Options() | ||
chrome_options.add_experimental_option("detach", True) | ||
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options) | ||
driver.get(self.login_url) | ||
url = '' | ||
while 'request_token' not in url: | ||
url = driver.current_url | ||
self.launch_app(driver) | ||
# driver.quit() | ||
self.request_token = url[url.index('request_token')+len('request_token')+1:url.index('&action')] | ||
except Exception as e: | ||
print('Exception Occured. : {}'.format(e)) | ||
|
||
|
||
if __name__ == '__main__': | ||
trader = TRADER() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
[{ | ||
"tradable": true, | ||
"mode": "quote", | ||
"instrument_token": 5633, | ||
"last_price": 2047.15, | ||
"last_quantity": 1, | ||
"average_price": 2043.13, | ||
"volume": 263725, | ||
"buy_quantity": 98049, | ||
"sell_quantity": 98782, | ||
"ohlc": { | ||
"open": 2050.0, | ||
"high": 2062.6, | ||
"low": 2026.3, | ||
"close": 2045.95 | ||
}, | ||
"change": 0.05865245973753246 | ||
}, | ||
{ | ||
"tradable": true, | ||
"mode": "full", | ||
"instrument_token": 738561, | ||
"last_price": 2218.3, | ||
"last_quantity": 5, | ||
"average_price": 2213.05, | ||
"volume": 3706007, | ||
"buy_quantity": 444677, | ||
"sell_quantity": 627748, | ||
"ohlc": { | ||
"open": 2226.6, | ||
"high": 2227.15, | ||
"low": 2198.15, | ||
"close": 2227.4 | ||
}, | ||
"change": -0.40854808296668355, | ||
"last_trade_time": [2021, 6, 8, 14, 53, 55], | ||
"oi": 0, | ||
"oi_day_high": 0, | ||
"oi_day_low": 0, | ||
"timestamp": [2021, 6, 8, 14, 53, 56], | ||
"depth": { | ||
"buy": [{ | ||
"quantity": 723, | ||
"price": 2218.25, | ||
"orders": 9 | ||
}, | ||
{ | ||
"quantity": 108, | ||
"price": 2218.2, | ||
"orders": 5 | ||
}, | ||
{ | ||
"quantity": 4, | ||
"price": 2218.1, | ||
"orders": 1 | ||
}, | ||
{ | ||
"quantity": 211, | ||
"price": 2218.05, | ||
"orders": 4 | ||
}, | ||
{ | ||
"quantity": 516, | ||
"price": 2218.0, | ||
"orders": 16 | ||
} | ||
], | ||
"sell": [{ | ||
"quantity": 28, | ||
"price": 2218.3, | ||
"orders": 3 | ||
}, | ||
{ | ||
"quantity": 22, | ||
"price": 2218.35, | ||
"orders": 1 | ||
}, | ||
{ | ||
"quantity": 2, | ||
"price": 2218.4, | ||
"orders": 1 | ||
}, | ||
{ | ||
"quantity": 513, | ||
"price": 2218.5, | ||
"orders": 8 | ||
}, | ||
{ | ||
"quantity": 64, | ||
"price": 2218.7, | ||
"orders": 3 | ||
} | ||
] | ||
} | ||
} | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .functions import * | ||
from .ticker import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import numpy as np | ||
import math | ||
|
||
|
||
''' | ||
FORMULA TO CALCULATE RSI(MA) | ||
RSI = 100 – 100 / ( 1 + RS ) | ||
RS = Relative Strength = AvgU / AvgD | ||
AvgU = average of all up moves in the last N price bars | ||
AvgD = average of all down moves in the last N price bars | ||
N = the period of RSI | ||
''' | ||
def rsi(entries): | ||
last_value = entries[0]['ohlc']['close'] | ||
|
||
up_points, down_points = [], [] | ||
for entry in entries[1:]: | ||
dirn_magn = entry['ohlc']['close'] - last_value | ||
last_value = entry['ohlc']['close'] | ||
if dirn_magn > 0: | ||
up_points.append(dirn_magn) | ||
else: | ||
down_points.append(-1*dirn_magn) | ||
|
||
avg_up = sum(up_points)/(len(up_points)+1) | ||
avg_down = sum(down_points)/(len(down_points)+1) | ||
rs = avg_up/(1e-3 + avg_down) | ||
rsi = 100 - (100/(1+rs)) | ||
return rsi | ||
|
||
|
||
def volume_ma(entries): | ||
return sum([i['volume'] for i in entries])/(1+len(entries)) | ||
|
||
|
||
def open_interest_ma(): | ||
|
||
return | ||
|
||
|
||
def vwap_ma(entries): | ||
num = 0 | ||
den = 0 | ||
for entry in entries: | ||
opn, hgh, lw, clse = entry['ohlc'].values() | ||
price = (hgh+lw+clse)/3 | ||
volume = entry['volume'] | ||
num += (volume*price) | ||
den += volume | ||
|
||
return num/(den+1e3) | ||
|
||
|
||
def calc_vals(entries): | ||
volume = volume_ma(entries[1:]) | ||
vwap = vwap_ma(entries[1:]) | ||
rsi = rsi_ma(entries) | ||
oi = open_interest_ma(entries) | ||
return volume, rsi, vwap, oi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from utils.functions import * | ||
from kiteconnect import KiteTicker | ||
|
||
|
||
class INSTRUMENT: | ||
def __init__(self, instrument, api_key, access_token): | ||
self.strike = instrument[0] | ||
self.instrument_token = instrument[1] | ||
self.ticker = KiteTicker(api_key, access_token) | ||
self.entries = [] | ||
self.period = 14 | ||
self.rsi = None | ||
self.vw = None | ||
self.vol = None | ||
self.oi = None | ||
self.set_callbacks() | ||
self.ticker.connect() | ||
|
||
def connect_callback(self): | ||
def on_connect(ws, response): | ||
ws.subscribe([self.instrument_token]) | ||
ws.set_mode(ws.MODE_FULL, [self.instrument_token]) | ||
|
||
return on_connect | ||
|
||
def update_entries(self): | ||
if len(self.entries) >= self.period: | ||
self.entries = self.entries[1:] | ||
|
||
def tick_callback(self): | ||
def on_tick(ws, ticks): | ||
self.entries.append(ticks) | ||
self.calc_indicators() | ||
self.update_entries() | ||
|
||
return on_tick | ||
|
||
def calc_indicators(self): | ||
if len(self.entries) >= self.period: | ||
# Perform Calculations | ||
self.vol, self.rsi, self.vw, self.oi = calc_vals(self.entries) | ||
|
||
def close_callback(self): | ||
def on_close(ws, code, reason): | ||
ws.close() | ||
# Perform Some Other Stuff | ||
|
||
def set_callbacks(self): | ||
self.ticker.on_connect = self.connect_callback() | ||
self.ticker.on_ticks = self.tick_callback() | ||
self.ticker.on_close = self.close_callback() |
Oops, something went wrong.