-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbackfiller.py
executable file
·52 lines (39 loc) · 1.75 KB
/
backfiller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def backfill_now(port=7496, clientId=23, tickers=['TATAMOTOR'], duration="20 D", bar_size="5 mins"):
from broker_to_csv import TradingApp, multi_historical_retriver
import pandas as pd
import threading
import time
########## Starting App as Thread #############
def websocket_con():
app.run()
event = threading.Event()
app = TradingApp()
app.event=event
app.connect(host='127.0.0.1', port=port, clientId=clientId) #port 4002 for ib gateway paper trading/7497 for TWS paper trading
con_thread = threading.Thread(target=websocket_con, daemon=True)
con_thread.start()
time.sleep(1) # some latency added to ensure that the connection is established
##################################################
########## From Datetime #############
import datetime
today_date=(datetime.datetime.today().strftime("%Y%m%d %H:%M:%S"))
########################################
tickers=tickers
duration=duration
bar_size=bar_size
########## Historical Data ############
multi_historical_retriver(ticker_list=tickers,
app_obj=app,
from_date=today_date,
duration=duration,
bar_size=bar_size,
event=event
)
########################################
# Old Csv to sql
from csv_to_sql import sql_ingester
import sqlalchemy
data_dir="./Data"
sql_obj = sqlalchemy.create_engine('postgresql://krh:krh@123@localhost:5432/krh')
df=sql_ingester(data_dir, sql_obj, False)
####################################################################################################################