---
# System prepended metadata

title: API WebSocket 事件傳送格式
tags: [API 文件]

---

###### tags: `API 文件`

API WebSocket 事件傳送格式
===
    
    
### 基本API格式
SendMessage([MessageType 事件ID], [Body 事件訊息])

enum MessageType {
  MarketChanged = 0;   // 賽事賠率變化資訊(目前為A水混水到產出M水流程用)
  MatchInfo     = 1;   // 賽事資訊更新
  GetSessionID  = 2;   // 取得SessionID用(建立完WebSocket連線，推送sessionID給前端)
  MatchCreated  = 3;   // 賽事新增事件
  MatchDelete   = 4;   // 賽事刪除事件
}


### WebSocket Service(svc): 

svc.SendMarketChangedMsg(MarketChanged, [Body 事件訊息])
svc.SendMatchInfoMsg(MatchInfo, [Body 事件訊息])
svc.SendGetSessionIDMsg(GetSessionID, [Body 事件訊息])
svc.SendMatchCreatedMsg(MatchCreated, [Body 事件訊息])
svc.SendMatchDeleteMsg(MatchDelete, [Body 事件訊息])


### 事件傳送格式: 

SendMarketChangedMsg(MarketChanged, [Body 事件訊息])
MarketChanged = 0;  // 賽事賠率變化資訊(目前為A水混水到產出M水流程用)

```json=
[
  Tournament:{
    name: "",
    matches: [
      {
        id:"",
        status: {
          sourcePause:"",
          eventPause:"",
          adjustPause:"",
          isPause:"",
          isClose:"",
        }
        market:[ //玩法，如1x2、AH、OU
          {
            marketId:"",
            marketName:"",
            sourcePause:"",
            eventPause:"",
            adjustPause:"",
            isPause:"",
            lines: [ //盤口，如大2.5，讓0/0.5
              {
                condition: "" //盤口的決定球數
                status:"", //Open, Suspend, Closed
                isSync:"", //是否要跟隨水份(是否要上下盤連動)，default是true，要上下連動
                outcomes:[ //投注項，如讓球玩法中的主、客隊，大小玩法中的大、小
                  {
                    id:"",
                    odd:"",
                    adjust:""
                  }
                ]
              }
            ]
          }
          
        ]
      }
    ]
  }
]
```


SendMatchInfoMsg(MatchInfo, [Body 事件訊息])
MatchInfo = 1;     // 賽事資訊更新



```json=
[
  Tournament:{
    name: "",
    matches: [
      {
        id:"",
        home: {
          name: "", //隊名
          score: "", //分數
          redCard: "", //紅牌數
        },
        away: {
          name: "", //隊名
          score: "", //分數
          redCard: "", //紅牌數
        },
        status: {
          phase: "1H",//"賽事節數變化，上半場、中場、下半場、延長賽上半場、延長賽中場、延長賽下半場、PK"
          startTime: "2022-12-19T18:15:52Z", //該節賽事開賽時間
        }
]

```
 
SendGetSessionIDMsg(GetSessionID, [Body 事件訊息])
GetSessionID = 2;  // 取得SessionID用(建立完WebSocket連線，推送sessionID給前端)


```json=
[
  SessionID: "1f36daee-8107-11ed-99ee-ce4447cc92e9" 
]
  
```

SendMatchCreatedMsg(MatchCreated, [Body 事件訊息])
MatchCreated = 3;  // 賽事新增事件

```json=
[
  Tournament:{
    name: "",
    matches: [
      {
        id:"",
        home: {
          name: "", //隊名
          score: "0", //分數
          redCard: "0", //紅牌數
        },
        away: {
          name: "", //隊名
          score: "0", //分數
          redCard: "0", //紅牌數
        },
        status: {
          phase: "1H",//"賽事節數，上半場、中場、下半場、延長賽上半場、延長賽中場、延長賽下半場、PK"
          startTime: "2022-12-19T18:15:52Z", //該節賽事開賽時間
          injuryTime: "", // Whta is this for??
          sourcePause:"",
          eventPause:"",
          adjustPause:"",
          isPause:"",
          isClose:"",
        }
        market:[ //玩法，如1x2、AH、OU
          {
            marketId:"",
            marketName:"",
            sourcePause:"",
            eventPause:"",
            adjustPause:"",
            isPause:"",
            lines: [ //盤口，如大2.5，讓0/0.5
              {
                condition:"" //盤口的決定球數
                status:"", //Open, Suspend, Closed
                isSync:"", //是否要跟隨水份(是否要上下盤連動)，default是true，要上下連動
                outcomes:[ //投注項，如讓球玩法中的主、客隊，大小玩法中的大、小
                  {
                    id:"",
                    odd:"",
                    adjust:""
                  }
                ]
              }
            ]
          }
          
        ]
      }
    ]
  }
]
```

SendMatchDeleteMsg(MatchDelete, [Body 事件訊息])
MatchDelete = 4;   // 賽事刪除事件

```json=
[
     matchID: "str" // match id
]
```
