iT邦幫忙

2021 iThome 鐵人賽

DAY 7
0
  • 取得信用帳戶資訊
# futopt_account - 期貨,選擇權帳號
account_margin = api.get_account_margin(account=api.futopt_account)
df_margin = pd.DataFrame(account_margin.data())
df_margin

參數:
currency: {NTX, USX, NTD, USD, HKD, EUR, JPY, GBP}
- NTX: 約當台幣
- USX: 約當美金
- NTD: 新台幣
- USD: 美金
- HKD: 港幣
- EUR: 歐元
- JPY: 日幣
- GBP: 英鎊
margin_type: { 1, 2 }
- 1: 即時
- 2: 風險

  • 取得未沖銷部位
positions = api.get_account_openposition(query_type='1', account=api.futopt_account)
df_positions = pd.DataFrame(positions.data())
df_positions

參數:
product_type: { 0, 1, 2, 3 }
- 0: all
- 1: 期貨
- 2: 選擇權
- 3: 美金計價
query_type: { 0, 1 }
- 0: detail
- 1: summary

  • 取得平倉損益
st_date = (date.today() - timedelta(days=60)).strftime('%Y%m%d')
settle_profitloss = api.get_account_settle_profitloss(summary='Y', start_date=st_date)
settle_profitloss

*參數:
product_type: { 0, 1, 2 }
- 0: all (預設)
- 1: 期貨
- 2: 選擇權
summary: { 'Y', 'N'}
- Y: summary
- N: detail
start_date: 日期格式 %Y%m%d, example: 20210622
currenct: 幣別
account: api.futopt_account

  • 損益
api.list_profit_loss(api.stock_account, '2021-09-01', '2021-09-22')

參數:
account: api.stock_account
begin_date: 統計開始時間
end_date: 統計結束時間
cb: callback 程式

回傳欄位

id (int): use to find detail.
code (str): 股票代碼
seqno (str): seqno no.
dseq (str): seqno no.
quantity (int): 數量
price (float): 價格
pnl (float): profit and loss 損益
pr_ratio (float): profit rate 損益率
cond (StockOrderCond): {Cash, Netting, MarginTrading, ShortSelling} { 現金,餘額交割, 融資,融券 }
date (str): trade date. 交易日期

  • 損益明細
api.list_profit_loss_detail(api.stock_account, 2)

*參數:

  • account: api.stock_account
  • detail_id: api.list_profit_loss 查出來的 id*

回傳欄位

date (str): trade date. 交易日期
cond (StockOrderCond): {Cash, Netting, MarginTrading, ShortSelling}
code (str): contract id. 股票代碼
quantity (int): quantity. 數量
price (float): price. 價格
cost (int): cost of price. 交易金額
dseq (str): detail seqno no.
rep_margintrading_amt (int): repay amount of margin trading.
rep_collateral (int): repay collateral.
rep_margin (int): repay margin.
fee (int): fee. 手續費
interest (int): interest.
tax (int): trading tax. 交易稅
shortselling_fee (int): fee of short selling.
currency (str): {NTD, USD, HKD, EUR, CAD, BAS} 幣別

  • 交割金額
settlement = api.list_settlements(api.stock_account)
df = pd.DataFrame(settlement)
df

回傳欄位

t_money (float): T settlement 當日交割金額
t1_money (float): T + 1 settlement 次日交割金額
t2_money (float): T + 2 settlement 次2日交割金額
t_day (str): T 交割日期
t1_day (str): T + 1 次日交割日期
t2_day (str): T + 2 次2日交割日期

  • 帳戶餘額
acc_balance = api.account_balance()
df = pd.DataFrame(acc_balance)
df

回傳欄位

acc_balance (float): account balance 帳戶餘額
date (str): query date 查詢日期
errmsg (str): error message 錯誤訊息

今天大概列出幾個和帳務有關的 api,因為本身沒有接觸過期貨選擇權,所以在和期貨有關的 api 可能會有些出入,請大家自行參考


上一篇
基本操作 - 下單
下一篇
基本操作 - 歷史資訊
系列文
永豐金融APIs - 從零開始到放棄!?30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言