'The market value is tricky to calculate as we only have
access to the top of the order book through Interactive
Brokers, which means that the true redemption price is
unknown until executed.
However, it can be estimated via the mid-price of the
bid-ask spread. Once the market value is calculated it
allows calculation of the unrealised and realised profit
and loss of any transactions.'

def update_market_value(self, bid, ask):

    midpoint = ((bid + ask) // 2)
    self.market_value = ((self.quantity * midpoint) * sign(self.net))
    self.unrealised_pnl = (self.market_value - self.cost_basis)
