Created
January 28, 2021 15:41
-
-
Save Vasiliy566/de95ec236d33baff4435063fcdd25545 to your computer and use it in GitHub Desktop.
learnToTrade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .models import ChartRequest | |
from django.forms import ModelForm, TextInput | |
class ChartRequestForm(ModelForm): | |
class Meta: | |
model = ChartRequest | |
fields = ["begin_day", "end_day", "json"] | |
widgets = { | |
"begin_day": TextInput(attrs={ | |
'class': "form-control", | |
"type": "date", | |
'placeholder': 'первый день' | |
}), | |
"end_day": TextInput(attrs={ | |
'class': "form-control", | |
"type": "date", | |
'placeholder': 'последний день' | |
}), | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.contrib.postgres.fields import JSONField | |
class ChartRequest(models.Model): | |
JSON = '{}' | |
begin_day = models.TextField('первый день') | |
end_day = models.TextField('последний день') | |
json = JSONField(default={2: "b"}) | |
def __str__(self): | |
return self.begin_day, self.end_day, self. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django.shortcuts import render, redirect | |
from server.src.predict_strategy import PredictStrategy | |
from server.src.common.time_interval import TimeInterval, BaseTimeInterval | |
from server.src.functional import get_historical_klines | |
from binance.client import Client | |
from .forms import ChartRequestForm | |
import sys | |
from server.src.common.calendar_date import Date | |
root = logging.getLogger() | |
root.setLevel(logging.DEBUG) | |
handler = logging.StreamHandler(sys.stdout) | |
handler.setLevel(logging.DEBUG) | |
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
handler.setFormatter(formatter) | |
root.addHandler(handler) | |
logger = logging.getLogger('predict_strategy') | |
sys.path.insert(1, "/home/apulazo/PycharmProjects/learnToTrade/server") | |
def index(request): | |
if request.method == "POST": | |
post = request.POST.copy() | |
post.update({'json': {1 : "A"}}) | |
form = ChartRequestForm(post) | |
print(request.POST) | |
print(post) | |
begin_day = Date(request.POST["begin_day"]).to_binance_format() | |
end_day = Date(request.POST["end_day"]).to_binance_format() | |
if form.is_valid(): | |
form.save() | |
logger.info("vievs started") | |
# data = {'d': "{ time: 2018-10-19, open: 180.34, high: 180.99, low: 178.57, close: 179.85 },{ time: 2018-10-22, open: 180.82, high: 181.40, low: 177.56, close: 178.75 },{ time: 2018-10-23, open: 175.77, high: 179.49, low: 175.44, close: 178.53 }"} | |
# target = get_historical_klines("BTCUSDT", Client.KLINE_INTERVAL_1MINUTE, "1 day ago UTC") | |
target = get_historical_klines("BTCUSDT", Client.KLINE_INTERVAL_1MINUTE, begin_day, end_day) | |
start = PredictStrategy() | |
data_ = [] | |
logger.info("calculating predict inited") | |
res = start.process(TimeInterval([BaseTimeInterval(x) for x in target])) | |
for item in res.get_data(): | |
print(item) | |
tmp = [] | |
tmp.append(int(item["start"]) * 1000) | |
tmp.append(int(item["end"]) * 1000) | |
data_.append(tmp) | |
logger.info("calculations parsed") | |
#data = {'start': 1596382920470, 'end': 1596392920470} | |
print("--------------") | |
s = "" | |
for i in range(3): | |
s += "start" + str(i+1) + "1-" + str(data_[i][0]) + "_" | |
s += "end" + str(i+1) + "2-" + str(data_[i][1]) + "_" | |
s += str(request.POST["begin_day"]) + "_" | |
s += str(request.POST["end_day"]) | |
# print(s[:-1]) | |
print(data_) | |
data = {'start11': int(data_[0][0]), 'end12': int(data_[0][1]), | |
'start21': int(data_[1][0]), 'end22': int(data_[1][1]), | |
'start31': int(data_[2][0]), 'end32': int(data_[2][1])} | |
# data = {'start': 1595631313149} | |
logger.info("calculations finished") | |
return redirect("/similar_charts/"+s) | |
# return render(request, 'mysite/samecharts.html', context=data) | |
# return render(request, 'mysite/main_next.html', context = data) | |
form = ChartRequestForm() | |
context = { | |
'form': form | |
} | |
# return render(request, 'mysite/staticchart.html', context) | |
# return render(request, 'mysite/wrapper2.html', context) | |
return render(request, 'mysite/main2.html', context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment