|
|
@@ -1,12 +1,12 @@
|
|
|
import psycopg2.extras
|
|
|
|
|
|
|
|
|
-def get_timestamp_previous():
|
|
|
+def get_timestamp_previous(this_db):
|
|
|
"""
|
|
|
Retrieve second to last timestamp from the stocks database
|
|
|
:return timestamp:
|
|
|
"""
|
|
|
- cursor = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
+ cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
query = """SELECT DISTINCT timestamp FROM stocks ORDER BY stocks.timestamp DESC LIMIT 1 OFFSET 1;"""
|
|
|
cursor.execute(query)
|
|
|
res = cursor.fetchone()
|
|
|
@@ -15,12 +15,12 @@ def get_timestamp_previous():
|
|
|
return this_timestamp_previous
|
|
|
|
|
|
|
|
|
-def get_timestamp_latest():
|
|
|
+def get_timestamp_latest(this_db):
|
|
|
"""
|
|
|
Retrieve latest timestamp from the stocks database
|
|
|
:return timestamp:
|
|
|
"""
|
|
|
- cursor = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
+ cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
query = """SELECT DISTINCT timestamp FROM stocks ORDER BY stocks.timestamp DESC LIMIT 1;"""
|
|
|
cursor.execute(query)
|
|
|
res = cursor.fetchone()
|
|
|
@@ -53,8 +53,8 @@ def put_timestamp_stored(this_timestamp):
|
|
|
f.write("{}".format(this_timestamp))
|
|
|
|
|
|
|
|
|
-def get_data(stock_id, this_timestamp):
|
|
|
- cursor = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
+def get_data(stock_id, this_timestamp, this_db):
|
|
|
+ cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
query = """SELECT current_price, available_shares FROM stocks WHERE stock_id = %s AND timestamp = %s"""
|
|
|
cursor.execute(query, (stock_id, this_timestamp))
|
|
|
this_data = cursor.fetchone()
|