###### tags: `BetContruct`, `bc`, `bet construct` # BetContruct封裝 API 使用手冊 V0.2 [toc] ## 帳號狀態 ### 系統建立Session :::info - 在傳送任何指令之前,先需要用Websocket與BC建立session - 建立session的同時傳遞語系(language)給BC,之後BC的以語系回覆內容(國家、聯賽、隊名等等) ::: - 指令 - bcSocket.requestSession(site_id, language) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | site_id | BC賜予我放的站台id | int | yes | | | language | 語系 | string | no | 預設簡中 | - 範例 ```json bcSocket.requestSession(1, "chn"); // 這邊的1 只是因為我仿照參考站台,所以使用1 ``` - 回應 | Field | Description | DataType | Memo | | -------- | -------- | -------- | -------- | | 無 | | | | - 範例 ```json 無 ``` - 重點: - language eng - English, chn - Chinese, zho - Chinese, kor - Korean。其他請參考SwarmApi文件APPENDIX B: LANGUAGE CODES ### 登入 :::info - 需先從我方取得auth_token ::: - 指令 - bcAccountCommand.restoreLogin(userId, authToken) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | userId | 玩家在我方系統的Id | String | yes | | | authToken | 玩家在我方系統的認證token | string | Yes | | - 範例 ```json bcAccountCommand.restoreLogin({ userId: "test15017", authToken: "abcdefg" }); ``` - 回應 | Field | Description | DataType | Memo | | -------- | -------- | -------- | -------- | | 無 | | | | ### 登出 :::info - 登出 ::: - 指令 - bcAccountCommand.logout() - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | 無 | | | | | - 回應 | Field | Description | DataType | Memo | | -------- | -------- | -------- | -------- | | 無 | | | | ### 取得帳戶餘額 :::info - 需先登入 ::: - 指令 - bcAccountCommand.getBalance() - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | 無 | | | | | - 回應 | Field | Description | DataType | Memo | | -------- | -------- | -------- | -------- | | 無 | | | | - 範例 ```json { "code": 0, "rid": "get_balance_3", "data": { "data": { "profile": { "318021537": { "balance": 99999.0, "bonus_balance": 0.0 } } } } } ``` ### 取得體育投注上限 :::info - 需先登入 ::: - 指令 - bcAccountCommand.getClientSportBetLimit(); - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | 無 | | | | | - 回應 | Field | Description | DataType | Memo | | -------- | -------- | -------- | -------- | | 無 | | | | - 範例 ```json {"code":0,"rid":"get_client_sport_bet_limit_3","data":{"result":0,"result_text":null,"details":{"SportMaxDailyBet":null,"SportMaxSingleBet":null,"SportMaxWeeklyBet":null,"SportMaxMonthlyBet":null,"SportMaxRemainingDailyBet":null,"SportMaxRemainingSingleBet":null,"SportMaxRemainingWeeklyBet":null,"SportMaxRemainingMonthlyBet":null}}} ``` ## 訂閱賽事和賠率 ### 取得選單Menu :::info - 訂閱畫面左側漢堡選單: 階層為 運動->區域->聯賽 (顯示賽事數量)。 - 在初次呼叫時就會立刻收到全部數據。之後如有細節變更,就只會收到細節變更的內容。 - 參考畫面: ![](https://i.imgur.com/dag0lvz.png) ::: - 指令 - bcBettingSource.subscribeMenu(sportType) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | sportType | 體育類型 | int | no | 預設為2;0 == Electronic, 1 == Virtual, 2 == General, 4 == Racing, 5 == Fighting | - 範例 ```json bcBettingSource.subscribeMenu(); 或 bcBettingSource.subscribeMenu(2); ``` - 回應 | Field | Description | DataType | Memo | | -------- | -------- | -------- | -------- | | code | 結果代碼 | int | | | rid | request id | string | 可忽視,bcSocket內部會處理 | | subid | subscription id,之後退訂閱時候需要傳遞此id | string | 可忽視,bcSocket內部會處理 | - 範例 ![](https://i.imgur.com/2hQndN7.png) - 重點: - 小標題 內容介紹 ### 取得焦點賽事和主要玩法(主客和) :::info - 訂閱像是焦點賽事和其主要玩法(例如主客和) - 參考畫面: ![](https://i.imgur.com/4PhkPuT.png) ::: - 指令 - bcBettingSource.subscribeDashboardOdds(sportType) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | sportType | 體育類型 | int | no | 預設為2;0 == Electronic, 1 == Virtual, 2 == General, 4 == Racing, 5 == Fighting | - 範例 ```json bcBettingSource.subscribeDashboardOdds(); 或 bcBettingSource.subscribeDashboardOdds(2); ``` - 回應 | Field | Description | DataType | Memo | | -------- | -------- | -------- | -------- | | code | 結果代碼 | int | | | rid | request id | string | 可忽視,bcSocket內部會處理 | | subid | subscription id,之後退訂閱時候需要傳遞此id | string | 可忽視,bcSocket內部會處理 | ![](https://i.imgur.com/QOJj98m.png) ### 取得單或多筆賽事和玩法 :::info - 訂閱單一或多筆賽事的細節玩法(大小球、準確分數、誰先得分等等) - 參考畫面: - ![](https://i.imgur.com/5ltwujd.png) ::: - 指令 - bcBettingSource.subscribeGameDetail(gameId) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | gameId | 賽事的Id | string或string[] | yes | 參數可以是一個string或是string array | - 範例 ```json bcBettingSource.subscribeGameDetail("12345"); 或 bcBettingSource.subscribeGameDetail(["12345", "67890", "1314520"]); ``` - 回應:範例是取得某場SBL籃球賽的資料 ![](https://i.imgur.com/H2I2VHk.png) ### 取得體育->區域->聯賽的盤口 :::info - 進入運動項目->區域->聯賽後的頁面的玩法 - 參數marketType決定是歐洲盤口或是韓國盤口 - 參考畫面: ![](https://i.imgur.com/v1JbUL9.png) ::: - 指令 - bcBettingSource.subscribeGames(sportType, regionId, competitionId, marketType) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | sportType | 體育類型 | int | no | 預設為2;0 == Electronic, 1 == Virtual, 2 == General, 4 == Racing, 5 == Fighting | | regionId | 區域Id | int | no| 要訂閱的區域的Id | | competitionId | 聯賽的Id | int | no | | marketType | 盤口類型 | int | yes | 0 == 歐洲盤口, 1 == 韓國盤口 | - 範例 ```json bcBettingSource.subscribeGames(2, 515, null, 0); // 取得regionId 515的賽事盤口, 歐洲盤口呈現 或 bcBettingSource.subscribeGames(2, null, 757, 1); // 取得聯賽Id為757的賽事盤口, 韓國盤口呈現 ``` ## 退訂閱 ### 退訂閱內容 :::info - 在切換頁面時候,原先訂閱的資料已不被需要時,應當呼叫退訂閱資料 ::: - 指令 - bcSocket.unsubscribe(subscriptionId) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | subscriptionId | 訂閱的Id | string或string[] | yes | 參數可以是一個string或是string array | - 範例 ```json bcSocket.unsubscribe("12345"); 或 bcSocket.unsubscribe(["12345", "67890", "1314520"]); ``` ### 退訂閱所有內容 :::info - 一口氣退訂閱所有內容 ::: - 指令 - bcSocket.unsubscribeAll() ## 投注相關指令 ### 投注 :::info - 投注 ::: - 指令 - bcBetCommand.doBet({ type, mode, amount, bets }) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | type | 投注類型 | int | yes | 1 = Single, 2 = Multiple, 3 = System, 4 = Chain | | mode | 投注模式 | int | yes | -1 = 超級模式<br/>0 = 接受下注如果賠率沒變<br/>1 = 接受下注如果賠率沒變或是提升<br/> 2 = 接受下注不管賠率有沒有變 | | amount | 金額 | int | yes | | | bets | 投注的項目 | array of {event_id和price} | yes | 可以一次下單筆或多筆 | - 範例 ```json bcBetCommand.doBet({ type: 1, mode: 2, amount: 328, bets: [{ event_id: 1832941, price: 1.85 }] }); ``` - 回應範例 ```json { "code": 0, "data": { "result": "OK", "details": { "bet_id": 1832941 } } } ``` ### 投注記錄 :::info - 取得投注記錄 ::: - 指令 - bcBetCommand.betHistory({ from_date, to_date }) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | fromDate | 起始時間 | int或string | yes | 可以是timestamp或是文字時間 | | toDate | 結束時間 | int或string | yes | 可以是timestamp或是文字時間 | - 範例 ```json bcBetCommand.({ fromDate:1401566400, toDate:1404158400 }); 或是 bcBetCommand.({ fromDate:"2021/01/01 00:00:00", toDate:"2021/02/01 00:00:00" }); ``` - 回應範例 ```json ``` ### 買回注單 :::info - 任賠殺出,一種投降輸一半的概念 ::: - 指令 - bcBetCommand.cashout({betId, price, mode, partialPrice}) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | betId | 注單Id | int | yes | | | price | 金額 | int | yes | | | mode | 接受模式 | int | no | 0 = 預設, 1 = 更高, 2 = 任何 | | partialPrice | Partial price for partial cashout case | int | no | | - 範例 ```json bcBetCommand.cashout({betId:838198, price:45, mode:1, partialPrice:20}); ``` - 回應範例 ```json ``` - 重點: - 應先呼叫 bcBetCommand.calculateCashoutAmount 來計算買回注單的金額 ### 計算買回注單的金額 :::info - 任賠殺出,一種投降輸一半的概念 ::: - 指令 - bcBetCommand.calculateCashoutAmount({betId}) - 請求 | Field | Description | DataType | Required | Memo | | -------- | -------- | -------- | -------- | -------- | | betId | 注單Id | int | yes | | - 範例 ```json bcBetCommand.calculateCashoutAmount({betId:838198}); ``` - 回應範例 ```json ```