Project Background

Recently worked on an overseas exchange system, with client requirements including perpetual contracts, delivery contracts, and K-line control features. The tech stack is Vue + Java, and I’m documenting the development process here.

Technical Solution

Frontend: Vue 3 + Vue 2 (both ends)

Backend: Java Spring Boot

Database: MySQL + Redis

Vue was chosen because of its excellent ecosystem and rich component library, which is well-suited for building complex interfaces like exchanges.

Core Features

1. Contract Trading Types

This system supports three types of contract trading:

– Perpetual Contract: No expiration date, can be held indefinitely

– Delivery Contract: Has an expiration date, settles upon expiration

– Spot Trading: Buying and selling digital currencies

// Contract Service

@Service

public class ContractService {

// Open Position

public OpenResult openPosition(OpenRequest request) {

// Check if position exceeds limit

if (checkPositionLimit(request)) {

throw new BusinessException(“Position exceeds limit”);

}

// Calculate margin

BigDecimal margin = calculateMargin(request);

// Create position record

Position position = new Position();

position.setSymbol(request.getSymbol());

position.setType(request.getType());

position.setDirection(request.getDirection());

position.setAmount(request.getAmount());

position.setLeverage(request.getLeverage());

position.setMargin(margin);

positionMapper.insert(position);

return new OpenResult(position.getId());

}

}

2. K-line Control

This is a essential feature for overseas exchanges. Sometimes manual intervention in K-line trends is needed, such as pumping or dumping the price.

Implementation approach:

– Store preset K-line data in the database

– API returns preset data instead of real exchange data

@Service

public class KLineService {

// Get K-line data

public List getKLines(String symbol, String interval) {

// Check if control mode is enabled

if (isControlEnabled(symbol)) {

return getPresetKLines(symbol, interval);

}

return getRealKLines(symbol, interval);

}

// Set K-line control

public void setKLineControl(String symbol, List presetData) {

redis.set(“kline:” + symbol, JSON.toJSONString(presetData));

}

}

This feature should be used cautiously, mainly for market makers to maintain the market.

3. Staking Financial Products

Supports holding coins to earn interest, a standard feature for exchanges.

Risk Control

Risk control is the top priority for exchange systems:

– Position Limit: Total positions for a single user cannot exceed a certain amount

– Withdrawal Limit: Daily withdrawal frequency and amount limits

– Anomaly Detection: High-frequency large transactions should trigger risk control

– Liquidation Handling: Losses exceeding margin should trigger forced liquidation

UI Design

Exchange UI should be professional, referencing the layout of major exchanges like Binance and Huobi. Dark color schemes look professional and are easier on the eyes.

Summary

The main challenges in exchange system development are:

– Performance: High-frequency trading requires high performance

– Risk Control: Must handle various edge cases properly

– Capital Security: Involves real money, and safety cannot be emphasized enough