帳戶操作
帳戶列表
用戶登入後,透過帳戶列表取得對應帳戶,並對帳戶進行操作
python
from eskmo import api
api.logger.show = True
@api.start
def main():
user = api.login(userId="A123456789", password="************")
accounts = user.accounts
print(accounts)
if __name__ == "__main__":
main()
帳戶設定
用戶預設的帳戶 user.account
為證券帳戶
透過 set_main_account
可修改為其他帳戶(例如期貨帳戶)
python
from eskmo import api
api.logger.show = True
@api.start
def main():
# 預設帳戶
user = api.login(userId="A123456789", password="************")
account = user.account
print(account)
# 修改預設帳戶
user.set_main_account(account.name)
print(user.account)
# 修改帳戶名稱
account_info = ("************", "主帳戶")
user.update_account_name(*account_info)
account: StockAccount = user.accounts["主帳戶"]
if __name__ == "__main__":
main()
取得帳戶 ID
與下單有關的操作可能會需要帳戶 ID,透過用戶可取得所有帳戶 ID:
python
from eskmo import api
api.logger.show = True
@api.start
def main():
user = api.login(userId="A123456789", password="************")
accountIds = user.get_account_ids()
print(accountIds)
if __name__ == "__main__":
main()
或是透過帳戶物件 account.id
取得:
python
api.logger.show = True
@api.start
def main():
user = api.login(userId="A123456789", password="*************")
account = user.account
print(account.id)
if __name__ == "__main__":
main()