betcode-org / flumine

flūmine - Betting trading framework
MIT License
177 stars 60 forks source link

Fix utils.get_file_md #761

Closed mberk closed 2 months ago

mberk commented 5 months ago

After changes in https://github.com/betcode-org/flumine/pull/693, utils.get_file_md no longer gracefully handles the case where the first line of the file contains a non-empty mc list where the first element is missing a marketDefinition field

On this line: https://github.com/betcode-org/flumine/blob/0241aca36f751bf1e35c5f8d7242735d2f1a5687/flumine/utils.py#L80 if the field is missing then md is set to a default value of an empty dictionary. However, it is not possible to then construct a MarketDefinition object from an empty dictionary on the following line: https://github.com/betcode-org/flumine/blob/0241aca36f751bf1e35c5f8d7242735d2f1a5687/flumine/utils.py#L81 as the following exception gets thrown:

TypeError: MarketDefinition.__init__() missing 22 required positional arguments: 'betDelay', 'bettingType', 'bspMarket', 'bspReconciled', 'complete', 'crossMatching', 'discountAllowed', 'eventId', 'eventTypeId', 'inPlay', 'marketBaseRate', 'marketTime', 'numberOfActiveRunners', 'numberOfWinners', 'persistenceEnabled', 'regulators', 'runnersVoidable', 'status', 'timezone', 'turnInPlayEnabled', 'version', and 'runners'

The fix is to guard against the marketDefinition field being missing and to return None if that is the case. A new unit test has been added which fails under the old code but passes with the added guard