-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_historical_ratios_quick.py
More file actions
57 lines (39 loc) · 1.67 KB
/
task_historical_ratios_quick.py
File metadata and controls
57 lines (39 loc) · 1.67 KB
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
import traceback
import time
import app
import model
from datetime import datetime, timedelta
from sqlalchemy.orm import Session
engine = model.get_engine()
def task_historical_ratios_quick():
engine.dispose()
time.sleep(30)
while app.running:
current_time = datetime.utcnow()
future_time = current_time + timedelta(seconds=10)
seconds = future_time.timetuple().tm_sec
future_time = future_time.replace(second=int(seconds / 10) * 10).replace(microsecond=0)
difference = future_time - current_time
time.sleep(difference.total_seconds())
try:
with Session(engine) as session, session.begin():
current_ratios = session.query(model.CurrentOperationsToOpen).all()
for current_ratio in current_ratios:
ratio = model.HistoricalRatiosQuick()
session.add(ratio)
ratio.time = future_time
ratio.future_symbol = current_ratio.future_symbol
ratio.spot_symbol = current_ratio.spot_symbol
ratio.hours = current_ratio.hours
ratio.days = current_ratio.days
ratio.future_price = current_ratio.future_price
ratio.spot_price = current_ratio.spot_price
ratio.direct_ratio = current_ratio.direct_ratio
ratio.hour_ratio = current_ratio.hour_ratio
ratio.year_ratio = current_ratio.year_ratio
except Exception as ex:
print(ex)
traceback.print_stack()
if __name__ == '__main__':
model.create_tables()
task_historical_ratios_quick()