- 在示例中,只有一条记录,所以我创建了一个包含多条记录的示例
positions
- 我会使用熊猫来访问所有数据
import pandas as pd
# create dataframe
df = pd.json_normalize(data, 'positions')
# display(df)
market.bid market.delayTime market.epic market.expiry market.high market.instrumentName market.instrumentType market.lotSize market.low market.marketStatus market.netChange market.offer market.percentageChange market.scalingFactor market.streamingPricesAvailable market.updateTime market.updateTimeUTC position.contractSize position.controlledRisk position.createdDate position.createdDateUTC position.currency position.dealId position.dealReference position.direction position.level position.limitLevel position.limitedRiskPremium position.size position.stopLevel position.trailingStep position.trailingStopDistance
0 1719.59 0 - - 1749.95 Sverige30 Cash (100SK) INDICES 100.0 1713.33 TRADEABLE -25.44 1721.09 -1.46 1 True 22:15:16 21:15:16 100.0 False 2020/07/13 23:12:53:000 2020-07-13T21:12:53 USD BUY 1720.74 None None 5.0 None None None
1 1719.59 0 - - 1749.95 Sverige30 Cash (100SK) INDICES 100.0 1713.33 TRADEABLE -25.44 1721.09 -1.46 1 True 22:15:16 21:15:16 100.0 False 2020/07/13 23:12:53:000 2020-07-13T21:12:53 USD BUY 1720.74 None None 5.0 None None None
2 1719.59 0 - - 1749.95 Sverige30 Cash (100SK) INDICES 100.0 1713.33 TRADEABLE -25.44 1721.09 -1.46 1 True 22:15:16 21:15:16 100.0 False 2020/07/13 23:12:53:000 2020-07-13T21:12:53 USD BUY 1720.74 None None 5.0 None None None
3 1719.59 0 - - 1749.95 Sverige30 Cash (100SK) INDICES 100.0 1713.33 TRADEABLE -25.44 1721.09 -1.46 1 True 22:15:16 21:15:16 100.0 False 2020/07/13 23:12:53:000 2020-07-13T21:12:53 USD BUY 1720.74 None None 5.0 None None None
data
有多个记录
data = {
'positions': [{
'market': {
'bid': 1719.59,
'delayTime': 0,
'epic': '-',
'expiry': '-',
'high': 1749.95,
'instrumentName': 'Sverige30 Cash (100SK)',
'instrumentType': 'INDICES',
'lotSize': 100.0,
'low': 1713.33,
'marketStatus': 'TRADEABLE',
'netChange': -25.44,
'offer': 1721.09,
'percentageChange': -1.46,
'scalingFactor': 1,
'streamingPricesAvailable': True,
'updateTime': '22:15:16',
'updateTimeUTC': '21:15:16'
},
'position': {
'contractSize': 100.0,
'controlledRisk': False,
'createdDate': '2020/07/13 23:12:53:000',
'createdDateUTC': '2020-07-13T21:12:53',
'currency': 'USD',
'dealId': '',
'dealReference': '',
'direction': 'BUY',
'level': 1720.74,
'limitLevel': None,
'limitedRiskPremium': None,
'size': 5.0,
'stopLevel': None,
'trailingStep': None,
'trailingStopDistance': None
}
}, {
'market': {
'bid': 1719.59,
'delayTime': 0,
'epic': '-',
'expiry': '-',
'high': 1749.95,
'instrumentName': 'Sverige30 Cash (100SK)',
'instrumentType': 'INDICES',
'lotSize': 100.0,
'low': 1713.33,
'marketStatus': 'TRADEABLE',
'netChange': -25.44,
'offer': 1721.09,
'percentageChange': -1.46,
'scalingFactor': 1,
'streamingPricesAvailable': True,
'updateTime': '22:15:16',
'updateTimeUTC': '21:15:16'
},
'position': {
'contractSize': 100.0,
'controlledRisk': False,
'createdDate': '2020/07/13 23:12:53:000',
'createdDateUTC': '2020-07-13T21:12:53',
'currency': 'USD',
'dealId': '',
'dealReference': '',
'direction': 'BUY',
'level': 1720.74,
'limitLevel': None,
'limitedRiskPremium': None,
'size': 5.0,
'stopLevel': None,
'trailingStep': None,
'trailingStopDistance': None
}
}, {
'market': {
'bid': 1719.59,
'delayTime': 0,
'epic': '-',
'expiry': '-',
'high': 1749.95,
'instrumentName': 'Sverige30 Cash (100SK)',
'instrumentType': 'INDICES',
'lotSize': 100.0,
'low': 1713.33,
'marketStatus': 'TRADEABLE',
'netChange': -25.44,
'offer': 1721.09,
'percentageChange': -1.46,
'scalingFactor': 1,
'streamingPricesAvailable': True,
'updateTime': '22:15:16',
'updateTimeUTC': '21:15:16'
},
'position': {
'contractSize': 100.0,
'controlledRisk': False,
'createdDate': '2020/07/13 23:12:53:000',
'createdDateUTC': '2020-07-13T21:12:53',
'currency': 'USD',
'dealId': '',
'dealReference': '',
'direction': 'BUY',
'level': 1720.74,
'limitLevel': None,
'limitedRiskPremium': None,
'size': 5.0,
'stopLevel': None,
'trailingStep': None,
'trailingStopDistance': None
}
}, {
'market': {
'bid': 1719.59,
'delayTime': 0,
'epic': '-',
'expiry': '-',
'high': 1749.95,
'instrumentName': 'Sverige30 Cash (100SK)',
'instrumentType': 'INDICES',
'lotSize': 100.0,
'low': 1713.33,
'marketStatus': 'TRADEABLE',
'netChange': -25.44,
'offer': 1721.09,
'percentageChange': -1.46,
'scalingFactor': 1,
'streamingPricesAvailable': True,
'updateTime': '22:15:16',
'updateTimeUTC': '21:15:16'
},
'position': {
'contractSize': 100.0,
'controlledRisk': False,
'createdDate': '2020/07/13 23:12:53:000',
'createdDateUTC': '2020-07-13T21:12:53',
'currency': 'USD',
'dealId': '',
'dealReference': '',
'direction': 'BUY',
'level': 1720.74,
'limitLevel': None,
'limitedRiskPremium': None,
'size': 5.0,
'stopLevel': None,
'trailingStep': None,
'trailingStopDistance': None
}
}
]
}