order_info.py
import urllib.request
import json
import pprint
import unregister_watch
import settings
def orders_info():
url = 'http://localhost:' + settings.port + '/kabusapi/orders'
params = { 'product': 0, 'id': settings.entryOrderID}
req = urllib.request.Request('{}?{}'.format(url, urllib.parse.urlencode(params)), method='GET')
req.add_header('Content-Type', 'application/json')
req.add_header('X-API-KEY', settings.token)
try:
print('###order_info')
with urllib.request.urlopen(req) as res:
print(res.status, res.reason)
for header in res.getheaders():
print(header)
print()
content = json.loads(res.read())
pprint.pprint(content)
# 注文情報を取得
firstOrder = content[len(content)-1]
print(firstOrder['Details'])
firstOrderDetails = firstOrder['Details']
firstDetailOrder = firstOrderDetails[len(firstOrderDetails)-1]
settings.orderPrice = firstDetailOrder['Price']
#監視銘柄登録解除
unregister_watch.unregister_watch()
except urllib.error.HTTPError as e:
print(e)
content = json.loads(e.read())
pprint.pprint(content)
except Exception as e:
print(e)
if __name__ == "__main__":
import sys
orders_info()
これも以前書いた処理の流用です。エントリした段階ではまだ注文は1つしかないので、取得した配列から最初の1つを取って、”Price”を調べています。
コメント