# Path: crumpet/backtests/forms.py
# class ToTheMoonStrategyForm(forms.Form):
# 
# Path: crumpet/tradebot.py
# class Tradebot(object):
#     def __init__(self, mode: str, wallet: Wallet, strategy: str, instrument: str, period: int, **kwargs) -> None:
#     def __repr__(self):
#     def restart(self):
#     def increment_timer(self):
#     def start_live_backtest(self):
#     def init_live_bot_start(self) -> None:
#     def init_bot_start(self) -> []:
#     def get_time(self):
#     def start(self):
#     def stop(self):
#     def buy_and_hold(price, wallet):
#     def buy_and_hold_efficiency(tick):
#     def display_stats(self, timer, tick):


import simplejson
from django.http import JsonResponse
from django.shortcuts import render
from django.views.generic import FormView
from crumpet.backtests import forms
from crumpet.tradebot import Tradebot, Wallet
        sma_period = form.cleaned_data['sma_period']
        ema_period = form.cleaned_data['ema_period']

        bot = Tradebot(
            mode=mode,
            wallet=wallet,
            strategy=strategy,
            instrument=instrument, period=int(period),
            start_date=start_date, end_date=end_date,
            sma_period=sma_period, ema_period=ema_period)
        data = bot.start()

        data = simplejson.dumps(data.result(), ignore_nan=True)
        return JsonResponse(simplejson.loads(data))


class LiveTestView(FormView):
    form_class = forms.ToTheMoonStrategyForm
    template_name = "backtests/livetest.html"

    def form_valid(self, form):
        context = self.get_context_data()
        exchange = form.cleaned_data['exchange']
        instrument = form.cleaned_data['instrument']
        period = form.cleaned_data['exchange_period']

        if form.cleaned_data['trading_fee']:
            trading_fee = float(form.cleaned_data['trading_fee'])
            wallet = Wallet(assets=100, currency=100, instrument=instrument, fee=trading_fee)
        else:

# Path: crumpet/backtests/forms.py
# class ToTheMoonStrategyForm(forms.Form):
# 
# Path: crumpet/tradebot.py
# class Tradebot(object):
#     def __init__(self, mode: str, wallet: Wallet, strategy: str, instrument: str, period: int, **kwargs) -> None:
#     def __repr__(self):
#     def restart(self):
#     def increment_timer(self):
#     def start_live_backtest(self):
#     def init_live_bot_start(self) -> None:
#     def init_bot_start(self) -> []:
#     def get_time(self):
#     def start(self):
#     def stop(self):
#     def buy_and_hold(price, wallet):
#     def buy_and_hold_efficiency(tick):
#     def display_stats(self, timer, tick):


# Path: crumpet/backtests/views.py
import simplejson
from django.http import JsonResponse
from django.shortcuts import render
from django.views.generic import FormView
from crumpet.backtests import forms
from crumpet.tradebot import Tradebot, Wallet

        sma_period = form.cleaned_data['sma_period']
        ema_period = form.cleaned_data['ema_period']

        bot = Tradebot(
            mode=mode,
            wallet=wallet,
            strategy=strategy,
            instrument=instrument, period=int(period),
            start_date=start_date, end_date=end_date,
            sma_period=sma_period, ema_period=ema_period)
        data = bot.start()

        data = simplejson.dumps(data.result(), ignore_nan=True)
        return JsonResponse(simplejson.loads(data))


class LiveTestView(FormView):
    form_class = forms.ToTheMoonStrategyForm
    template_name = "backtests/livetest.html"

    def form_valid(self, form):
        context = self.get_context_data()
        exchange = form.cleaned_data['exchange']
        instrument = form.cleaned_data['instrument']
        period = form.cleaned_data['exchange_period']

        if form.cleaned_data['trading_fee']:
            trading_fee = float(form.cleaned_data['trading_fee'])
            wallet = Wallet(assets=100, currency=100, instrument=instrument, fee=trading_fee)
        else:

            wallet = Wallet(assets=100, currency=100, instrument=instrument)