Esempio n. 1
0
    def test_event(self):
        open = SignalEvent(SignalAction.OPEN,
                           HLHBTrendStrategy.name,
                           HLHBTrendStrategy.version,
                           HLHBTrendStrategy.magic_number,
                           instrument='EURUSD',
                           side=OrderSide.BUY,
                           order_type=OrderType.MARKET,
                           stop_loss=30,
                           take_profit=50,
                           trailing_stop=None,
                           percent=None)
        close = SignalEvent(SignalAction.CLOSE,
                            HLHBTrendStrategy.name,
                            HLHBTrendStrategy.version,
                            HLHBTrendStrategy.magic_number,
                            instrument='EURUSD',
                            side=OrderSide.BUY,
                            percent=0.5)

        data = json.dumps(open.to_dict())
        data2 = json.loads(data)
        open2 = Event.from_dict(data2)

        self.assertEqual(open.type, open2.type)
        for k in open.__dict__.keys():
            self.assertEqual(open.__dict__[k], open2.__dict__[k])

        data = json.dumps(close.to_dict())
        data2 = json.loads(data)
        close2 = Event.from_dict(data2)

        self.assertEqual(close.type, close2.type)
        for k in close.__dict__.keys():
            self.assertEqual(close.__dict__[k], close2.__dict__[k])
Esempio n. 2
0
    def receive_ball(self, received_ball):
        logger.debug('I received a ball.', received_ball=received_ball)
        ball = []
        for event in received_ball:
            logger.debug('Looping events.', current_event=event)
            ball.append(Event.from_dict(event))

        for event in ball:
            if event.ttl < self.ttl:
                if event in self.next_ball:
                    for e in self.next_ball:
                        if e.event_id == event.event_id and e.ttl < event.ttl:
                            e.ttl = event.ttl
                else:
                    self.next_ball.add(event)
            self.stability_oracle.update_clock(event.ts)