0. 课程视频
1. 实体类DepthsVo 选出属性 解耦
import org.example.domain.DepthItemVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
@Data
@ApiModel(value = "深度盘口数据")
public class DepthsVo {
/**
* 委托买单
*/
@ApiModelProperty(value = "委托买单")
private List<DepthItemVo> bids = Collections.emptyList() ;
/**
* 委托卖单
*/
@ApiModelProperty(value = "委托卖单")
private List<DepthItemVo> asks = Collections.emptyList() ;
/**
* 当前成交价(GCN)
*/
@ApiModelProperty(value = "当前成交价GCN")
private BigDecimal price = BigDecimal.ZERO;
/**
* 当前成交价对应CNY价格
*/
@ApiModelProperty(value = "当前成交价CNY")
private BigDecimal cnyPrice = BigDecimal.ZERO;
}
2. 前端确定 请求url
http://127.0.0.1/exchange/markets/depth/BTCGCN/DEFAULT
3. DepthItemVo
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@ApiModel("明细")
@NoArgsConstructor
@AllArgsConstructor
@Data
public class DepthItemVo implements Comparable<DepthItemVo> {
/**
* 价格
*/
@ApiModelProperty(value = "价格")
private BigDecimal price = BigDecimal.ZERO;;
/**
* 数量
*/
@ApiModelProperty(value = "数量")
private BigDecimal volume = BigDecimal.ZERO;
@Override
public int compareTo(DepthItemVo o) {
return this.price.compareTo(o.getPrice());
}
}
4. controller ->MarketController
public R<DepthsVo> findDeptVosSymbol(@PathVariable("symbol") String symbol, String dept) { // @PathVariable("symbol") 路径里的值
// 交易市场
Market market = marketService.getMarkerBySymbol(symbol);
DepthsVo depthsVo = new DepthsVo();
depthsVo.setCnyPrice(market.getOpenPrice()); // CNY的价格
depthsVo.setPrice(market.getOpenPrice()); // GCN的价格
// 接入okx 数据的地方
// 假数据
depthsVo.setAsks(
Arrays.asList(
new DepthItemVo(BigDecimal.valueOf(7.00000),BigDecimal.valueOf(100)
new DepthItemVo(BigDecimal.valueOf(6.00000),BigDecimal.valueOf(100)
));
depthsVo.setBids(
Arrays.asList(
new DepthItemVo(BigDecimal.valueOf(5.00000),BigDecimal.valueOf(100)
new DepthItemVo(BigDecimal.valueOf(4.00000),BigDecimal.valueOf(100)
));
return R.ok(depthsVo);
}