Commit 5d31a0df by rongjun

init

parent c11e6569
# coding=utf8 # coding=utf8
import traceback
from datetime import datetime from datetime import datetime
from decimal import Decimal from decimal import Decimal
from django.db import IntegrityError
from django.http.response import HttpResponse 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 core.utils.email import send
from django_q.tasks import async_task from django_q.tasks import async_task
from core.utils import log as logger
def cta(timestamp, last_price, task): def cta(timestamp, last_price, task):
...@@ -12,19 +15,22 @@ def cta(timestamp, last_price, task): ...@@ -12,19 +15,22 @@ def cta(timestamp, last_price, task):
_type = task.get('type') _type = task.get('type')
max_val = Decimal(task.get('max_val')) max_val = Decimal(task.get('max_val'))
min_val = Decimal(task.get('min_val')) min_val = Decimal(task.get('min_val'))
style = '' style = None
point = '' point = ''
point_val = None
over = False over = False
if _type == 'A': if _type == 'A':
if max_val == min_val: if max_val == min_val:
if last_price > min_val: if last_price > min_val:
style = '突破' style = '突破'
point = '预值' point = '预值'
point_val = min_val
over = True over = True
else: else:
if last_price < min_val: if last_price < min_val:
style = '回调' style = '回调'
point = '突破原点' point = '突破原点'
point_val = min_val
over = True over = True
m = max_val - min_val m = max_val - min_val
p1 = min_val + m * Decimal('0.333') p1 = min_val + m * Decimal('0.333')
...@@ -32,20 +38,24 @@ def cta(timestamp, last_price, task): ...@@ -32,20 +38,24 @@ def cta(timestamp, last_price, task):
if last_price >= p1: if last_price >= p1:
style = '突破' style = '突破'
point = '0.333' point = '0.333'
point_val = p1
if last_price >= p2: if last_price >= p2:
style = '突破' style = '突破'
point = '0.382' point = '0.382'
point_val = p2
over = True over = True
if _type == 'D': if _type == 'D':
if max_val == min_val: if max_val == min_val:
if last_price < min_val: if last_price < min_val:
style = '突破' style = '突破'
point = '预值' point = '预值'
point_val = min_val
over = True over = True
else: else:
if last_price > max_val: if last_price > max_val:
style = '回调' style = '回调'
point = '突破原点' point = '突破原点'
point_val = max_val
over = True over = True
m = max_val - min_val m = max_val - min_val
p1 = max_val - m * Decimal('0.333') p1 = max_val - m * Decimal('0.333')
...@@ -53,9 +63,11 @@ def cta(timestamp, last_price, task): ...@@ -53,9 +63,11 @@ def cta(timestamp, last_price, task):
if last_price <= p1: if last_price <= p1:
style = '突破' style = '突破'
point = '0.333' point = '0.333'
point_val = p1
if last_price <= p2: if last_price <= p2:
style = '突破' style = '突破'
point = '0.382' point = '0.382'
point_val = p2
over = True over = True
_title = '【{}{}】的提醒' _title = '【{}{}】的提醒'
_content = '【{}】,镜像空间【{}-{}】,预期趋势【{}】;在【{}】【{}】点位为【{}】' _content = '【{}】,镜像空间【{}-{}】,预期趋势【{}】;在【{}】【{}】点位为【{}】'
...@@ -63,9 +75,17 @@ def cta(timestamp, last_price, task): ...@@ -63,9 +75,17 @@ def cta(timestamp, last_price, task):
title = _title.format(style, point) title = _title.format(style, point)
content = _content.format(task.get('name'), task.get('max_val'), task.get('min_val'), task.get('type'), times, content = _content.format(task.get('name'), task.get('max_val'), task.get('min_val'), task.get('type'), times,
style, last_price) style, last_price)
if over: if style:
Task.remove_task(task) try:
send(title, content, task.get('emails')) 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): def push(request):
......
...@@ -47,3 +47,12 @@ class Task(BaseModel): ...@@ -47,3 +47,12 @@ class Task(BaseModel):
def remove_task(task): def remove_task(task):
Task.objects.filter(pk=int(task.get('id'))).update(active=False) Task.objects.filter(pk=int(task.get('id'))).update(active=False)
Task.set_active_list(task.get('instrument')) 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