コード例 #1
0
 def setUp(self):
     super(TestAccount, self).setUp()
     self.owner = Owner(name='lucky')
     self.pesos = Currency(name='Pesos', code='ARG')
     self.exchange = Exchange(name='Merval', currency=self.pesos)
     self.free_broker = Broker(name='Free Broker')
     self.stock_one = Stock(symbol='PBR', description='Petrobras BR', ISIN='US71654V4086', exchange=self.exchange)
     self.stock_two = Stock(symbol='YPF', description='YPF S.A', ISIN='US9842451000', exchange=self.exchange)
     self.account=Account(owner=self.owner, broker=self.free_broker)
     self.money = Money(amount=1000, currency=self.pesos)
コード例 #2
0
    def test_is_order_met(self):
        now = datetime.datetime.now()
        broker = Broker(name='Broker1')
        account = Account(broker=broker)

        pesos = Currency(name='Pesos', code='ARG')
        account.deposit(Money(amount=10000, currency=pesos))
        exchange = Exchange(name='Merval', code='MERV', currency=pesos)
        stock = Stock(symbol='symbol',
                      description='a stock',
                      ISIN='US123456789',
                      exchange=exchange)
        tick1 = Tick(trade_date=now,
                     price=13.20,
                     amount=1000,
                     volume=1000,
                     security=stock)
        order1 = BuyOrder(account=account,
                          security=stock,
                          price=13.25,
                          share=10,
                          is_market=True)
        order2 = BuyOrder(account=account,
                          security=stock,
                          price=13.15,
                          share=10)
        order3 = SellOrder(account=account,
                           security=stock,
                           price=13.25,
                           share=10)
        order4 = SellOrder(account=account,
                           security=stock,
                           price=13.15,
                           share=10,
                           is_market=True)
        self.session.add(order1)
        self.session.add(order2)
        self.session.add(order3)
        self.session.add(order4)
        self.session.commit()

        self.assertTrue(order1.is_order_met(tick1))
        self.assertFalse(order2.is_order_met(tick1))
        self.assertFalse(order3.is_order_met(tick1))
        self.assertTrue(order4.is_order_met(tick1))
コード例 #3
0
    def test_security_quote(self):
        tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
        exchange = Exchange(name='Merval', code='MERV')
        security = Stock(symbol='PBR',
                         description='Petrobras BR',
                         ISIN='US71654V4086',
                         exchange=exchange)
        quote = SecurityQuote(date=tomorrow,
                              close_price=Decimal(100),
                              open_price=10.1,
                              high_price=14,
                              low_price=10.1,
                              volume=10000,
                              security=security)
        self.session.add(quote)
        self.session.commit()

        self.assertEquals(
            "<Quote('PBR', '{0}','10.1000000000', '14.0000000000', '10.1000000000', '100.0000000000', '10000.0000000000', 'None')>"
            .format(quote.date), str(quote))
コード例 #4
0
    def _buy_stock(self):
        pesos = Currency(name='Pesos', code='ARG')
        broker = Broker(name='Cheap')
        self.account = Account(broker=broker)
        ten_thousand_pesos = Money(amount=Decimal(10000), currency=pesos)
        self.account.deposit(ten_thousand_pesos)
        exchange = Exchange(name='Merval', currency=pesos)
        self.security = Stock(symbol='PBR',
                              description='Petrobras BR',
                              ISIN='US71654V4086',
                              exchange=exchange)
        filled_stage = FillOrderStage(executed_on=datetime.datetime.now())
        price = Decimal(10)
        share = 10
        order = BuyOrder(account=self.account,
                         security=self.security,
                         stage=filled_stage,
                         price=price,
                         share=share)

        self.session.add(order)
        self.session.commit()
        return self.account
コード例 #5
0
    def test_exchange_str(self):
        exchange = Exchange(name='Merval', code='MERV')

        self.assertEquals('Exchange MERV Merval', str(exchange))