-
Notifications
You must be signed in to change notification settings - Fork 3
/
eval_positions_1.py
42 lines (36 loc) · 980 Bytes
/
eval_positions_1.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
import simplejson as json
from celery import Celery
from celery.utils.log import get_task_logger
import redis
celery=Celery('positions',broker='redis://',backend='redis://')
logger = get_task_logger(__name__)
@celery.task
def get_initial_position_value(name):
db=redis.Redis()
pos=json.loads(db.get(name))
if pos is None:
return
else:
return pos['size']*pos['price']
@celery.task
def get_value_at_close(name,close):
if close is None or close<0:
return None
db=redis.Redis()
pos_str=db.get(name)
if pos_str is None:
return None
else:
pos=json.loads(pos_str)
return pos['size']*close
@celery.task
def get_value_at_close_retry(name,close):
if close is None or close<0:
return None
db=redis.Redis()
pos_str=db.get(name)
if pos_str is None:
raise get_value_at_close_retry.retry()
else:
pos=json.loads(pos_str)
return pos['size']*close