I have a bz2-file from betfair with historical odds of 1 match and 1 market (match-odds) In fact I have a lot of bz2-files, but I simplify it to 1 here I want to convert it to a csv-file. The website https://www.betfairhistoricdata.co.uk/ does this very good and the website is powered by the python package 'betfairlightweight'.
I want the same output like the website but I can't replicate it in python, is it possible to provide me the code with betfairlightweight (or with another package is also ok).
bz2-file content
{"op":"mcm","clk":"10414445718","pt":1704314685202,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"OPEN","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"GMT","openDate":"2024-02-01T19:30:00.000Z","version":5663400343,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
{"op":"mcm","clk":"10422905409","pt":1704464572326,"mc":[{"id":"1.223091126","rc":[{"ltp":2.28,"id":48756},{"ltp":3.3,"id":1141}]}]}
{"op":"mcm","clk":"10425186776","pt":1704489481069,"mc":[{"id":"1.223091126","rc":[{"ltp":2.16,"id":48756}]}]}
{"op":"mcm","clk":"10432388950","pt":1704570330490,"mc":[{"id":"1.223091126","rc":[{"ltp":2.22,"id":48756}]}]}
{"op":"mcm","clk":"10435187755","pt":1704625091119,"mc":[{"id":"1.223091126","rc":[{"ltp":2.26,"id":48756}]}]}
{"op":"mcm","clk":"10437449719","pt":1704643845497,"mc":[{"id":"1.223091126","rc":[{"ltp":2.38,"id":48756}]}]}
{"op":"mcm","clk":"10442281047","pt":1704720154240,"mc":[{"id":"1.223091126","rc":[{"ltp":3.7,"id":58805}]}]}
{"op":"mcm","clk":"10443741528","pt":1704747459225,"mc":[{"id":"1.223091126","rc":[{"ltp":2.26,"id":48756},{"ltp":3.4,"id":1141}]}]}
{"op":"mcm","clk":"10444017555","pt":1704753820826,"mc":[{"id":"1.223091126","rc":[{"ltp":2.24,"id":48756}]}]}
{"op":"mcm","clk":"10445453091","pt":1704782335460,"mc":[{"id":"1.223091126","rc":[{"ltp":2.26,"id":48756}]}]}
{"op":"mcm","clk":"10446022742","pt":1704792595601,"mc":[{"id":"1.223091126","rc":[{"ltp":4.0,"id":58805}]}]}
{"op":"mcm","clk":"10446476255","pt":1704800674197,"mc":[{"id":"1.223091126","rc":[{"ltp":2.28,"id":48756}]}]}
{"op":"mcm","clk":"10447114386","pt":1704811255024,"mc":[{"id":"1.223091126","rc":[{"ltp":3.7,"id":58805},{"ltp":2.56,"id":48756},{"ltp":3.05,"id":1141}]}]}
{"op":"mcm","clk":"10447122760","pt":1704811372095,"mc":[{"id":"1.223091126","rc":[{"ltp":2.52,"id":48756}]}]}
{"op":"mcm","clk":"10447235920","pt":1704812793414,"mc":[{"id":"1.223091126","rc":[{"ltp":2.48,"id":48756}]}]}
{"op":"mcm","clk":"10447847933","pt":1704820144554,"mc":[{"id":"1.223091126","rc":[{"ltp":2.66,"id":48756}]}]}
{"op":"mcm","clk":"10454483898","pt":1704915831409,"mc":[{"id":"1.223091126","rc":[{"ltp":2.48,"id":48756}]}]}
{"op":"mcm","clk":"10458202960","pt":1704972759939,"mc":[{"id":"1.223091126","rc":[{"ltp":2.64,"id":48756}]}]}
{"op":"mcm","clk":"10477063575","pt":1705176328375,"mc":[{"id":"1.223091126","rc":[{"ltp":3.0,"id":1141}]}]}
{"op":"mcm","clk":"10477573853","pt":1705180907388,"mc":[{"id":"1.223091126","rc":[{"ltp":2.54,"id":48756}]}]}
{"op":"mcm","clk":"10478235475","pt":1705189060371,"mc":[{"id":"1.223091126","rc":[{"ltp":2.46,"id":48756}]}]}
{"op":"mcm","clk":"10479072293","pt":1705199331450,"mc":[{"id":"1.223091126","rc":[{"ltp":2.98,"id":1141}]}]}
{"op":"mcm","clk":"10480774727","pt":1705222843519,"mc":[{"id":"1.223091126","rc":[{"ltp":2.52,"id":48756}]}]}
{"op":"mcm","clk":"10486319404","pt":1705270561035,"mc":[{"id":"1.223091126","rc":[{"ltp":3.8,"id":58805}]}]}
{"op":"mcm","clk":"10486415077","pt":1705272213348,"mc":[{"id":"1.223091126","rc":[{"ltp":2.48,"id":48756}]}]}
{"op":"mcm","clk":"10494636837","pt":1705397335431,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-01-16T09:30:03.000Z","suspendTime":"2024-01-16T09:30:03.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"OPEN","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe/London","openDate":"2024-01-16T09:30:03.000Z","version":5682014978,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
{"op":"mcm","clk":"10494644637","pt":1705397444854,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-01-16T09:30:03.000Z","suspendTime":"2024-01-16T09:30:03.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"SUSPENDED","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe/London","openDate":"2024-01-16T09:30:03.000Z","version":5682018825,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
{"op":"mcm","clk":"10494742371","pt":1705398656173,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"SUSPENDED","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe/London","openDate":"2024-02-01T19:30:00.000Z","version":5682038859,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
{"op":"mcm","clk":"10494746225","pt":1705398710970,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"OPEN","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe/London","openDate":"2024-02-01T19:30:00.000Z","version":5682039132,"name":"Match Odds","eventName":"West Ham v Bournemouth"},"rc":[{"ltp":2.46,"id":48756},{"ltp":3.05,"id":1141}]}]}
{"op":"mcm","clk":"10600341058","pt":1706821796486,"mc":[{"id":"1.223091126","rc":[{"ltp":1.58,"id":58805},{"ltp":6.6,"id":48756},{"ltp":4.5,"id":1141}]}]}
{"op":"mcm","clk":"10600345889","pt":1706821856460,"mc":[{"id":"1.223091126","rc":[{"ltp":1.59,"id":58805},{"ltp":5.9,"id":48756},{"ltp":5.1,"id":1141}]}]}
{"op":"mcm","clk":"10600351148","pt":1706821916517,"mc":[{"id":"1.223091126","rc":[{"ltp":1.55,"id":58805},{"ltp":7.0,"id":48756},{"ltp":4.5,"id":1141}]}]}
{"op":"mcm","clk":"10600356640","pt":1706821976500,"mc":[{"id":"1.223091126","rc":[{"ltp":1.5,"id":58805},{"ltp":7.8,"id":48756},{"ltp":4.7,"id":1141}]}]}
{"op":"mcm","clk":"10600361459","pt":1706822036516,"mc":[{"id":"1.223091126","rc":[{"ltp":1.46,"id":58805},{"ltp":7.6,"id":48756},{"ltp":5.3,"id":1141}]}]}
{"op":"mcm","clk":"10600366005","pt":1706822096518,"mc":[{"id":"1.223091126","rc":[{"ltp":1.38,"id":58805},{"ltp":9.4,"id":48756},{"ltp":5.6,"id":1141}]}]}
{"op":"mcm","clk":"10600370890","pt":1706822156480,"mc":[{"id":"1.223091126","rc":[{"ltp":8.6,"id":48756},{"ltp":6.2,"id":1141}]}]}
{"op":"mcm","clk":"10600375997","pt":1706822216544,"mc":[{"id":"1.223091126","rc":[{"ltp":1.32,"id":58805},{"ltp":10.0,"id":48756},{"ltp":7.2,"id":1141}]}]}
{"op":"mcm","clk":"10600380511","pt":1706822276476,"mc":[{"id":"1.223091126","rc":[{"ltp":9.2,"id":48756},{"ltp":7.4,"id":1141}]}]}
{"op":"mcm","clk":"10600384714","pt":1706822336524,"mc":[{"id":"1.223091126","rc":[{"ltp":1.35,"id":58805},{"ltp":10.0,"id":48756},{"ltp":6.4,"id":1141}]}]}
{"op":"mcm","clk":"10600389208","pt":1706822396502,"mc":[{"id":"1.223091126","rc":[{"ltp":1.3,"id":58805},{"ltp":10.5,"id":48756},{"ltp":7.2,"id":1141}]}]}
{"op":"mcm","clk":"10600393788","pt":1706822456472,"mc":[{"id":"1.223091126","rc":[{"ltp":1.26,"id":58805},{"ltp":13.5,"id":48756},{"ltp":7.0,"id":1141}]}]}
{"op":"mcm","clk":"10600397983","pt":1706822516506,"mc":[{"id":"1.223091126","rc":[{"ltp":1.22,"id":58805},{"ltp":17.0,"id":48756},{"ltp":8.6,"id":1141}]}]}
{"op":"mcm","clk":"10600401728","pt":1706822576486,"mc":[{"id":"1.223091126","rc":[{"ltp":1.15,"id":58805},{"ltp":19.0,"id":48756},{"ltp":12.5,"id":1141}]}]}
{"op":"mcm","clk":"10600405462","pt":1706822636487,"mc":[{"id":"1.223091126","rc":[{"ltp":1.13,"id":58805},{"ltp":26.0,"id":48756},{"ltp":14.0,"id":1141}]}]}
{"op":"mcm","clk":"10600408925","pt":1706822696518,"mc":[{"id":"1.223091126","rc":[{"ltp":1.07,"id":58805},{"ltp":30.0,"id":48756},{"ltp":22.0,"id":1141}]}]}
{"op":"mcm","clk":"10600412523","pt":1706822756490,"mc":[{"id":"1.223091126","rc":[{"ltp":1.05,"id":58805},{"ltp":50.0,"id":48756},{"ltp":23.0,"id":1141}]}]}
{"op":"mcm","clk":"10600416101","pt":1706822813177,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":true,"complete":true,"inPlay":true,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":5,"status":"SUSPENDED","runners":[{"status":"ACTIVE","sortPriority":1,"bsp":2.54,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"bsp":2.92,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"bsp":3.8,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"GMT","openDate":"2024-02-01T19:30:00.000Z","version":5709608432,"name":"Match Odds","eventName":"West Ham v Bournemouth"},"rc":[{"ltp":1.04,"id":58805},{"ltp":70.0,"id":48756},{"ltp":32.0,"id":1141}]}]}
{"op":"mcm","clk":"10600428678","pt":1706823040197,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":true,"complete":true,"inPlay":true,"crossMatching":false,"runnersVoidable":false,"numberOfActiveRunners":0,"betDelay":5,"status":"CLOSED","settledTime":"2024-02-01T21:27:54.000Z","runners":[{"status":"LOSER","sortPriority":1,"bsp":2.54,"id":48756,"name":"West Ham"},{"status":"LOSER","sortPriority":2,"bsp":2.92,"id":1141,"name":"Bournemouth"},{"status":"WINNER","sortPriority":3,"bsp":3.8,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"GMT","openDate":"2024-02-01T19:30:00.000Z","version":5709611525,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
csv-file content output
marketId,publishTime,selection_selectionId,selection_lastPriceTraded
1.223091126,2024-01-03 20:44:45.202000,48756,
1.223091126,2024-01-03 20:44:45.202000,1141,
1.223091126,2024-01-03 20:44:45.202000,58805,
1.223091126,2024-01-05 14:22:52.326000,48756,2.28
1.223091126,2024-01-05 14:22:52.326000,1141,3.3
1.223091126,2024-01-05 21:18:01.069000,48756,2.16
1.223091126,2024-01-06 19:45:30.490000,48756,2.22
1.223091126,2024-01-07 10:58:11.119000,48756,2.26
1.223091126,2024-01-07 16:10:45.497000,48756,2.38
1.223091126,2024-01-08 13:22:34.240000,58805,3.7
1.223091126,2024-01-08 20:57:39.225000,48756,2.26
1.223091126,2024-01-08 20:57:39.225000,1141,3.4
1.223091126,2024-01-08 22:43:40.826000,48756,2.24
1.223091126,2024-01-09 06:38:55.460000,48756,2.26
1.223091126,2024-01-09 09:29:55.601000,58805,4.0
1.223091126,2024-01-09 11:44:34.197000,48756,2.28
1.223091126,2024-01-09 14:40:55.024000,48756,2.56
1.223091126,2024-01-09 14:40:55.024000,1141,3.05
1.223091126,2024-01-09 14:40:55.024000,58805,3.7
1.223091126,2024-01-09 14:42:52.095000,48756,2.52
1.223091126,2024-01-09 15:06:33.414000,48756,2.48
1.223091126,2024-01-09 17:09:04.554000,48756,2.66
1.223091126,2024-01-10 19:43:51.409000,48756,2.48
1.223091126,2024-01-11 11:32:39.939000,48756,2.64
1.223091126,2024-01-13 20:05:28.375000,1141,3.0
1.223091126,2024-01-13 21:21:47.388000,48756,2.54
1.223091126,2024-01-13 23:37:40.371000,48756,2.46
1.223091126,2024-01-14 02:28:51.450000,1141,2.98
1.223091126,2024-01-14 09:00:43.519000,48756,2.52
1.223091126,2024-01-14 22:16:01.035000,58805,3.8
1.223091126,2024-01-14 22:43:33.348000,48756,2.48
1.223091126,2024-01-16 09:51:50.970000,48756,2.46
1.223091126,2024-01-16 09:51:50.970000,1141,3.05
1.223091126,2024-02-01 21:09:56.486000,48756,6.6
1.223091126,2024-02-01 21:09:56.486000,1141,4.5
1.223091126,2024-02-01 21:09:56.486000,58805,1.58
1.223091126,2024-02-01 21:10:56.460000,48756,5.9
1.223091126,2024-02-01 21:10:56.460000,1141,5.1
1.223091126,2024-02-01 21:10:56.460000,58805,1.59
1.223091126,2024-02-01 21:11:56.517000,48756,7.0
1.223091126,2024-02-01 21:11:56.517000,1141,4.5
1.223091126,2024-02-01 21:11:56.517000,58805,1.55
1.223091126,2024-02-01 21:12:56.500000,48756,7.8
1.223091126,2024-02-01 21:12:56.500000,1141,4.7
1.223091126,2024-02-01 21:12:56.500000,58805,1.5
1.223091126,2024-02-01 21:13:56.516000,48756,7.6
1.223091126,2024-02-01 21:13:56.516000,1141,5.3
1.223091126,2024-02-01 21:13:56.516000,58805,1.46
1.223091126,2024-02-01 21:14:56.518000,48756,9.4
1.223091126,2024-02-01 21:14:56.518000,1141,5.6
1.223091126,2024-02-01 21:14:56.518000,58805,1.38
1.223091126,2024-02-01 21:15:56.480000,48756,8.6
1.223091126,2024-02-01 21:15:56.480000,1141,6.2
1.223091126,2024-02-01 21:16:56.544000,48756,10.0
1.223091126,2024-02-01 21:16:56.544000,1141,7.2
1.223091126,2024-02-01 21:16:56.544000,58805,1.32
1.223091126,2024-02-01 21:17:56.476000,48756,9.2
1.223091126,2024-02-01 21:17:56.476000,1141,7.4
1.223091126,2024-02-01 21:18:56.524000,48756,10.0
1.223091126,2024-02-01 21:18:56.524000,1141,6.4
1.223091126,2024-02-01 21:18:56.524000,58805,1.35
1.223091126,2024-02-01 21:19:56.502000,48756,10.5
1.223091126,2024-02-01 21:19:56.502000,1141,7.2
1.223091126,2024-02-01 21:19:56.502000,58805,1.3
1.223091126,2024-02-01 21:20:56.472000,48756,13.5
1.223091126,2024-02-01 21:20:56.472000,1141,7.0
1.223091126,2024-02-01 21:20:56.472000,58805,1.26
1.223091126,2024-02-01 21:21:56.506000,48756,17.0
1.223091126,2024-02-01 21:21:56.506000,1141,8.6
1.223091126,2024-02-01 21:21:56.506000,58805,1.22
1.223091126,2024-02-01 21:22:56.486000,48756,19.0
1.223091126,2024-02-01 21:22:56.486000,1141,12.5
1.223091126,2024-02-01 21:22:56.486000,58805,1.15
1.223091126,2024-02-01 21:23:56.487000,48756,26.0
1.223091126,2024-02-01 21:23:56.487000,1141,14.0
1.223091126,2024-02-01 21:23:56.487000,58805,1.13
1.223091126,2024-02-01 21:24:56.518000,48756,30.0
1.223091126,2024-02-01 21:24:56.518000,1141,22.0
1.223091126,2024-02-01 21:24:56.518000,58805,1.07
1.223091126,2024-02-01 21:25:56.490000,48756,50.0
1.223091126,2024-02-01 21:25:56.490000,1141,23.0
1.223091126,2024-02-01 21:25:56.490000,58805,1.05
1.223091126,2024-02-01 21:26:53.177000,48756,70.0
1.223091126,2024-02-01 21:26:53.177000,1141,32.0
1.223091126,2024-02-01 21:26:53.177000,58805,1.04
Ok, it seems like "pt" might indicate a unix timestamp and we seem to use it to produce "publishTime". Assuming that is correct and the rest of my guesses are also correct then you can read the rows of json row by row and pick out the results.
Given:
data = """
{"op":"mcm","clk":"10414445718","pt":1704314685202,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"OPEN","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"GMT","openDate":"2024-02-01T19:30:00.000Z","version":5663400343,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
{"op":"mcm","clk":"10422905409","pt":1704464572326,"mc":[{"id":"1.223091126","rc":[{"ltp":2.28,"id":48756},{"ltp":3.3,"id":1141}]}]}
{"op":"mcm","clk":"10425186776","pt":1704489481069,"mc":[{"id":"1.223091126","rc":[{"ltp":2.16,"id":48756}]}]}
{"op":"mcm","clk":"10432388950","pt":1704570330490,"mc":[{"id":"1.223091126","rc":[{"ltp":2.22,"id":48756}]}]}
{"op":"mcm","clk":"10435187755","pt":1704625091119,"mc":[{"id":"1.223091126","rc":[{"ltp":2.26,"id":48756}]}]}
{"op":"mcm","clk":"10437449719","pt":1704643845497,"mc":[{"id":"1.223091126","rc":[{"ltp":2.38,"id":48756}]}]}
{"op":"mcm","clk":"10442281047","pt":1704720154240,"mc":[{"id":"1.223091126","rc":[{"ltp":3.7,"id":58805}]}]}
{"op":"mcm","clk":"10443741528","pt":1704747459225,"mc":[{"id":"1.223091126","rc":[{"ltp":2.26,"id":48756},{"ltp":3.4,"id":1141}]}]}
{"op":"mcm","clk":"10444017555","pt":1704753820826,"mc":[{"id":"1.223091126","rc":[{"ltp":2.24,"id":48756}]}]}
{"op":"mcm","clk":"10445453091","pt":1704782335460,"mc":[{"id":"1.223091126","rc":[{"ltp":2.26,"id":48756}]}]}
{"op":"mcm","clk":"10446022742","pt":1704792595601,"mc":[{"id":"1.223091126","rc":[{"ltp":4.0,"id":58805}]}]}
{"op":"mcm","clk":"10446476255","pt":1704800674197,"mc":[{"id":"1.223091126","rc":[{"ltp":2.28,"id":48756}]}]}
{"op":"mcm","clk":"10447114386","pt":1704811255024,"mc":[{"id":"1.223091126","rc":[{"ltp":3.7,"id":58805},{"ltp":2.56,"id":48756},{"ltp":3.05,"id":1141}]}]}
{"op":"mcm","clk":"10447122760","pt":1704811372095,"mc":[{"id":"1.223091126","rc":[{"ltp":2.52,"id":48756}]}]}
{"op":"mcm","clk":"10447235920","pt":1704812793414,"mc":[{"id":"1.223091126","rc":[{"ltp":2.48,"id":48756}]}]}
{"op":"mcm","clk":"10447847933","pt":1704820144554,"mc":[{"id":"1.223091126","rc":[{"ltp":2.66,"id":48756}]}]}
{"op":"mcm","clk":"10454483898","pt":1704915831409,"mc":[{"id":"1.223091126","rc":[{"ltp":2.48,"id":48756}]}]}
{"op":"mcm","clk":"10458202960","pt":1704972759939,"mc":[{"id":"1.223091126","rc":[{"ltp":2.64,"id":48756}]}]}
{"op":"mcm","clk":"10477063575","pt":1705176328375,"mc":[{"id":"1.223091126","rc":[{"ltp":3.0,"id":1141}]}]}
{"op":"mcm","clk":"10477573853","pt":1705180907388,"mc":[{"id":"1.223091126","rc":[{"ltp":2.54,"id":48756}]}]}
{"op":"mcm","clk":"10478235475","pt":1705189060371,"mc":[{"id":"1.223091126","rc":[{"ltp":2.46,"id":48756}]}]}
{"op":"mcm","clk":"10479072293","pt":1705199331450,"mc":[{"id":"1.223091126","rc":[{"ltp":2.98,"id":1141}]}]}
{"op":"mcm","clk":"10480774727","pt":1705222843519,"mc":[{"id":"1.223091126","rc":[{"ltp":2.52,"id":48756}]}]}
{"op":"mcm","clk":"10486319404","pt":1705270561035,"mc":[{"id":"1.223091126","rc":[{"ltp":3.8,"id":58805}]}]}
{"op":"mcm","clk":"10486415077","pt":1705272213348,"mc":[{"id":"1.223091126","rc":[{"ltp":2.48,"id":48756}]}]}
{"op":"mcm","clk":"10494636837","pt":1705397335431,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-01-16T09:30:03.000Z","suspendTime":"2024-01-16T09:30:03.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"OPEN","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe/London","openDate":"2024-01-16T09:30:03.000Z","version":5682014978,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
{"op":"mcm","clk":"10494644637","pt":1705397444854,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-01-16T09:30:03.000Z","suspendTime":"2024-01-16T09:30:03.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"SUSPENDED","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe/London","openDate":"2024-01-16T09:30:03.000Z","version":5682018825,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
{"op":"mcm","clk":"10494742371","pt":1705398656173,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"SUSPENDED","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe/London","openDate":"2024-02-01T19:30:00.000Z","version":5682038859,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
{"op":"mcm","clk":"10494746225","pt":1705398710970,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":0,"status":"OPEN","runners":[{"status":"ACTIVE","sortPriority":1,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe/London","openDate":"2024-02-01T19:30:00.000Z","version":5682039132,"name":"Match Odds","eventName":"West Ham v Bournemouth"},"rc":[{"ltp":2.46,"id":48756},{"ltp":3.05,"id":1141}]}]}
{"op":"mcm","clk":"10600341058","pt":1706821796486,"mc":[{"id":"1.223091126","rc":[{"ltp":1.58,"id":58805},{"ltp":6.6,"id":48756},{"ltp":4.5,"id":1141}]}]}
{"op":"mcm","clk":"10600345889","pt":1706821856460,"mc":[{"id":"1.223091126","rc":[{"ltp":1.59,"id":58805},{"ltp":5.9,"id":48756},{"ltp":5.1,"id":1141}]}]}
{"op":"mcm","clk":"10600351148","pt":1706821916517,"mc":[{"id":"1.223091126","rc":[{"ltp":1.55,"id":58805},{"ltp":7.0,"id":48756},{"ltp":4.5,"id":1141}]}]}
{"op":"mcm","clk":"10600356640","pt":1706821976500,"mc":[{"id":"1.223091126","rc":[{"ltp":1.5,"id":58805},{"ltp":7.8,"id":48756},{"ltp":4.7,"id":1141}]}]}
{"op":"mcm","clk":"10600361459","pt":1706822036516,"mc":[{"id":"1.223091126","rc":[{"ltp":1.46,"id":58805},{"ltp":7.6,"id":48756},{"ltp":5.3,"id":1141}]}]}
{"op":"mcm","clk":"10600366005","pt":1706822096518,"mc":[{"id":"1.223091126","rc":[{"ltp":1.38,"id":58805},{"ltp":9.4,"id":48756},{"ltp":5.6,"id":1141}]}]}
{"op":"mcm","clk":"10600370890","pt":1706822156480,"mc":[{"id":"1.223091126","rc":[{"ltp":8.6,"id":48756},{"ltp":6.2,"id":1141}]}]}
{"op":"mcm","clk":"10600375997","pt":1706822216544,"mc":[{"id":"1.223091126","rc":[{"ltp":1.32,"id":58805},{"ltp":10.0,"id":48756},{"ltp":7.2,"id":1141}]}]}
{"op":"mcm","clk":"10600380511","pt":1706822276476,"mc":[{"id":"1.223091126","rc":[{"ltp":9.2,"id":48756},{"ltp":7.4,"id":1141}]}]}
{"op":"mcm","clk":"10600384714","pt":1706822336524,"mc":[{"id":"1.223091126","rc":[{"ltp":1.35,"id":58805},{"ltp":10.0,"id":48756},{"ltp":6.4,"id":1141}]}]}
{"op":"mcm","clk":"10600389208","pt":1706822396502,"mc":[{"id":"1.223091126","rc":[{"ltp":1.3,"id":58805},{"ltp":10.5,"id":48756},{"ltp":7.2,"id":1141}]}]}
{"op":"mcm","clk":"10600393788","pt":1706822456472,"mc":[{"id":"1.223091126","rc":[{"ltp":1.26,"id":58805},{"ltp":13.5,"id":48756},{"ltp":7.0,"id":1141}]}]}
{"op":"mcm","clk":"10600397983","pt":1706822516506,"mc":[{"id":"1.223091126","rc":[{"ltp":1.22,"id":58805},{"ltp":17.0,"id":48756},{"ltp":8.6,"id":1141}]}]}
{"op":"mcm","clk":"10600401728","pt":1706822576486,"mc":[{"id":"1.223091126","rc":[{"ltp":1.15,"id":58805},{"ltp":19.0,"id":48756},{"ltp":12.5,"id":1141}]}]}
{"op":"mcm","clk":"10600405462","pt":1706822636487,"mc":[{"id":"1.223091126","rc":[{"ltp":1.13,"id":58805},{"ltp":26.0,"id":48756},{"ltp":14.0,"id":1141}]}]}
{"op":"mcm","clk":"10600408925","pt":1706822696518,"mc":[{"id":"1.223091126","rc":[{"ltp":1.07,"id":58805},{"ltp":30.0,"id":48756},{"ltp":22.0,"id":1141}]}]}
{"op":"mcm","clk":"10600412523","pt":1706822756490,"mc":[{"id":"1.223091126","rc":[{"ltp":1.05,"id":58805},{"ltp":50.0,"id":48756},{"ltp":23.0,"id":1141}]}]}
{"op":"mcm","clk":"10600416101","pt":1706822813177,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":true,"complete":true,"inPlay":true,"crossMatching":true,"runnersVoidable":false,"numberOfActiveRunners":3,"betDelay":5,"status":"SUSPENDED","runners":[{"status":"ACTIVE","sortPriority":1,"bsp":2.54,"id":48756,"name":"West Ham"},{"status":"ACTIVE","sortPriority":2,"bsp":2.92,"id":1141,"name":"Bournemouth"},{"status":"ACTIVE","sortPriority":3,"bsp":3.8,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"GMT","openDate":"2024-02-01T19:30:00.000Z","version":5709608432,"name":"Match Odds","eventName":"West Ham v Bournemouth"},"rc":[{"ltp":1.04,"id":58805},{"ltp":70.0,"id":48756},{"ltp":32.0,"id":1141}]}]}
{"op":"mcm","clk":"10600428678","pt":1706823040197,"mc":[{"id":"1.223091126","marketDefinition":{"bspMarket":true,"turnInPlayEnabled":true,"persistenceEnabled":true,"marketBaseRate":5.0,"eventId":"32908106","eventTypeId":"1","numberOfWinners":1,"bettingType":"ODDS","marketType":"MATCH_ODDS","marketTime":"2024-02-01T19:30:00.000Z","suspendTime":"2024-02-01T19:30:00.000Z","bspReconciled":true,"complete":true,"inPlay":true,"crossMatching":false,"runnersVoidable":false,"numberOfActiveRunners":0,"betDelay":5,"status":"CLOSED","settledTime":"2024-02-01T21:27:54.000Z","runners":[{"status":"LOSER","sortPriority":1,"bsp":2.54,"id":48756,"name":"West Ham"},{"status":"LOSER","sortPriority":2,"bsp":2.92,"id":1141,"name":"Bournemouth"},{"status":"WINNER","sortPriority":3,"bsp":3.8,"id":58805,"name":"The Draw"}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"GMT","openDate":"2024-02-01T19:30:00.000Z","version":5709611525,"name":"Match Odds","eventName":"West Ham v Bournemouth"}}]}
""".strip()
Then this code:
import csv
import json
import datetime
import io
with io.StringIO(data) as file_in: ## simulate open()
with open("results.csv", "w", encoding="utf-8", newline="") as file_out:
writer = csv.writer(file_out)
writer.writerow(["marketId","publishTime","selection_selectionId","selection_lastPriceTraded"])
for row in file_in:
row = json.loads(row)
publishTime = float(row["pt"]) / 1000
publishTime = str(datetime.datetime.fromtimestamp(publishTime))
for market in row["mc"]:
marketId = market["id"]
for runner in market.get("marketDefinition", {}).get("runners", []):
writer.writerow([marketId, publishTime, runner["id"], None])
for item in market.get("rc", []):
writer.writerow([marketId, publishTime, item["id"], item["ltp"]])
Will give you a file:
marketId,publishTime,selection_selectionId,selection_lastPriceTraded
1.223091126,2024-01-03 15:44:45.202000,48756,
1.223091126,2024-01-03 15:44:45.202000,1141,
1.223091126,2024-01-03 15:44:45.202000,58805,
1.223091126,2024-01-05 09:22:52.326000,48756,2.28
1.223091126,2024-01-05 09:22:52.326000,1141,3.3
1.223091126,2024-01-05 16:18:01.069000,48756,2.16
1.223091126,2024-01-06 14:45:30.490000,48756,2.22
1.223091126,2024-01-07 05:58:11.119000,48756,2.26
1.223091126,2024-01-07 11:10:45.497000,48756,2.38
1.223091126,2024-01-08 08:22:34.240000,58805,3.7
1.223091126,2024-01-08 15:57:39.225000,48756,2.26
1.223091126,2024-01-08 15:57:39.225000,1141,3.4
1.223091126,2024-01-08 17:43:40.826000,48756,2.24
1.223091126,2024-01-09 01:38:55.460000,48756,2.26
1.223091126,2024-01-09 04:29:55.601000,58805,4.0
1.223091126,2024-01-09 06:44:34.197000,48756,2.28
1.223091126,2024-01-09 09:40:55.024000,58805,3.7
1.223091126,2024-01-09 09:40:55.024000,48756,2.56
1.223091126,2024-01-09 09:40:55.024000,1141,3.05
1.223091126,2024-01-09 09:42:52.095000,48756,2.52
1.223091126,2024-01-09 10:06:33.414000,48756,2.48
1.223091126,2024-01-09 12:09:04.554000,48756,2.66
1.223091126,2024-01-10 14:43:51.409000,48756,2.48
1.223091126,2024-01-11 06:32:39.939000,48756,2.64
1.223091126,2024-01-13 15:05:28.375000,1141,3.0
1.223091126,2024-01-13 16:21:47.388000,48756,2.54
1.223091126,2024-01-13 18:37:40.371000,48756,2.46
1.223091126,2024-01-13 21:28:51.450000,1141,2.98
1.223091126,2024-01-14 04:00:43.519000,48756,2.52
1.223091126,2024-01-14 17:16:01.035000,58805,3.8
1.223091126,2024-01-14 17:43:33.348000,48756,2.48
1.223091126,2024-01-16 04:28:55.431000,48756,
1.223091126,2024-01-16 04:28:55.431000,1141,
1.223091126,2024-01-16 04:28:55.431000,58805,
1.223091126,2024-01-16 04:30:44.854000,48756,
1.223091126,2024-01-16 04:30:44.854000,1141,
1.223091126,2024-01-16 04:30:44.854000,58805,
1.223091126,2024-01-16 04:50:56.173000,48756,
1.223091126,2024-01-16 04:50:56.173000,1141,
1.223091126,2024-01-16 04:50:56.173000,58805,
1.223091126,2024-01-16 04:51:50.970000,48756,
1.223091126,2024-01-16 04:51:50.970000,1141,
1.223091126,2024-01-16 04:51:50.970000,58805,
1.223091126,2024-01-16 04:51:50.970000,48756,2.46
1.223091126,2024-01-16 04:51:50.970000,1141,3.05
1.223091126,2024-02-01 16:09:56.486000,58805,1.58
1.223091126,2024-02-01 16:09:56.486000,48756,6.6
1.223091126,2024-02-01 16:09:56.486000,1141,4.5
1.223091126,2024-02-01 16:10:56.460000,58805,1.59
1.223091126,2024-02-01 16:10:56.460000,48756,5.9
1.223091126,2024-02-01 16:10:56.460000,1141,5.1
1.223091126,2024-02-01 16:11:56.517000,58805,1.55
1.223091126,2024-02-01 16:11:56.517000,48756,7.0
1.223091126,2024-02-01 16:11:56.517000,1141,4.5
1.223091126,2024-02-01 16:12:56.500000,58805,1.5
1.223091126,2024-02-01 16:12:56.500000,48756,7.8
1.223091126,2024-02-01 16:12:56.500000,1141,4.7
1.223091126,2024-02-01 16:13:56.516000,58805,1.46
1.223091126,2024-02-01 16:13:56.516000,48756,7.6
1.223091126,2024-02-01 16:13:56.516000,1141,5.3
1.223091126,2024-02-01 16:14:56.518000,58805,1.38
1.223091126,2024-02-01 16:14:56.518000,48756,9.4
1.223091126,2024-02-01 16:14:56.518000,1141,5.6
1.223091126,2024-02-01 16:15:56.480000,48756,8.6
1.223091126,2024-02-01 16:15:56.480000,1141,6.2
1.223091126,2024-02-01 16:16:56.544000,58805,1.32
1.223091126,2024-02-01 16:16:56.544000,48756,10.0
1.223091126,2024-02-01 16:16:56.544000,1141,7.2
1.223091126,2024-02-01 16:17:56.476000,48756,9.2
1.223091126,2024-02-01 16:17:56.476000,1141,7.4
1.223091126,2024-02-01 16:18:56.524000,58805,1.35
1.223091126,2024-02-01 16:18:56.524000,48756,10.0
1.223091126,2024-02-01 16:18:56.524000,1141,6.4
1.223091126,2024-02-01 16:19:56.502000,58805,1.3
1.223091126,2024-02-01 16:19:56.502000,48756,10.5
1.223091126,2024-02-01 16:19:56.502000,1141,7.2
1.223091126,2024-02-01 16:20:56.472000,58805,1.26
1.223091126,2024-02-01 16:20:56.472000,48756,13.5
1.223091126,2024-02-01 16:20:56.472000,1141,7.0
1.223091126,2024-02-01 16:21:56.506000,58805,1.22
1.223091126,2024-02-01 16:21:56.506000,48756,17.0
1.223091126,2024-02-01 16:21:56.506000,1141,8.6
1.223091126,2024-02-01 16:22:56.486000,58805,1.15
1.223091126,2024-02-01 16:22:56.486000,48756,19.0
1.223091126,2024-02-01 16:22:56.486000,1141,12.5
1.223091126,2024-02-01 16:23:56.487000,58805,1.13
1.223091126,2024-02-01 16:23:56.487000,48756,26.0
1.223091126,2024-02-01 16:23:56.487000,1141,14.0
1.223091126,2024-02-01 16:24:56.518000,58805,1.07
1.223091126,2024-02-01 16:24:56.518000,48756,30.0
1.223091126,2024-02-01 16:24:56.518000,1141,22.0
1.223091126,2024-02-01 16:25:56.490000,58805,1.05
1.223091126,2024-02-01 16:25:56.490000,48756,50.0
1.223091126,2024-02-01 16:25:56.490000,1141,23.0
1.223091126,2024-02-01 16:26:53.177000,48756,
1.223091126,2024-02-01 16:26:53.177000,1141,
1.223091126,2024-02-01 16:26:53.177000,58805,
1.223091126,2024-02-01 16:26:53.177000,58805,1.04
1.223091126,2024-02-01 16:26:53.177000,48756,70.0
1.223091126,2024-02-01 16:26:53.177000,1141,32.0
1.223091126,2024-02-01 16:30:40.197000,48756,
1.223091126,2024-02-01 16:30:40.197000,1141,
1.223091126,2024-02-01 16:30:40.197000,58805,