Exemple #1
0
    def test_save_data(self):
        sp = StockPos()
        sp.save_raw_data(position=self.position, raw_stock=self.raw_stock)

        print 'stock row count in db: %d\n' % len(StockPos.objects.all())
        self.assertEqual(len(StockPos.objects.all()), 1)

        print 'Stock Position in db:'
        print StockPos.objects.get(id=1)
Exemple #2
0
    def save_position(self):
        """
        save all into db
        """
        instrument_count = 0
        option_count = 0

        # now import all symbol position in files into db
        for symbol, items in self.position.items():
            instrument = items["Instrument"]
            stock = items["Stock"]
            options = items["Options"]

            # get company name
            company = stock["name"]

            # leg_identify insert position

            position = Position(symbol=symbol, company=company, date=self.date)
            position.save()

            # second insert instrument
            instrument_pos = InstrumentPos()
            instrument_pos.save_raw_data(position=position, raw_instrument=instrument)

            # third insert stock
            stock_pos = StockPos()
            stock_pos.save_raw_data(position=position, raw_stock=stock)

            # fourth and final insert option
            for option in options:
                option_pos = OptionPos()
                option_pos.save_raw_data(position=position, raw_option=option)

                option_count += 1

            # update insert count
            instrument_count += 1

        # after finish clear data
        self.position = None

        return instrument_count, option_count