Untitled

 avatar
unknown
plain_text
a year ago
2.3 kB
14
Indexable
trades = await asyncio.gather(*trades)
        trades = list(filter(lambda x: x['symbol'] != None, trades))
        total_volume = {}
        total_edge = {}
        total_dex = {}
        total_gex = {}
        otm_total_flow = {}
        total_flow = {}
        
        for contract in trades:
            for time, volume in contract['volume'].items():
                key = time.strftime("%Y-%m-%d %H:%M:%S")
                if key in total_volume:
                    total_volume[key] += volume
                else:
                    total_volume[key] = volume
                    
            for time, edge in contract['net_edge'].items():
                key = time.strftime("%Y-%m-%d %H:%M:%S")
                if key in total_edge:
                    total_edge[key] += round(edge, 4)
                else:
                    total_edge[key] = round(edge, 4)
                    
            for time, dex in contract['dex'].items():
                key = time.strftime("%Y-%m-%d %H:%M:%S")
                if key in total_dex:
                    total_dex[key] += dex
                else:
                    total_dex[key] = dex
            
            for time, gex in contract['gex'].items():
                key = time.strftime("%Y-%m-%d %H:%M:%S")
                if key in total_gex:
                    total_gex[key] += gex
                else:
                    total_gex[key] = gex
                    
            for time, flow in contract['flow'].items():
                key = time.strftime("%Y-%m-%d %H:%M:%S")
                if key in total_flow:
                    total_flow[key] += flow
                else:
                    total_flow[key] = flow
        
        net_values.set_index('timestamp', inplace=True)
        net_values['timestamp'] = net_values.index
        net_values['cumulative_edge'] = net_values['edge'].cumsum()
        net_values['flow'] = pd.DataFrame(total_flow.values(), columns=['flow'])
        net_values['dex'] = pd.DataFrame(total_dex.values(), columns=['dex'])
        
        return {'total_volume': total_volume, 'total_edge': total_edge, 'total_dex': total_dex, 'total_gex': total_gex, 'otm_total_flow': otm_total_flow, 'total_flow': total_flow, 'underlying': underlying_prices, }
Editor is loading...
Leave a Comment