Skip to content

Commit

Permalink
Make created_on_str always MST
Browse files Browse the repository at this point in the history
  • Loading branch information
rubik committed Apr 14, 2016
1 parent 2e18d3c commit ce4e8dc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions history/management/commands/compare_perf.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
10 changes: 4 additions & 6 deletions history/management/commands/pull_balance.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
5 changes: 2 additions & 3 deletions history/management/commands/pull_deposits.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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()
3 changes: 2 additions & 1 deletion history/management/commands/pull_prices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from history.tools import utc_to_mst_str
from django.core.management.base import BaseCommand
from django.conf import settings

Expand Down Expand Up @@ -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()
4 changes: 2 additions & 2 deletions history/management/commands/trade.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions history/tools.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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):
Expand Down

0 comments on commit ce4e8dc

Please sign in to comment.