-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounts_database.py
87 lines (85 loc) · 2.45 KB
/
accounts_database.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from time import sleep
import time
sleep(5)
from common import message as m
from fyers.insert_database import database_ticks
import pandas as pd
import pickle
import pandas as pd
emergency_start=False
import pdb
import datetime
a=True
while a==True:
try:
intimate = open('intimate.txt', 'r')
u=intimate.read().split('\n')[0]
a=u
if a==False:
break
print('Logged in ')
intimate.close()
except:
print('Waiting for other python file to login ...')
sleep(5)
wait=False
while not wait:
wait=((0 <= time.localtime().tm_wday <= 4) and (datetime.datetime.strptime(
datetime.datetime.strftime(datetime.datetime.now(), "%d-%m-%Y") + " 09:14:58",
"%d-%m-%Y %H:%M:%S") <= datetime.datetime.now()))
if wait:
break
print('waiting market to open ')
if emergency_start:
break
#print('waiting')
sleep(1)
wait=True
try:
h=pd.read_csv(('fyers/cred.csv'))
except :
h = pd.read_csv(('cred.csv'))
accounts=[]
import time
import os
import pandas as pd
import sqlite3
from datetime import datetime
import sys
if os.getcwd()[0] == 'C':
db = sqlite3.connect('ticks.db')
else:
db = sqlite3.connect('ticks.db')
for i in h:
with open(f'{i}', 'rb') as disk:
accounts.append(pickle.load(disk))
name1=[]
for i in h:
name1.append(i)
def accounts_database(name,accounts=accounts):
sql = database_ticks(name,accounts[0])
sql.database()
'''try:
read=open('stock_selection.txt','r')
except:
read=open('fyers/stock_selection.txt','r')
stock_name=read.read().split('\n')
read.close()
stock_name=stock_name[0]'''
stock_name='NSE:NIFTY50-INDEX'
#from fyers.broker_allow_stocks import allow
#allowed_stocks=allow(stock_name)
#stock_name=allowed_stocks[0]
count=0
while count<60:
try:
count+=1
m.message("Ticks will save to database from now ")
try:
accounts_database([stock_name])
except Exception as error:
m.message(f"There may be an error in inserting to database ,{error}")
sleep(10)
except Exception as error :
m.message(f"Final Call , it wont't try again , stopped inserting to database there may be an error in inserting to database , Ticks entering to database is stopped . Trades from will not work correctly , Algo trading won't work correctly , Please check code or contact srikar to solve issue , {error}")
sleep(10)