*3.2. Continuous Auction Stage*

In the continuous stage, every pair matched successfully is recorded as one round. That is, there is only one matching pair of trades per round.

Objective function—the social welfare of the continuous auction stage can be expressed as follows:

$$\pi\_2 = \sum\_{r \in \mathbb{R}} \max((P'\_{\text{bd};r} - P'\_{\text{bd};j;r}) \times Q'\_{\text{bd};j;r} + (P'\_{\text{sd};j;r} - P'\_{\text{sb};j,r}) \times Q'\_{\text{sd};j;r}) \tag{8}$$

where *r*, *R* represents the index and set of trade rounds during the second stage (continuous double auction); *<sup>P</sup> bb*,*i*,*<sup>r</sup>* (yuan/kWh) represents the bid price of market buyer *i* in the round *r*; *<sup>P</sup> bd*,*ij*,*<sup>r</sup>* (yuan/kWh) represents the deal price of market buyer *i* with market seller *j* in the round *r*; *<sup>Q</sup> bd*,*ij*,*<sup>r</sup>* (kWh) represents the energy cleared of market buyer *i* with market seller *j* in the round *r*; *<sup>P</sup> sb*,*j*,*<sup>r</sup>* (yuan/kWh) represents the bid price of market seller j in the round *r*; *<sup>P</sup> sd*,*ij*,*<sup>r</sup>* (yuan/kWh) represents the deal price of market seller *j* with market buyer *i* in the round *r*; *<sup>Q</sup> sd*,*ij*,*<sup>r</sup>* (kWh) represents the energy cleared of market seller *j* with market buyer *i* in the round *r*; and π2 (yuan) represents the social welfare of the second stage.

Market bidding constraints are defined as follows:

> ⎧⎪⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎪⎩

⎧⎪⎪⎨⎪⎪⎩

$$\begin{array}{c} Q'\_{bb,i,r} \leq \overline{Q}'\_{bb,i,r} \\ Q'\_{sb,j,r} \leq \overline{Q}'\_{sb,j,r} \end{array} \tag{9}$$

$$\begin{aligned} \overline{Q}'\_{bb;j,r} &= \overline{Q}\_{bb;j} - \sum\_{j \in I} Q\_{hd,ij} - \sum\_{r'=1}^{r-1} \sum\_{j \in I} Q'\_{hd,ij,r'}\\ \overline{Q}'\_{sb,j,r} &= \overline{Q}\_{sb,j} - \sum\_{j \in I} Q\_{sd,ij} - \sum\_{r'=1}^{r-1} \sum\_{j \in I} Q'\_{sd,i,j,r'} \end{aligned} \tag{10}$$

$$\begin{cases} \ P\_{\alpha} \le P\_{bb,i,r}' \le P\_{\beta} \\\ P\_{\alpha} \le P\_{sb,i,r}' \le P\_{\beta} \end{cases} \tag{11}$$

where *Q bb*,*i*,*<sup>r</sup>* represents the bid quantity caps of buyer *i* in the round *r*; *Q sb*,*j*,*<sup>r</sup>* represents the bid quantity caps of seller *j* in the round *r*; Equation (10) explains that how to calculate the bid quantity constraint value of the round *r*.

Market clearing constraints are defined as follows:

$$\begin{cases} \sum\_{j \in I} Q'\_{bd,ij,r} \le Q'\_{vb,i,r} \\ \sum\_{i \in I} Q'\_{sd,ij,r} \le Q'\_{sb,j,r} \end{cases} \tag{12}$$

$$\sum\_{i \in I} \sum\_{j \in \mathcal{J}} Q'\_{\text{bd,ij,r}} = \sum\_{i \in I} \sum\_{j \in \mathcal{J}} Q'\_{\text{sd},ij,r} \tag{13}$$

$$\begin{cases} Q'\_{lb,i,r} \ge 0 \\ Q'\_{sb,j,r} \ge 0 \end{cases} \tag{14}$$

$$\begin{cases} P'\_{\Lambda,ij,r} = P'\_{lb,j,r} - P'\_{sb,j,r} \\ P'\_{lb,ij,r} = P'\_{lb,j,r} - P'\_{\Lambda,ij,r}/2 \\ P'\_{sd,ij,r} = P'\_{sb,j,r} + P'\_{\Lambda,ij,r}/2 \end{cases} \tag{15}$$

Equation (12) indicates that the accumulated transaction quantity must be less than their bid quantity in the per round. Equation (13) represents that the total amount of electricity traded between buyers and sellers is balanced. In Equation (14), the lower bound takes nonnegative values for *Q bb*,*i*,*<sup>r</sup>* and *<sup>Q</sup> sb*,*j*,*r*, which means that transfers of electricity between buyers or between sellers are not allowed in this transaction. The clearing price mechanism is illustrated in Equation (15). *<sup>P</sup>* <sup>Δ</sup>,*ij*,*<sup>r</sup>* represents the DOP between marker buyer *i* and marker seller *j* in the round *r*, and *<sup>P</sup> bd*,*ij*,*<sup>r</sup> <sup>P</sup> sd*,*ij*,*<sup>r</sup>* are the buying and selling prices for the financial settlement of each pair, respectively.

#### **4. Two-Stage Integrated Clearing Algorithm**

As mentioned above, the CBT includes a bidding process that integrates CA and CDA. In order to better design a two-stage integrated market clearing algorithm, it is necessary to analyze its main differences and connections.

Connections: After the market clearing of the first stage, the orders with remaining unmatched volume will be directly included in the second stage, at the same time as the earliest bidding information in the second stage.

Differences: The market clearing takes place only once after all the biddings are collected in the first stage, and the bidding and clearing are obviously sequential; the market clearing is real-time in the second stage, and once the transaction conditions are met, the matching will be carried out. The real-time market-clearing couples the continuous bidding and clearing together.

To ensure the data consistency and business continuity in an efficient way, based on the above analysis, a two-stage integrated market-clearing algorithm is designed. The algorithm used to solve the whole problem is represented by the flowchart in Figure 3. The main steps involved in the algorithm implementation are described as follows.

**Figure 3.** Flowchart of the algorithm.

Step 1: pair each buyer and seller, and the DOPs are calculated for all matching pairs.

Step 2: these pairs are then sorted in descending order based on DOP values. Obviously, a pair with a negative DOP value will not be contracted. The same DOP pairs are divided into a group.

Step 3: start with the group with the largest DOP. If there are any remaining spread groups to calculate, proceed to the next step; otherwise, the market clearing of the first phase is over, so move on to Step 5. Step 4: the total transaction amount of this group is the smaller value of the quantity declared by all the buyers and the quantity declared by all the sellers in this group. Then, the transaction quantity of each pair is allocated according to the bid quantity in this group. The prices are given by Equation (7), which is mentioned above. After the contract is formed, move on to step 3.

Step 5: orders with remaining unmatched volume are marked with the same timestamp and grouped by price. After entering the second stage, each group is listed as a new order at the earliest time.

Step 6: if the continuous phase is still in progress, then enter the next step; otherwise, the market clearing in the second phase is over.

Step 7: wait and receive new bid info of buyers or sellers. All buyer bids are sorted according to bid-price values in descending order, while seller bids are sorted in ascending order. Once the bid price between buyers or between sellers is the same, it shall be sorted according to the principle of early declaration priority.

Step 8: obtain the optimal order of buyers' declaration and sellers' declaration, and calculate the DOP between buyers' and sellers' bids.

Step 9: if the DOP is not negative, go to the next step; otherwise, move on to step 6.

Step 10: the pair is matched between the buyer and seller, whose transaction amount is the smaller value of the quantity declared by the buyer and the quantity declared by the seller. The buyer price

and seller price are given by Equation (15), which is mentioned above. After the contract is formed, move on to step 6.

## **5. CBT-Based Electricity Trading Platform**

As the software application platform for the CBT in the YNEM, the CETP mainly serves market participants and the market operators. The former need to submit a set of price-volume bids through the CETP to obtain the electricity contracts. The latter is responsible for matching the electricity bids submitted by buyers and sellers and for determining the prices and quantities of the energy traded in the market, which needs to be completed through the CETP.

The framework of the CETP and some key implementation strategies adopted in the system are described below.

#### *5.1. The Overall Architecture of CETP*

The conceptual framework of the CETP is demonstrated in Figure 4, employing a multitier architecture: client-side application (presentation tier); application server cluster (application tier); and database cluster (data tier) [42]. In the overall deployment, the responsibilities of each tier are different, and each tier can have one or more components. It should be noted that these tiers may not correspond to the physical distribution and are purely abstract. The components that handle the user interface and user interaction are at the presentation tier. Components that work together to solve business logic problems, such as user bidding, order validation, and market clearing, belong to the application layer. The business logic tier uses the data tier as the repository of the whole system. The CETP selects both relational and nonrelational databases [43], according to the business characteristics of the CBT. For the sake of high performance, clustering technology and dual hot backup machine technology are adopted for each application server and database server in the system.

**Figure 4.** Conceptual framework of the trading system with multitiered architecture.

Generating company (GENCO) users, consumption company (CONCO) users, market operators of the KMPEX, etc. can independently and synchronously access the user interfaces for data entry, bidding, operation, analysis, market clearing, grid security checks, querying information, and so on. The requests received in the presentation tier are proposed in the application tier. Components consisting in the application tier constitute four main modules: message queue-based order processing, multilevel order logic verification with predefined rules, market clearing using models (i.e., market clearing models), and real-time push and disclosure of market information. The data generated by the application layer will be stored in the database for archiving. The results are displayed to the user in the presentation tier.

#### *5.2. Process Flow of Bidding Order*

The CBT orders run through the kernel business of the CETP. Figure 5 graphically represents the order data flows in the CETP and analyzes the data flows during order processing. During processing, the orders in the CETP are stored in a message queue. All the orders submitted or canceled are first placed in the original queue. If two bids are made at exactly the same time, the order of entry into the original queue is determined by chance. Next, the orders in the original queue will be marked with a timestamp, as a key indicator of order sorting for the clearing algorithm, and then enter the queue to be detected. Furthermore, based on the trading rules, all orders in the order queue to be detected are checked according to the rules, and those that do not meet the conditions are put into the order queue without pass validation; otherwise, they are put into the order queue with pass validation. Only orders that pass validation can be used for market clearing, and the orders that meet the transaction conditions will be matched to form the final transaction results stored in the result queue. In addition, the market information needs to be calculated logically based on the market process information and pushed to the market participants through the real-time push service. All process and result information for processing an order is stored in a persistent manner.

**Figure 5.** Data flow diagram of CBT.

#### *5.3. Logic Verification for Trading Rules*

Reasonable and e ffective order verification can ensure the standardization and e ffectiveness of bidding orders, to ensure the normal operation of transactions. A multilevel order logic verification method with predefined rules is put into use in the CETP.

The verification content of each level is as follows.

Level One: verify the information integrity of the bidding data, such as the unique identification code of the bidding subject and the bidding timestamp, which is regarded as the information integrity validation.

Level Two: verify the basic specifications of bidding power and electricity price in each stage, such as data type and accuracy, which is regarded as business standardization verification.

Level Three: verify the number of bidding segments in each stage, the logic of placing and withdrawing orders, and other types of business constraints, which is regarded as the business logic validation.

As shown in Figure 6, the verification of the three layers is carried out in sequence. Once the order cannot pass the verification of one layer, the verification failure will be directly determined. It should be noted that the check items in each layer can be adjusted, invalidated, or added when the business rules change. After the verification process, the verification module forwards the order to the verification result queue, and participants ge<sup>t</sup> notified of a successful or failed order submission.

**Figure 6.** Schematic diagram of the verification process.
