File size: 1,384 Bytes
9d4bd7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from tortoise import fields, models
from tortoise.contrib.pydantic import pydantic_model_creator
from tortoise.contrib.pydantic.creator import pydantic_queryset_creator
from tortoise.queryset import QuerySet

class Bond(models.Model):
    id = fields.IntField(pk=True)
    instrument_type = fields.CharField(max_length=50)
    auction_number = fields.IntField()
    auction_date = fields.DateField()
    maturity_years = fields.CharField(max_length=10)
    maturity_date = fields.DateField()
    effective_date = fields.DateField()
    dtm = fields.IntField()
    bond_auction_number = fields.IntField()
    holding_number = fields.IntField()
    face_value = fields.BigIntField()
    price_per_100 = fields.FloatField()
    coupon_rate = fields.FloatField()
    isin = fields.CharField(max_length=12, unique=True)

    @staticmethod
    async def get_list(data):

        if type(data) == QuerySet:
            parser=pydantic_queryset_creator(Bond)
            return await parser.from_queryset(data)

        if type(data) == type([Bond]):
            return [ await i.to_dict() for i in data]


    async def to_dict(self):
        if type(self) == Bond:
            parser=pydantic_model_creator(Bond)
            return await parser.from_tortoise_orm(self)


        
        

    class Meta:
        table = "bonds"
        unique_together = ("auction_number", "auction_date")