diff --git a/history/management/commands/compare_perf.py b/history/management/commands/compare_perf.py index ec300df..a97d2fa 100644 --- a/history/management/commands/compare_perf.py +++ b/history/management/commands/compare_perf.py @@ -1,6 +1,6 @@ from django.core.management.base import BaseCommand from django.conf import settings -from history.tools import get_fee_amount +from history.tools import get_fee_amount, utc_to_mst_str from history.models import Price, TradeRecommendation, PerformanceComp import datetime @@ -61,5 +61,5 @@ def handle(self, *args, **options): weighted_avg_nn_rec=weighted_avg_nn_rec, directionally_same=directionally_same, directionally_same_int=1 if directionally_same else 0, - created_on_str=tr_timerange_end.strftime('%Y-%m-%d %H:%M')) + created_on_str=utc_to_mst_str(tr_timerange_end)) pc.save() diff --git a/history/management/commands/pull_balance.py b/history/management/commands/pull_balance.py index 8aee80e..8c4d488 100644 --- a/history/management/commands/pull_balance.py +++ b/history/management/commands/pull_balance.py @@ -1,6 +1,7 @@ from django.core.management.base import BaseCommand from django.conf import settings -from history.tools import get_exchange_rate_to_btc, get_exchange_rate_btc_to_usd, get_deposit_balance +from history.tools import (get_exchange_rate_to_btc, get_exchange_rate_btc_to_usd, get_deposit_balance, + utc_to_mst_str) from history.models import Balance, Trade import datetime from django.db import transaction @@ -40,13 +41,10 @@ def handle(self, *args, **options): b.save() for b in Balance.objects.filter(date_str='0'): - # django timezone stuff , FML - b.date_str = datetime.datetime.strftime(b.created_on - datetime.timedelta(hours=int(7)), '%Y-%m-%d %H:%M') + b.date_str = utc_to_mst_str(b.created_on) b.save() # normalize trade recommendations too. merp for tr in Trade.objects.filter(created_on_str=''): - # django timezone stuff , FML - tr.created_on_str = datetime.datetime.strftime( - tr.created_on - datetime.timedelta(hours=int(7)), '%Y-%m-%d %H:%M') + tr.created_on_str = utc_to_mst_str(tr.created_on) tr.save() diff --git a/history/management/commands/pull_deposits.py b/history/management/commands/pull_deposits.py index 3e82e4c..e123fba 100644 --- a/history/management/commands/pull_deposits.py +++ b/history/management/commands/pull_deposits.py @@ -1,7 +1,7 @@ from django.core.management.base import BaseCommand from django.conf import settings import datetime -from history.tools import get_utc_unixtime +from history.tools import get_utc_unixtime, utc_to_mst_str from history.models import Deposit @@ -35,6 +35,5 @@ def handle(self, *args, **options): d.status = status d.created_on = created_on d.modified_on = created_on - d.created_on_str = datetime.datetime.strftime( - created_on - datetime.timedelta(hours=int(7)), '%Y-%m-%d %H:%M') + d.created_on_str = utc_to_mst_str(created_on) d.save() diff --git a/history/management/commands/pull_prices.py b/history/management/commands/pull_prices.py index 7c5fa8c..fb4b8db 100644 --- a/history/management/commands/pull_prices.py +++ b/history/management/commands/pull_prices.py @@ -1,3 +1,4 @@ +from history.tools import utc_to_mst_str from django.core.management.base import BaseCommand from django.conf import settings @@ -25,5 +26,5 @@ def handle(self, *args, **options): p.lowestask = price[ticker]['lowestAsk'] p.highestbid = price[ticker]['highestBid'] p.symbol = ticker - p.created_on_str = str(p.created_on) + p.created_on_str = utc_to_mst_str(p.created_on) p.save() diff --git a/history/management/commands/trade.py b/history/management/commands/trade.py index 1bbf8ed..a769c47 100644 --- a/history/management/commands/trade.py +++ b/history/management/commands/trade.py @@ -1,6 +1,6 @@ from django.core.management.base import BaseCommand from history.models import Price, PredictionTest, Trade, TradeRecommendation, Balance, ClassifierTest -from history.tools import get_utc_unixtime, print_and_log +from history.tools import get_utc_unixtime, print_and_log, utc_to_mst_str import datetime import time from history.poloniex import poloniex @@ -192,7 +192,7 @@ def run_predictor(self, nn_index): confidence=confidence, recommendation=recommend, net_amount=-1 if recommend == 'SELL' else (1 if recommend == 'BUY' else 0), - created_on_str=timezone.now().strftime('%Y-%m-%d %H:%M')) + created_on_str=utc_to_mst_str(timezone.now())) tr.save() self.trs[nn_index] = tr return recommend diff --git a/history/tools.py b/history/tools.py index ef7815b..4ce5a70 100644 --- a/history/tools.py +++ b/history/tools.py @@ -1,6 +1,8 @@ import time +import pytz import datetime from django.conf import settings +from django.utils import timezone from django.core.exceptions import ImproperlyConfigured @@ -11,14 +13,17 @@ def print_and_log(log_string): def get_utc_unixtime(): - import time - import datetime - d = datetime.datetime.now() unixtime = time.mktime(d.timetuple()) return int(unixtime) +def utc_to_mst_str(dt): + mst = pytz.timezone('MST') + local = timezone.localtime(dt, mst) + return datetime.datetime.strftime(local, '%Y-%m-%d %H:%M') + + def create_sample_row(data, i, size): sample = () for k in range(0, size):