Ejemplo n.º 1
0
    def test_ParseTables(self):
        # test equity tables

        dd_mmm_yyyy = StrDate.default_format(format="%d-%b-%Y")
        schema = [
            str, str, dd_mmm_yyyy, float, float, float, float, float, float,
            float, int, float, int, int, float
        ]
        bs = BeautifulSoup(htmls.html_equity)
        t = ParseTables(soup=bs, schema=schema)
        lst = text_to_list(htmls.csv_equity, schema=schema)
        self.assertEqual(lst, t.get_tables())

        # test derivative tables
        schema = [
            str, dd_mmm_yyyy, dd_mmm_yyyy, float, float, float, float, float,
            float, int, float, int, int, float
        ]
        bs = BeautifulSoup(htmls.html_derivative)
        t = ParseTables(soup=bs, schema=schema)
        lst = text_to_list(htmls.csv_derivative, schema)
        self.assertEqual(lst, t.get_tables())

        # test index tables
        schema = [dd_mmm_yyyy, float, float, float, float, int, float]
        bs = BeautifulSoup(htmls.html_index)
        t = ParseTables(soup=bs, schema=schema)
        lst = text_to_list(htmls.csv_index, schema)
        self.assertEqual(lst, t.get_tables())
Ejemplo n.º 2
0
 def test_ParseTables_equity(self):
     # test equity tables
     dd_mmm_yyyy = StrDate.default_format(format="%d-%b-%Y")
     # schema for equity history values
     schema = [str, str,
               dd_mmm_yyyy,
               float, float, float, float,
               float, float, float, int, float,
               int, int, float]
     bs = BeautifulSoup(htmls.html_equity)
     t = ParseTables(soup=bs,
                     schema=schema)
     lst = text_to_list(htmls.csv_equity, schema)
     self.assertEqual(lst, t.get_tables())
     
     #test derivative tables
     schema = [str, dd_mmm_yyyy, dd_mmm_yyyy,
               float, float, float, float,
               float, float, int, float,
               int, int, float]
     bs = BeautifulSoup(htmls.html_derivative)
     t = ParseTables(soup=bs,
                     schema=schema)
     lst = text_to_list(htmls.csv_derivative, schema)
     self.assertEqual(lst, t.get_tables())
     
     #test index tables
     schema = [dd_mmm_yyyy,
               float, float, float, float,
               int, float]
     bs = BeautifulSoup(htmls.html_index)
     t = ParseTables(soup=bs,
                     schema=schema)
     lst = text_to_list(htmls.csv_index, schema)
     self.assertEqual(lst, t.get_tables())
Ejemplo n.º 3
0
 def test_ParseTables_headers(self):
     # test equity tables
     dd_mmm_yyyy = StrDate.default_format(format="%d-%b-%Y")
     # schema for equity history values
     schema = [
         str, str, dd_mmm_yyyy, float, float, float, float, float, float,
         float, int, float, int, int, float
     ]
     headers = [
         "Symbol", "Series", "Date", "Prev Close", "Open", "High", "Low",
         "Last", "Close", "VWAP", "Volume", "Turnover", "Trades",
         "Deliverable Volume", "%Deliverble"
     ]
     bs = BeautifulSoup(htmls.html_equity)
     t = ParseTables(soup=bs, schema=schema, headers=headers, index='Date')
     lst = text_to_list(htmls.csv_equity, schema)
     df = t.get_df()
     self.assertIn("Symbol", df.columns, str(df.columns))
Ejemplo n.º 4
0
 def test_ParseTables_headers(self):
     # test equity tables
     dd_mmm_yyyy = StrDate.default_format(format="%d-%b-%Y")
     # schema for equity history values
     schema = [str, str,
               dd_mmm_yyyy,
               float, float, float, float,
               float, float, float, int, float,
               int, int, float]
     headers = ["Symbol", "Series", "Date", "Prev Close", 
               "Open", "High", "Low","Last", "Close", "VWAP",
               "Volume", "Turnover", "Trades", "Deliverable Volume",
               "%Deliverble"]
     bs = BeautifulSoup(htmls.html_equity)
     t = ParseTables(soup=bs,
                     schema=schema, headers=headers,index='Date')
     lst = text_to_list(htmls.csv_equity, schema)
     df = t.get_df()
     self.assertIn("Symbol",df.columns, str(df.columns))
Ejemplo n.º 5
0
 def test_StrDate(self):
     dd_mmm_yyyy = StrDate.default_format(format="%d-%b-%Y")
     dt1 = dd_mmm_yyyy(date="12-Nov-2012")
     dt2 = datetime.date(2012, 11, 12)
     self.assertEqual(dt1, dt2)
Ejemplo n.º 6
0
 def test_StrDate(self):
     dd_mmm_yyyy = StrDate.default_format(format="%d-%b-%Y")
     dt1 = dd_mmm_yyyy(date= "12-Nov-2012")
     dt2 = datetime.date(2012, 11, 12)
     self.assertEqual(dt1, dt2)
Ejemplo n.º 7
0
from django.db import models
from datetime import datetime
# Create your models here.
from nsepy.commons import StrDate
dd_mmm_yyyy = StrDate.default_format(format="%d-%b-%Y")


class Stock(models.Model):
    symbol = models.CharField(default='NA', primary_key=True, max_length=200)

    def __str__(self):
        return self.symbol


class Share(models.Model):
    symbol = models.ForeignKey(Stock, db_index=True)
    series = models.CharField(default='NA', max_length=200)
    date = models.DateTimeField(default=datetime.now())
    prev_close = models.FloatField(default=0.0)
    open = models.FloatField(default=0.0)
    high = models.FloatField(default=0.0)
    low = models.FloatField(default=0.0)
    last = models.FloatField(default=0.0)
    close = models.FloatField(default=0.0)
    vwap = models.FloatField(default=0.0)
    volume = models.IntegerField(default=0)
    turnover = models.FloatField(default=0.0)
    trades = models.IntegerField(default=0)
    deliverable_volume = models.IntegerField(default=0)
    percentage_deliverable = models.FloatField(default=0.0)