Skip to content

Order Book ​

Vue 已实现 · 还原验收 0/1 · 上游演示 · 固定版本源码

预览 ​

SOL / USD Simulated
Price USDSize SOLTotal
7828,581
1,2007,799
1,1006,599
2,2005,499
1,8003,299
2781,499
3631,221
574858
284284
245.85 Spread 0.30
194194
543737
3141,051
5921,643
7152,358
7443,102
7893,891
7354,626
1,1005,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 定制累计深度。

还原验收 ​

基于 beUI 的独立 Vue 移植,依 MIT 许可证分发。