# Path: crumpet/profiles/forms.py
# class UserAccountForm(forms.Form):
# 
# Path: crumpet/profiles/models.py
# class UserAccount(models.Model):
#     class Meta:
#     def __str__(self):
# 
# Path: crumpet/profiles/constants.py
# CRYPTO_EXCHANGES = (
#     ("poloniex", _("Poloniex")),
#     ("bittrex", _("Bittrex")),
#     ("bitstamp", _("Bitstamp"))
# )
# EXCHANGE_PERIODS = (
#     (300, "5-min"),
#     (900, "15-min"),
#     (1800, "30-min"),
#     (7200, "2-hr"),
#     (14400, "4-hr"),
#     (86400, "1-day")
# )
# STRATEGIES = (
#     ("To The Moon", "toTheMoon"),
#     ("Strategy 2", "strategy 2"),
# )
# INSTRUMENTS = (
#     ("ETH", _("Ethereum")),
#     ("DGB", _("DigiByte")),
#     ("XRP", _("Ripple")),
#     ("XMR", _("Monero")),
#     ("LTC", _("LiteCoin")),
#     ("LSK", _("LISK")),
#     ("STEEM", _("STEEM"))
# )
# MODES = (
#     ("backtest", _("Backtest")),
#     ("livetest", _("Live Backtest")),
#     ("live", _("Live"))
# )
#     BUY = 0
#     SELL = 1
# ORDER_TYPES = (
#     (OrderType.BUY, 'buy'),
#     (OrderType.SELL, 'sell')
# )
# OPEN, CANCELLED, PROCESSED = 'open', 'cancelled', 'processed'
# ORDER_STATES = (
#     (OPEN, _('open')),
#     (CANCELLED, _('cancelled')),
#     (PROCESSED, _('processed'))
# )
# SMA, EMA, RSI = 'sma', 'ema', 'rsi'
# INDICATORS = (
#     (SMA, _('sma')),
#     (EMA, _('ema')),
#     (RSI, _('rsi'))
# )
# class OrderType(object):
# 
# Path: crumpet/models.py
# class Order(models.Model):
#     type = models.IntegerField(
#         choices=constants.ORDER_TYPES,
#         max_length=255,
#         db_index=True
#     )
#     order_number = models.CharField(
#         null=True,
#         blank=True,
#         max_length=50,
#         verbose_name="Order Number"
#     )
#     amount = AmountField()
#     price = AmountField()
#     date = models.DateTimeField()
#     created = models.DateTimeField(auto_now_add=True)
#     updated = models.DateTimeField(auto_now=True)
#     user_account = models.ForeignKey(UserAccount, related_name='orders')
#     ticker = models.CharField(verbose_name='Ticker Symbol', max_length=30)
# 
#     status = models.CharField(
#         default=None,
#         choices=constants.ORDER_STATES,
#         max_length=255,
#         db_index=True
#     )
# 
#     class Meta:
#         ordering = ['-date']
#         get_latest_by = 'date'
#         db_table = 'bot_order'
# 
#     def __str__(self):
#         return '{type} {amount} BTC at {price} US$'.format(
#             type=self.get_type_display(),
#             amount=self.amount,
#             price=self.price
#         )


import json
from django.contrib import messages
from django.shortcuts import redirect, render
from django.urls import reverse
from django.views.generic import TemplateView, FormView
from poloniex import Poloniex
from crumpet.profiles import forms, models, constants
from crumpet.models import Order
        context = self.get_context_data(**kwargs)
        if not request.user.is_authenticated():
            return redirect(reverse('account_login'))
        polo = Poloniex()
        print(polo.returnTicker()['BTC_ETH'])

        user_account = models.UserAccount.objects.filter(
            user=self.request.user
        ).first()

        # if user_account.api_key and user_account.api_secret:
        #     polo = Poloniex(key=user_account.api_key, secret=user_account.api_secret)
        #     balance = polo.returnBalances()
        #     # balance = polo.returnCompleteBalances()
        #     ticker = polo.returnTicker()
        #
        #     balance = {key: value for key, value in balance.items() if float(value) != 0}
        #     context['balance'] = balance
        #     # context['ticker'] = ticker

        return self.render_to_response(context)


class AccountPageView(FormView):
    form_class = forms.UserAccountForm
    template_name = "crumpet/pages/account.html"

    def get_context_data(self, **kwargs):
        context = super(AccountPageView, self).get_context_data(**kwargs)
        form = context["form"]

# Path: crumpet/profiles/forms.py
# class UserAccountForm(forms.Form):
# 
# Path: crumpet/profiles/models.py
# class UserAccount(models.Model):
#     class Meta:
#     def __str__(self):
# 
# Path: crumpet/profiles/constants.py
# CRYPTO_EXCHANGES = (
#     ("poloniex", _("Poloniex")),
#     ("bittrex", _("Bittrex")),
#     ("bitstamp", _("Bitstamp"))
# )
# EXCHANGE_PERIODS = (
#     (300, "5-min"),
#     (900, "15-min"),
#     (1800, "30-min"),
#     (7200, "2-hr"),
#     (14400, "4-hr"),
#     (86400, "1-day")
# )
# STRATEGIES = (
#     ("To The Moon", "toTheMoon"),
#     ("Strategy 2", "strategy 2"),
# )
# INSTRUMENTS = (
#     ("ETH", _("Ethereum")),
#     ("DGB", _("DigiByte")),
#     ("XRP", _("Ripple")),
#     ("XMR", _("Monero")),
#     ("LTC", _("LiteCoin")),
#     ("LSK", _("LISK")),
#     ("STEEM", _("STEEM"))
# )
# MODES = (
#     ("backtest", _("Backtest")),
#     ("livetest", _("Live Backtest")),
#     ("live", _("Live"))
# )
#     BUY = 0
#     SELL = 1
# ORDER_TYPES = (
#     (OrderType.BUY, 'buy'),
#     (OrderType.SELL, 'sell')
# )
# OPEN, CANCELLED, PROCESSED = 'open', 'cancelled', 'processed'
# ORDER_STATES = (
#     (OPEN, _('open')),
#     (CANCELLED, _('cancelled')),
#     (PROCESSED, _('processed'))
# )
# SMA, EMA, RSI = 'sma', 'ema', 'rsi'
# INDICATORS = (
#     (SMA, _('sma')),
#     (EMA, _('ema')),
#     (RSI, _('rsi'))
# )
# class OrderType(object):
# 
# Path: crumpet/models.py
# class Order(models.Model):
#     type = models.IntegerField(
#         choices=constants.ORDER_TYPES,
#         max_length=255,
#         db_index=True
#     )
#     order_number = models.CharField(
#         null=True,
#         blank=True,
#         max_length=50,
#         verbose_name="Order Number"
#     )
#     amount = AmountField()
#     price = AmountField()
#     date = models.DateTimeField()
#     created = models.DateTimeField(auto_now_add=True)
#     updated = models.DateTimeField(auto_now=True)
#     user_account = models.ForeignKey(UserAccount, related_name='orders')
#     ticker = models.CharField(verbose_name='Ticker Symbol', max_length=30)
# 
#     status = models.CharField(
#         default=None,
#         choices=constants.ORDER_STATES,
#         max_length=255,
#         db_index=True
#     )
# 
#     class Meta:
#         ordering = ['-date']
#         get_latest_by = 'date'
#         db_table = 'bot_order'
# 
#     def __str__(self):
#         return '{type} {amount} BTC at {price} US$'.format(
#             type=self.get_type_display(),
#             amount=self.amount,
#             price=self.price
#         )


# Path: crumpet/views.py
import json
from django.contrib import messages
from django.shortcuts import redirect, render
from django.urls import reverse
from django.views.generic import TemplateView, FormView
from poloniex import Poloniex
from crumpet.profiles import forms, models, constants
from crumpet.models import Order

        context = self.get_context_data(**kwargs)
        if not request.user.is_authenticated():
            return redirect(reverse('account_login'))
        polo = Poloniex()
        print(polo.returnTicker()['BTC_ETH'])

        user_account = models.UserAccount.objects.filter(
            user=self.request.user
        ).first()

        # if user_account.api_key and user_account.api_secret:
        #     polo = Poloniex(key=user_account.api_key, secret=user_account.api_secret)
        #     balance = polo.returnBalances()
        #     # balance = polo.returnCompleteBalances()
        #     ticker = polo.returnTicker()
        #
        #     balance = {key: value for key, value in balance.items() if float(value) != 0}
        #     context['balance'] = balance
        #     # context['ticker'] = ticker

        return self.render_to_response(context)


class AccountPageView(FormView):
    form_class = forms.UserAccountForm
    template_name = "crumpet/pages/account.html"

    def get_context_data(self, **kwargs):
        context = super(AccountPageView, self).get_context_data(**kwargs)
        form = context["form"]

        user_account = models.UserAccount.objects.filter(