Every 30 mins the UK energy suppliers put in a bid for how much energy they can produce and what price they will do it for. The UK then selects the cheapest N companies to fufill the predicted energy demand. Each company selected is then paid the price of the most expensive supplier chosen which is usually gas.This is a simplification of what the Octopus Energy CEO explains in the link below starts ~1:40.