Commit 5d31a0df by rongjun

init

parent c11e6569
# coding=utf8
import traceback
from datetime import datetime
from decimal import Decimal
from django.db import IntegrityError
from django.http.response import HttpResponse
from apps.task.models import Task
from apps.task.models import Task, TaskNotify
from core.utils.email import send
from django_q.tasks import async_task
from core.utils import log as logger
def cta(timestamp, last_price, task):
......@@ -12,19 +15,22 @@ def cta(timestamp, last_price, task):
_type = task.get('type')
max_val = Decimal(task.get('max_val'))
min_val = Decimal(task.get('min_val'))
style = ''
style = None
point = ''
point_val = None
over = False
if _type == 'A':
if max_val == min_val:
if last_price > min_val:
style = '突破'
point = '预值'
point_val = min_val
over = True
else:
if last_price < min_val:
style = '回调'
point = '突破原点'
point_val = min_val
over = True
m = max_val - min_val
p1 = min_val + m * Decimal('0.333')
......@@ -32,20 +38,24 @@ def cta(timestamp, last_price, task):
if last_price >= p1:
style = '突破'
point = '0.333'
point_val = p1
if last_price >= p2:
style = '突破'
point = '0.382'
point_val = p2
over = True
if _type == 'D':
if max_val == min_val:
if last_price < min_val:
style = '突破'
point = '预值'
point_val = min_val
over = True
else:
if last_price > max_val:
style = '回调'
point = '突破原点'
point_val = max_val
over = True
m = max_val - min_val
p1 = max_val - m * Decimal('0.333')
......@@ -53,9 +63,11 @@ def cta(timestamp, last_price, task):
if last_price <= p1:
style = '突破'
point = '0.333'
point_val = p1
if last_price <= p2:
style = '突破'
point = '0.382'
point_val = p2
over = True
_title = '【{}{}】的提醒'
_content = '【{}】,镜像空间【{}-{}】,预期趋势【{}】;在【{}】【{}】点位为【{}】'
......@@ -63,9 +75,17 @@ def cta(timestamp, last_price, task):
title = _title.format(style, point)
content = _content.format(task.get('name'), task.get('max_val'), task.get('min_val'), task.get('type'), times,
style, last_price)
if style:
try:
TaskNotify.objects.create(task_id=task.get('id'), point=point_val)
if over:
Task.remove_task(task)
send(title, content, task.get('emails'))
except IntegrityError:
pass
except Exception as e:
trace = traceback.format_exc()
logger.error(trace)
def push(request):
......
......@@ -47,3 +47,12 @@ class Task(BaseModel):
def remove_task(task):
Task.objects.filter(pk=int(task.get('id'))).update(active=False)
Task.set_active_list(task.get('instrument'))
class TaskNotify(BaseModel):
task_id = models.IntegerField()
point = models.CharField(max_length=200)
class Meta:
ordering = ['-id']
unique_together = ('task_id', 'point')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment