So I have a stock data that I am trying to calculate the difference of the volume between best ask and best bid price for each time moment.
The time moments are 0-1-2-3-4 shown in both Bid and Ask. And first element in those sublists of 0-1-2-3-4 are the best price with its volume (Second element is the second best price with its volume, third is third and goes on..)
{"Ask":
{"0":[[10.13,30500],[10.14,106456],[10.15,53772],[10.16,58104],[10.17,45589]],
"1":[[10.14,106976],[10.15,53782],[10.16,58104],[10.17,45899],[10.18,31521]],
"2":[[10.14,106986],[10.15,53652],[10.16,58504],[10.17,45589],[10.18,37821]],
"3":[[10.14,106996],[10.15,57872],[10.16,58104],[10.17,45789],[10.18,89721]],
"4":[[10.14,106936],[10.15,53982],[10.16,58154],[10.17,4495],[10.18,2521]]
}
,
"Bid":{
"0":[[10.12,198807],[10.11,1110],[10.1,42110],[10.09,84381],[10.08,98178]],
"1":[[10.13,13500],[10.12,198807],[10.11,1110],[10.1,42110],[10.09,84381]],
"2":[[10.13,13500],[10.12,198807],[10.11,1110],[10.1,42110],[10.09,84381]],
"3":[[10.13,13500],[10.12,198807],[10.11,1110],[10.1,42110],[10.09,84381]],
"4":[[10.13,13500],[10.12,198807],[10.11,1110],[10.1,42110],[10.09,84381]]
}
}
I need help calculating
1- The Volume difference between best ask price and best bid price for each time moment
2- The price difference between best ask price and best bid price for each moment.
(First elements like 10.xx decimals are price, Second elements are Volume)
I have read the json formula and trying to print best ask price to get started but failing it.
import json
with open(r"C:\Users\User\Desktop\FILE.json") as BOB:
data=json.load(BOB)
for x in data['Bid']['0'][0][0]:
print(x)
'float' object is not iterable