-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
credentials.py
71 lines (66 loc) · 2.77 KB
/
credentials.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Create credentials.json under $HOME/.kabuto.
Write and fill the information in the following format:
* DONT UPLOAD/SHARE THE CREDENTIAL FILE WITH ANYONE FOR ANY REASON
* Do `chmod 600 $HOME/.kabuto/credentials.json` to make your file private
* KABUS_API_ONETIME_TOKEN is optional (but the key should be there)
{
"KABUCOM_PASSWORD": "",
"KABUSAPI_HOST": "xxx.xxx.xxx.xxx",
"KABUSAPI_HOST_LIVE": "xxx.xxx.xxx.xxx:port/live",
"KABUSAPI_HOST_TEST": "xxx.xxx.xxx.xxx:port/test",
"KABUSAPI_PASSWORD_LIVE": "",
"KABUSAPI_PASSWORD_TEST": "",
"KABUSAPI_ONETIME_TOKEN": ""
}
See the comment in class Credential for mode detail on each property.
"""
import json
import os
from dataclasses import dataclass
@dataclass
class Credential:
# Password you use to enter kabu.com
kabucom_password: str
# Local IP address with port of the Windows PC running kabu STATION app.
host_ipaddr: str
# IP address with port and live/test domain (e.g., ipaddr/live), as defined by NGINX on Windows
# NOTE: This test API is not really "tested" much on our project yet...
host_live: str
host_test: str
# Password you set on kabu STATION app (the API setting panel).
# These are required to acquire the onetime access token.
password_live: str
password_test: str
# This is not used for bot.
# If you access to kabu STATION without using bot, say testing some function,
# get onetime token in some way and write it in the JSON.
onetime_token: str
try:
with open(f'{os.environ["HOME"]}/.kabuto/credentials.json') as f:
# CREDENTIAL_RAW can be used to hold any credential information even unrelated to the bot,
# for example, the API credential of a service you use for fundamental analysis etc.
# However, there are some properties necessary to be defined for KABUTO_CREDENTIAL.
CREDENTIAL_RAW = json.load(f)
KABUTO_CREDENTIAL = Credential(
kabucom_password=CREDENTIAL_RAW['KABUCOM_PASSWORD'],
host_ipaddr=CREDENTIAL_RAW['KABUSAPI_HOST'],
host_live=CREDENTIAL_RAW['KABUSAPI_HOST_LIVE'],
host_test=CREDENTIAL_RAW['KABUSAPI_HOST_TEST'],
password_live=CREDENTIAL_RAW['KABUSAPI_PASSWORD_LIVE'],
password_test=CREDENTIAL_RAW['KABUSAPI_PASSWORD_TEST'],
onetime_token=CREDENTIAL_RAW['KABUSAPI_ONETIME_TOKEN']
)
except FileNotFoundError:
print('ERROR: Credential file for kabu STATION API not found!')
print('Create $HOME/.kabuto/credentials.json and fill the information in the following format.')
print("""{
"KABUCOM_PASSWORD": "",
"KABUSAPI_HOST": "xxx.xxx.xxx.xxx",
"KABUSAPI_HOST_LIVE": "xxx.xxx.xxx.xxx:port/live",
"KABUSAPI_HOST_TEST": "xxx.xxx.xxx.xxx:port/live",
"KABUSAPI_PASSWORD_LIVE": "",
"KABUSAPI_PASSWORD_TEST": "",
"KABUSAPI_ONETIME_TOKEN": "",
}
""")