明日には暴風域が九州全土を呑み込むのでしょうか?
株どころではない感じなのですが・・・
$ export MTHD=board
$ export CODE=7203
$ py3 ./src/api_get.py 0 |iconv -f Shift_JIS -t UTF-8
200 OK
('Content-Length', '1844')
('Content-Type', 'application/json; charset=utf-8')
('Server', 'Microsoft-HTTPAPI/2.0')
('X-Content-Type-Options', 'nosniff')
('X-XSS-Protection', '1; mode=block')
('X-Frame-Options', 'DENY')
('Content-Security-Policy', "default-src 'none'")
('Access-Control-Allow-Origin', '*')
('Date', 'Sat, 05 Sep 2020 21:36:50 GMT')
('Connection', 'close')
{'AskPrice': 7041.0,
'AskQty': 1700.0,
'AskSign': '0101',
'AskTime': '2020-09-06T15:00:00+09:00',
'BidPrice': 7050.0,
'BidQty': 1000.0,
'BidSign': '0101',
'BidTime': '2020-09-06T15:00:00+09:00',
'Buy1': {'Price': 7041.0,
'Qty': 1700.0,
'Sign': '0101',
'Time': '2020-09-06T15:00:00+09:00'},
'Buy10': {'Price': 7032.0, 'Qty': 800.0},
'Buy2': {'Price': 7040.0, 'Qty': 10300.0},
'Buy3': {'Price': 7039.0, 'Qty': 400.0},
'Buy4': {'Price': 7038.0, 'Qty': 6600.0},
'Buy5': {'Price': 7037.0, 'Qty': 3100.0},
'Buy6': {'Price': 7036.0, 'Qty': 1300.0},
'Buy7': {'Price': 7035.0, 'Qty': 300.0},
'Buy8': {'Price': 7034.0, 'Qty': 8600.0},
'Buy9': {'Price': 7033.0, 'Qty': 1600.0},
'CalcPrice': 7046.0,
'ChangePreviousClose': 55.0,
'ChangePreviousClosePer': 0.79,
'CurrentPrice': 7046.0,
'CurrentPriceChangeStatus': '0061',
'CurrentPriceStatus': 1,
'CurrentPriceTime': '2020-09-06T15:00:00+09:00',
'Exchange': 1,
'ExchangeName': '東証1部',
'HighPrice': 7081.0,
'HighPriceTime': '2020-09-06T11:20:45+09:00',
'LowPrice': 6938.0,
'LowPriceTime': '2020-09-06T09:00:05+09:00',
'MarketOrderBuyQty': 0.0,
'MarketOrderSellQty': 0.0,
'OpeningPrice': 6950.0,
'OpeningPriceTime': '2020-09-06T09:00:00+09:00',
'OverSellQty': 1314100.0,
'PreviousClose': 6991.0,
'PreviousCloseTime': '2020-09-03T00:00:00+09:00',
'Sell1': {'Price': 7050.0,
'Qty': 1000.0,
'Sign': '0101',
'Time': '2020-09-06T15:00:00+09:00'},
'Sell10': {'Price': 7059.0, 'Qty': 2300.0},
'Sell2': {'Price': 7051.0, 'Qty': 8200.0},
'Sell3': {'Price': 7052.0, 'Qty': 500.0},
'Sell4': {'Price': 7053.0, 'Qty': 1600.0},
'Sell5': {'Price': 7054.0, 'Qty': 500.0},
'Sell6': {'Price': 7055.0, 'Qty': 800.0},
'Sell7': {'Price': 7056.0, 'Qty': 300.0},
'Sell8': {'Price': 7057.0, 'Qty': 10600.0},
'Sell9': {'Price': 7058.0, 'Qty': 1000.0},
'Symbol': '7203',
'SymbolName': 'トヨタ自動車',
'TotalMarketValue': 22991080328632.0,
'TradingValue': 28146468100.0,
'TradingVolume': 4002700.0,
'TradingVolumeTime': '2020-09-06T15:00:00+09:00',
'UnderBuyQty': 1040100.0,
'VWAP': 7031.8705}
-------7201-----------
200 OK
('Content-Length', '1883')
('Content-Type', 'application/json; charset=utf-8')
('Server', 'Microsoft-HTTPAPI/2.0')
('X-Content-Type-Options', 'nosniff')
('X-XSS-Protection', '1; mode=block')
('X-Frame-Options', 'DENY')
('Content-Security-Policy', "default-src 'none'")
('Access-Control-Allow-Origin', '*')
('Date', 'Sat, 05 Sep 2020 21:36:50 GMT')
('Connection', 'close')
{'AskPrice': 421.2,
'AskQty': 2000.0,
'AskSign': '0101',
'AskTime': '2020-09-06T15:00:00+09:00',
'BidPrice': 422.0,
'BidQty': 81000.0,
'BidSign': '0101',
'BidTime': '2020-09-06T15:00:00+09:00',
'Buy1': {'Price': 421.2,
'Qty': 2000.0,
'Sign': '0101',
'Time': '2020-09-06T15:00:00+09:00'},
'Buy10': {'Price': 420.3, 'Qty': 2500.0},
'Buy2': {'Price': 421.1, 'Qty': 7000.0},
'Buy3': {'Price': 421.0, 'Qty': 9300.0},
'Buy4': {'Price': 420.9, 'Qty': 12500.0},
'Buy5': {'Price': 420.8, 'Qty': 4400.0},
'Buy6': {'Price': 420.7, 'Qty': 2500.0},
'Buy7': {'Price': 420.6, 'Qty': 14700.0},
'Buy8': {'Price': 420.5, 'Qty': 3400.0},
'Buy9': {'Price': 420.4, 'Qty': 46900.0},
'CalcPrice': 422.0,
'ChangePreviousClose': -3.3,
'ChangePreviousClosePer': -0.78,
'CurrentPrice': 422.0,
'CurrentPriceChangeStatus': '0061',
'CurrentPriceStatus': 1,
'CurrentPriceTime': '2020-09-06T15:00:00+09:00',
'Exchange': 1,
'ExchangeName': '東証1部',
'HighPrice': 422.0,
'HighPriceTime': '2020-09-06T09:04:30+09:00',
'LowPrice': 415.2,
'LowPriceTime': '2020-09-06T09:53:24+09:00',
'MarketOrderBuyQty': 0.0,
'MarketOrderSellQty': 0.0,
'OpeningPrice': 418.0,
'OpeningPriceTime': '2020-09-06T09:00:00+09:00',
'OverSellQty': 4747900.0,
'PreviousClose': 425.3,
'PreviousCloseTime': '2020-09-03T00:00:00+09:00',
'Sell1': {'Price': 422.0,
'Qty': 81000.0,
'Sign': '0101',
'Time': '2020-09-06T15:00:00+09:00'},
'Sell10': {'Price': 423.0, 'Qty': 23900.0},
'Sell2': {'Price': 422.1, 'Qty': 98600.0},
'Sell3': {'Price': 422.2, 'Qty': 10900.0},
'Sell4': {'Price': 422.3, 'Qty': 6000.0},
'Sell5': {'Price': 422.4, 'Qty': 2400.0},
'Sell6': {'Price': 422.5, 'Qty': 1000.0},
'Sell7': {'Price': 422.7, 'Qty': 122800.0},
'Sell8': {'Price': 422.8, 'Qty': 700.0},
'Sell9': {'Price': 422.9, 'Qty': 1000.0},
'Symbol': '7201',
'SymbolName': '日産自動車',
'TotalMarketValue': 1781141777264.0,
'TradingValue': 6475469740.0,
'TradingVolume': 15442100.0,
'TradingVolumeTime': '2020-09-06T15:00:00+09:00',
'UnderBuyQty': 4241400.0,
'VWAP': 419.3387}
-------symbol-----------
200 OK
('Content-Length', '391')
('Content-Type', 'application/json; charset=utf-8')
('Server', 'Microsoft-HTTPAPI/2.0')
('X-Content-Type-Options', 'nosniff')
('X-XSS-Protection', '1; mode=block')
('X-Frame-Options', 'DENY')
('Content-Security-Policy', "default-src 'none'")
('Access-Control-Allow-Origin', '*')
('Date', 'Sat, 05 Sep 2020 21:36:54 GMT')
('Connection', 'close')
{'BisCategory': '3700 ',
'DisplayName': '日産自',
'Exchange': 1,
'ExchangeName': '東証1部',
'FiscalYearEndBasic': 20210331,
'KCMarginBuy': True,
'KCMarginSell': True,
'LowerLimit': 342.0,
'MarginBuy': True,
'MarginSell': True,
'PriceRangeGroup': '10003',
'Symbol': '7201',
'SymbolName': '日産自動車',
'TotalMarketValue': 1781141777264.0,
'TotalStocks': 4220715.0,
'TradingUnit': 100.0,
'UpperLimit': 502.0}
kabu STATION APIテストは続いてます
sampleコード弄ってるだけですが、一応いろいろ調べてclassを使ってます
オブジェクト指向苦手なので悪戦苦闘なのと、まだあまりわかってないままコード書いてる・・・
でもソース晒します
import urllib.request
import json
import pprint
#import sys
import os
#no='0'本番 '1'検証に接続
class APIdata:
def __init__(self, no, code, exch, mthd, apitoken):
self._no = no
self._code = code
self._exch = exch
self._mthd = mthd
self._apitoken = apitoken
self._base = 'http://localhost:1808'
class APIurl(APIdata):
def __str__(self):
if self._mthd == 'board':
return self._base + self._no + '/kabusapi/' + 'board/' + self._code + self._exch
elif self._mthd == 'symbol':
return self._base + self._no + '/kabusapi/' + 'symbol/' + self._code + self._exch
else:
return 'mthd error'
def request(self):
url = str(self)
req = urllib.request.Request(url, method='GET')
req.add_header('Content-Type', 'application/json')
req.add_header('X-API-KEY', self._apitoken)
return req
def reqprint(self):
req = self.request()
try:
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)
except urllib.error.HTTPError as e:
print(e)
content = json.loads(e.read())
pprint.pprint(content)
except Exception as e:
print(e)
#------------------
apitoken = os.environ['TOKEN']
code = os.environ['CODE']
mthd = os.environ['MTHD']
api_url = APIurl('0',code,'@1',mthd,apitoken)
api_url.reqprint()
print('-------7201-----------')
code = '7201'
api_url = APIurl('0',code,'@1',mthd,apitoken)
api_url.reqprint()
print('-------symbol-----------')
mthd = 'symbol'
api_url = APIurl('0',code,'@1',mthd,apitoken)
api_url.reqprint()
このブログは独り言ブログで日記のようなものなので、未完成のコードでも恥も外聞もなく記事にします
完成したらちゃんと纏めるかもしれませんが・・・・
台風次第でトレードもブログも中断するかもしれません
その時は悪しからず・・・
絶対停電するし、電話回線も危ない
2018台風24号で電話回線切れましたので・・・・
トレードより命が大事・・・