Order Book
Vue 已实现 · 还原验收 0/1 · 上游演示 · 固定版本源码
预览
| Price USD | Size SOL | Total |
|---|---|---|
| 782 | 8,581 | |
| 1,200 | 7,799 | |
| 1,100 | 6,599 | |
| 2,200 | 5,499 | |
| 1,800 | 3,299 | |
| 278 | 1,499 | |
| 363 | 1,221 | |
| 574 | 858 | |
| 284 | 284 | |
| 245.85 Spread 0.30 | ||
| 194 | 194 | |
| 543 | 737 | |
| 314 | 1,051 | |
| 592 | 1,643 | |
| 715 | 2,358 | |
| 744 | 3,102 | |
| 789 | 3,891 | |
| 735 | 4,626 | |
| 1,100 | 5,726 | |
Click a price to use it, for example in an order ticket.
用法
vue
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { OrderBook } from 'beui-vue'
const tick = ref(0), playing = ref(true), chosen = ref<number | null>(null)
const askSizes = [284,574,363,278,1800,2200,1100,1200,782], bidSizes = [194,543,314,592,715,744,789,735,1100]
function side(sizes: number[], direction: number) {
return sizes.map((size, index) => {
const phase = (index + Number(direction === 1)) % 3
const last = tick.value - (tick.value + phase) % 3
return { price: Number((245.85 + direction * (index + 1) * .15).toFixed(2)),
size: last <= 0 ? size : Math.round(size * (1 + Math.sin(last * 1.3 + index * 2.1 + direction) * .32)) }
})
}
const book = computed(() => ({ asks: side(askSizes, 1), bids: side(bidSizes, -1) }))
let timer: ReturnType<typeof setInterval> | undefined
onMounted(() => { timer = setInterval(() => { if (playing.value && !document.hidden) tick.value++ }, 950) })
onBeforeUnmount(() => clearInterval(timer))
</script>
<template>
<div class="chart-demo" style="max-width:520px"><header><strong>SOL / USD <small class="sim">Simulated</small></strong><div><button type="button" @click="playing = !playing">{{ playing ? 'Pause' : 'Resume' }}</button><button type="button" @click="playing = false; tick++">Step</button></div></header>
<OrderBook label="Simulated SOL / USD order book" base-symbol="SOL" quote-symbol="USD" v-bind="book" @level-select="level => chosen = level.price" />
<p aria-live="polite">{{ chosen === null ? 'Click a price to use it, for example in an order ticket.' : `Selected ${chosen.toFixed(2)} USD` }}</p>
</div>
</template>
<style scoped>
.chart-demo { width: 100%; min-width: 0; margin-inline: auto; }
.chart-demo > header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 20px; }
.chart-demo header strong { font-size: 14px; font-weight: 500; }
.chart-demo header p, .chart-demo > p { margin: 4px 0 0; color: var(--beui-muted-foreground); font-size: 12px; line-height: 16px; }
.chart-demo header button,.chart-demo fieldset button { padding: 6px 12px; background: transparent; border: 0; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; }
.chart-demo header button:hover,.chart-demo fieldset button[aria-pressed=true] { background: var(--beui-muted); }
.chart-demo > footer { margin-top: 24px; text-align: center; color: var(--beui-muted-foreground); font-size: 11px; }
.chart-demo .sim { margin-left: 6px; border: 1px solid var(--beui-border); padding: 2px 5px; border-radius: 3px; text-transform: uppercase; font-size: 9px; letter-spacing: .05em; color: var(--beui-muted-foreground); }
</style>API
bids、asks 接受价量快照,levels 控制深度,v-model:active-level 同步检查价位。@level-select 接收价位与方向,#summary 定制累计深度。