from django.db import models
from unixtimestampfield.fields import UnixTimeStampField

#from apps.channel.models.exchange_data import SOURCE_CHOICES
from apps.indicator.models.price import Price

from settings import SOURCE_CHOICES, COUNTER_CURRENCY_CHOICES, BTC

from datetime import timedelta, datetime
import pandas as pd

class Volume(models.Model):
    source = models.SmallIntegerField(choices=SOURCE_CHOICES, null=False)
    transaction_currency = models.CharField(max_length=6, null=False, blank=False)
    counter_currency = models.SmallIntegerField(choices=COUNTER_CURRENCY_CHOICES,
                                         null=False, default=BTC)

    volume = models.FloatField(null=False)
    timestamp = UnixTimeStampField(null=False)


    # MODEL PROPERTIES

    # MODEL FUNCTIONS

def get_n_last_volumes_ts(n, source, transaction_currency, counter_currency):
    back_in_time_records = list(Volume.objects.filter(
        source=source,
        transaction_currency=transaction_currency,
        counter_currency=counter_currency,
        timestamp__gte=datetime.now() - timedelta(minutes=n)
    ).values('timestamp', 'volume').order_by('timestamp'))

    if back_in_time_records:
        return pd.Series(
            data = [rec['volume'] for rec in back_in_time_records],
            index=[rec['timestamp'] for rec in back_in_time_records]
        )
d1d0a4e78eee2b346ce58b75c526e7245a6efdec
<mask token>


class Volume(models.Model):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>


<mask token>

<mask token>


class Volume(models.Model):
    source = models.SmallIntegerField(choices=SOURCE_CHOICES, null=False)
    transaction_currency = models.CharField(max_length=6, null=False, blank
        =False)
    counter_currency = models.SmallIntegerField(choices=
        COUNTER_CURRENCY_CHOICES, null=False, default=BTC)
    volume = models.FloatField(null=False)
    timestamp = UnixTimeStampField(null=False)


<mask token>

<mask token>


class Volume(models.Model):
    source = models.SmallIntegerField(choices=SOURCE_CHOICES, null=False)
    transaction_currency = models.CharField(max_length=6, null=False, blank
        =False)
    counter_currency = models.SmallIntegerField(choices=
        COUNTER_CURRENCY_CHOICES, null=False, default=BTC)
    volume = models.FloatField(null=False)
    timestamp = UnixTimeStampField(null=False)


def get_n_last_volumes_ts(n, source, transaction_currency, counter_currency):
    back_in_time_records = list(Volume.objects.filter(source=source,
        transaction_currency=transaction_currency, counter_currency=
        counter_currency, timestamp__gte=datetime.now() - timedelta(minutes
        =n)).values('timestamp', 'volume').order_by('timestamp'))
    if back_in_time_records:
        return pd.Series(data=[rec['volume'] for rec in
            back_in_time_records], index=[rec['timestamp'] for rec in
            back_in_time_records])

from django.db import models
from unixtimestampfield.fields import UnixTimeStampField
from apps.indicator.models.price import Price
from settings import SOURCE_CHOICES, COUNTER_CURRENCY_CHOICES, BTC
from datetime import timedelta, datetime
import pandas as pd


class Volume(models.Model):
    source = models.SmallIntegerField(choices=SOURCE_CHOICES, null=False)
    transaction_currency = models.CharField(max_length=6, null=False, blank
        =False)
    counter_currency = models.SmallIntegerField(choices=
        COUNTER_CURRENCY_CHOICES, null=False, default=BTC)
    volume = models.FloatField(null=False)
    timestamp = UnixTimeStampField(null=False)


def get_n_last_volumes_ts(n, source, transaction_currency, counter_currency):
    back_in_time_records = list(Volume.objects.filter(source=source,
        transaction_currency=transaction_currency, counter_currency=
        counter_currency, timestamp__gte=datetime.now() - timedelta(minutes
        =n)).values('timestamp', 'volume').order_by('timestamp'))
    if back_in_time_records:
        return pd.Series(data=[rec['volume'] for rec in
            back_in_time_records], index=[rec['timestamp'] for rec in
            back_in_time_records])

from django.db import models
from unixtimestampfield.fields import UnixTimeStampField

#from apps.channel.models.exchange_data import SOURCE_CHOICES
from apps.indicator.models.price import Price

from settings import SOURCE_CHOICES, COUNTER_CURRENCY_CHOICES, BTC

from datetime import timedelta, datetime
import pandas as pd

class Volume(models.Model):
    source = models.SmallIntegerField(choices=SOURCE_CHOICES, null=False)
    transaction_currency = models.CharField(max_length=6, null=False, blank=False)
    counter_currency = models.SmallIntegerField(choices=COUNTER_CURRENCY_CHOICES,
                                         null=False, default=BTC)

    volume = models.FloatField(null=False)
    timestamp = UnixTimeStampField(null=False)


    # MODEL PROPERTIES

    # MODEL FUNCTIONS

def get_n_last_volumes_ts(n, source, transaction_currency, counter_currency):
    back_in_time_records = list(Volume.objects.filter(
        source=source,
        transaction_currency=transaction_currency,
        counter_currency=counter_currency,
        timestamp__gte=datetime.now() - timedelta(minutes=n)
    ).values('timestamp', 'volume').order_by('timestamp'))

    if back_in_time_records:
        return pd.Series(
            data = [rec['volume'] for rec in back_in_time_records],
            index=[rec['timestamp'] for rec in back_in_time_records]
        )