add disabled and fulfilled
This commit is contained in:
parent
2c96653753
commit
3eab796967
2
app.py
2
app.py
|
|
@ -13,7 +13,7 @@ def handle_tickerdata(data: TickerData, condition: Condition):
|
|||
result = Condition.greater_than(condition.value, data.lastPrice)
|
||||
|
||||
if result:
|
||||
DbConnector.disable_condition(condition.id)
|
||||
DbConnector.fulfill_condition(condition.id)
|
||||
|
||||
print(data.symbol + ": " + data.lastPrice)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class Condition:
|
|||
condition: str
|
||||
value: float
|
||||
disabled: bool
|
||||
fulfilled: bool
|
||||
|
||||
@staticmethod
|
||||
def lower_than(value: float, lastPrice: float):
|
||||
|
|
|
|||
|
|
@ -41,13 +41,13 @@ class DbConnector:
|
|||
conditions = fetch_conditions()
|
||||
|
||||
for cond in conditions:
|
||||
if not cond.disabled:
|
||||
if not cond.disabled and not cond.fulfilled:
|
||||
callback(cond)
|
||||
|
||||
feed = r.table(TABLE_NAME).changes().run(get_connection())
|
||||
for change in feed:
|
||||
cond = Condition(**change['new_val'])
|
||||
if not cond.disabled:
|
||||
if not cond.disabled and not cond.fulfilled:
|
||||
callback(cond)
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -57,3 +57,11 @@ class DbConnector:
|
|||
json.disabled = True
|
||||
r.table(TABLE_NAME).get(condition_id).update(json).run(get_connection())
|
||||
|
||||
@staticmethod
|
||||
def fulfill_condition(condition_id: str):
|
||||
cursor = r.table(TABLE_NAME).get(condition_id).run(get_connection())
|
||||
json = jsonify(cursor)
|
||||
json.disabled = True
|
||||
json.fulfilled = True
|
||||
r.table(TABLE_NAME).get(condition_id).update(json).run(get_connection())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue