|
@@ -4,6 +4,7 @@ import psycopg2.extras
|
|
|
def get_timestamp_previous(this_db):
|
|
def get_timestamp_previous(this_db):
|
|
|
"""
|
|
"""
|
|
|
Retrieve second to last timestamp from the stocks database
|
|
Retrieve second to last timestamp from the stocks database
|
|
|
|
|
+ :param this_db:
|
|
|
:return timestamp:
|
|
:return timestamp:
|
|
|
"""
|
|
"""
|
|
|
cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
@@ -18,6 +19,7 @@ def get_timestamp_previous(this_db):
|
|
|
def get_timestamp_latest(this_db):
|
|
def get_timestamp_latest(this_db):
|
|
|
"""
|
|
"""
|
|
|
Retrieve latest timestamp from the stocks database
|
|
Retrieve latest timestamp from the stocks database
|
|
|
|
|
+ :param this_db:
|
|
|
:return timestamp:
|
|
:return timestamp:
|
|
|
"""
|
|
"""
|
|
|
cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
@@ -54,6 +56,13 @@ def put_timestamp_stored(this_timestamp):
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_data(stock_id, this_timestamp, this_db):
|
|
def get_data(stock_id, this_timestamp, this_db):
|
|
|
|
|
+ """
|
|
|
|
|
+ Retrieves detailed data from the existing stocks database
|
|
|
|
|
+ :param stock_id:
|
|
|
|
|
+ :param this_timestamp:
|
|
|
|
|
+ :param this_db:
|
|
|
|
|
+ :return:
|
|
|
|
|
+ """
|
|
|
cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
cursor = this_db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
query = """SELECT current_price, available_shares FROM stocks WHERE stock_id = %s AND timestamp = %s"""
|
|
query = """SELECT current_price, available_shares FROM stocks WHERE stock_id = %s AND timestamp = %s"""
|
|
|
cursor.execute(query, (stock_id, this_timestamp))
|
|
cursor.execute(query, (stock_id, this_timestamp))
|
|
@@ -62,17 +71,18 @@ def get_data(stock_id, this_timestamp, this_db):
|
|
|
return this_data
|
|
return this_data
|
|
|
|
|
|
|
|
|
|
|
|
|
-def process_data(this_data_previous, this_data_latest, this_threshold):
|
|
|
|
|
|
|
+def process_data(this_data_previous, this_data_latest, this_price, this_threshold):
|
|
|
"""
|
|
"""
|
|
|
Calculate if there is enough change to call it a drop
|
|
Calculate if there is enough change to call it a drop
|
|
|
:param this_data_previous:
|
|
:param this_data_previous:
|
|
|
:param this_data_latest:
|
|
:param this_data_latest:
|
|
|
- :param this_threshold
|
|
|
|
|
|
|
+ :param this_price:
|
|
|
|
|
+ :param this_threshold:
|
|
|
:return boolean:
|
|
:return boolean:
|
|
|
"""
|
|
"""
|
|
|
this_drop = False
|
|
this_drop = False
|
|
|
quantity_previous = this_data_previous.available_shares * float(this_data_latest.current_price)
|
|
quantity_previous = this_data_previous.available_shares * float(this_data_latest.current_price)
|
|
|
quantity_latest = this_data_latest.available_shares * float(this_data_latest.current_price)
|
|
quantity_latest = this_data_latest.available_shares * float(this_data_latest.current_price)
|
|
|
- if quantity_latest - quantity_previous > this_threshold * 1e9:
|
|
|
|
|
|
|
+ if this_data_latest.current_price > this_price or quantity_latest - quantity_previous > this_threshold * 1e9:
|
|
|
this_drop = True
|
|
this_drop = True
|
|
|
return this_drop
|
|
return this_drop
|