Answering my own question.

The order.ref answer that was given in that forum post actually works. My mistake was that I wanted to get the attributes directly and compare them. However the order class has overwritten the == method in which itself it compares ref attributes.

So instead of

if self.tradeid == order.ref:

I had to write

if self.tradeid == order: