simnow 仿真实测通过

This commit is contained in:
simple321vip
2022-09-14 23:11:36 +08:00
parent 736f026069
commit 4320f35a52
3 changed files with 117 additions and 47 deletions
+93 -35
View File
@@ -57,28 +57,45 @@
<el-tab-pane label="委托" name=3></el-tab-pane> <el-tab-pane label="委托" name=3></el-tab-pane>
<el-tab-pane label="成交" name=4></el-tab-pane> <el-tab-pane label="成交" name=4></el-tab-pane>
</el-tabs> </el-tabs>
<el-table v-if="activeName == 1" :data="position_data" stripe style="width: 100%"> <el-table v-if="activeName == 1" :data="positions_data" stripe style="width: 100%">
<el-table-column prop="symbol" label="合约名称" width="180" /> <el-table-column prop="symbol" label="合约名称" width="100" />
<el-table-column prop="direction" label="多空" width="180" /> <el-table-column prop="exchange" label="交易所" width="100" />
<el-table-column prop="open_price" label="开仓价格" width="180" /> <el-table-column prop="direction" label="多空" width="100" />
<el-table-column prop="gain_loss" label="盈亏" /> <el-table-column prop="volume" label="成交量" width="100" />
<el-table-column prop="price" label="开仓价格" width="100" />
<el-table-column prop="frozen" label="frozen" width="100" />
<el-table-column prop="pnl" label="pnl" width="100" />
<el-table-column prop="yd_volume" label="yd_volume" width="120" />
</el-table> </el-table>
<el-table v-if="activeName == 2" :data="position_data" stripe style="width: 100%"> <el-table v-if="activeName == 2" :data="orders_data" stripe style="width: 100%">
<el-table-column prop="symbol" label="合约名称" width="180" /> <el-table-column prop="symbol" label="合约名称" width="100" />
<el-table-column prop="direction" label="多空" width="180" /> <el-table-column prop="exchange" label="交易所" width="100" />
<el-table-column prop="balance" label="盈亏" /> <el-table-column prop="direction" label="多空" width="100" />
<el-table-column prop="volume" label="成交量" width="100" />
<el-table-column prop="price" label="开仓价格" width="100" />
</el-table> </el-table>
<el-table v-if="activeName == 3" :data="position_data" stripe style="width: 100%"> <el-table v-if="activeName == 3" :data="orders_data" stripe style="width: 100%">
<el-table-column prop="symbol" label="合约名称" width="180" /> <el-table-column prop="symbol" label="合约名称" width="80" />
<el-table-column prop="direction" label="多空" width="180" /> <el-table-column prop="exchange" label="交易所" width="80" />
<el-table-column prop="balance" label="盈亏" /> <el-table-column prop="direction" label="多空" width="80" />
<el-table-column prop="volume" label="成交量" width="80" />
<el-table-column prop="price" label="委托价格" width="100" />
<el-table-column prop="orderid" label="orderid" width="160" />
<el-table-column prop="type" label="type" width="80" />
<el-table-column prop="offset" label="开平" width="80" />
<el-table-column prop="traded" label="traded" width="80" />
<el-table-column prop="status" label="status" width="80" />
<el-table-column prop="reference" label="reference" width="100" />
</el-table> </el-table>
<el-table v-if="activeName == 4" :data="deal_data" stripe style="width: 100%"> <el-table v-if="activeName == 4" :data="trades_data" stripe style="width: 100%">
<el-table-column prop="symbol" label="合约名称" width="180" /> <el-table-column prop="symbol" label="合约名称" width="100" />
<el-table-column prop="direction" label="开平" width="180" /> <el-table-column prop="exchange" label="交易所" width="100" />
<el-table-column prop="price" label="成交价" width="180" /> <el-table-column prop="direction" label="多空" width="100" />
<el-table-column prop="volume" label="成交量" width="180" /> <el-table-column prop="volume" label="成交量" width="100" />
<el-table-column prop="balance" label="成交时间" width="180" /> <el-table-column prop="price" label="开仓价格" width="100" />
<el-table-column prop="orderid" label="orderid" width="100" />
<el-table-column prop="orderid" label="orderid" width="100" />
<el-table-column prop="offset" label="offset" width="100" />
</el-table> </el-table>
</div> </div>
</template> </template>
@@ -87,7 +104,7 @@
import { ElMessage, TabsPaneContext } from 'element-plus' import { ElMessage, TabsPaneContext } from 'element-plus'
import { reactive, ref, h, onMounted, onUnmounted } from 'vue' import { reactive, ref, h, onMounted, onUnmounted } from 'vue'
import { get_accounts, send_order, get_contract, subscribe } from '../../api/capital' import { get_accounts, send_order, get_tick } from '../../api/capital'
import { strategyStore } from '../../store/strategy'; import { strategyStore } from '../../store/strategy';
type AccountData = { type AccountData = {
geteway_name: string geteway_name: string
@@ -97,19 +114,41 @@ type AccountData = {
} }
type PositionData = { type PositionData = {
symbol: string symbol: string
exchange: string
direction: string direction: string
open_price: number
gain_loss: number
}
type DealData = {
symbol: string
direction: string
price: number
volume: number volume: number
price: number
frozen: number
pnl: number
yd_volume: number
}
type OrderData = {
symbol: string
exchange: string
direction: string
volume: number
price: number
orderid: string
type: string
offset: string
traded: number
status: string
// datetime :datetime
reference: string
}
type TradeData = {
symbol: string
exchange: string
direction: string
volume: number
price: number
orderid: string
tradeid: string
offset: string
// datetime: datetime
} }
const store = strategyStore() const store = strategyStore()
const vt_symbol = ref<string>("") const vt_symbol = ref<string>("")
const contracts = reactive<string[]>([])
const direction = ref('多') const direction = ref('多')
const offset = ref('开') const offset = ref('开')
const activeName = ref(1) const activeName = ref(1)
@@ -122,20 +161,39 @@ const account_data = reactive<AccountData>({
balance: 0.0, balance: 0.0,
frozen: 0.0 frozen: 0.0
}) })
const position_data = reactive<PositionData[]>([]) const positions_data = reactive<PositionData[]>([])
const deal_data = reactive<DealData[]>([]) const trades_data = reactive<TradeData[]>([])
const orders_data = reactive<OrderData[]>([])
const on_query_accounts = () => { const on_query_accounts = () => {
get_accounts().then(res => { get_accounts().then(res => {
account_data.account_id = res.data.account_id let accounts: [] = res.data.accounts
account_data.balance = res.data.balance let account: any = accounts.pop()
account_data.geteway_name = res.data.geteway_name account_data.account_id = account.account_id
account_data.frozen = res.data.frozen account_data.balance = account.balance
account_data.geteway_name = account.geteway_name
account_data.frozen = account.frozen
positions_data.length = 0
res.data.positions.forEach((element: PositionData) => {
positions_data.push(element)
})
trades_data.length = 0
res.data.trades.forEach((element: TradeData) => {
trades_data.push(element)
})
orders_data.length = 0
res.data.orders.forEach((element: OrderData) => {
orders_data.push(element)
})
}) })
} }
const select_contract = () => { const select_contract = () => {
subscribe(vt_symbol.value).then(res => { get_tick(vt_symbol.value).then(res => {
price.value = res.data.tick.last_price price.value = res.data.tick.last_price
}) })
} }
+1 -1
View File
@@ -48,7 +48,7 @@ const init = () => {
}) })
get_subscribe_vt_symbols().then(res => { get_subscribe_vt_symbols().then(res => {
store.$patch({ vt_symbols: res.data.vt_symbols }) store.$patch({ subscribe_vt_symbols: res.data.vt_symbols })
}).catch(error => { }).catch(error => {
ElMessage({ ElMessage({
message: h('p', null, [ message: h('p', null, [
+23 -11
View File
@@ -1,22 +1,22 @@
<template> <template>
<el-row> <el-row>
<el-col :span="4"> <el-col :span="4">
<el-select v-model="exchange" placeholder="select a exchange" @change="filter_vt_symbols"> <el-select v-model="exchange" placeholder="select a exchange">
<el-option v-for="ex in store.exchanges" :value="ex" /> <el-option v-for="ex in exchanges" :value="ex" />
</el-select> </el-select>
</el-col> </el-col>
<el-col :span="1"> <el-col :span="1">
</el-col> </el-col>
<el-col :span="4"> <el-col :span="4">
<el-select v-model="vt_symbol" placeholder="select a vt_symbol"> <el-select v-model="vt_symbol" placeholder="select a vt_symbol">
<el-option v-for="symbol in store.vt_symbols.get(exchange)" :value="symbol" /> <el-option v-for="symbol in vt_symbols" :value="symbol" />
</el-select> </el-select>
</el-col> </el-col>
<el-col :span="1"> <el-col :span="1">
</el-col> </el-col>
<el-col :span="4"> <el-col :span="4">
<span style="cursor: pointer"> <span style="cursor: pointer">
<el-icon :size="25" @click="on_subscribe(vt_symbol)"> <el-icon :size="25" @click="on_subscribe()">
<ZoomIn /> <ZoomIn />
</el-icon> </el-icon>
</span> </span>
@@ -36,14 +36,19 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, h, onMounted, onUnmounted, reactive } from 'vue' import { ref, h, onMounted, onUnmounted, reactive, watch } from 'vue'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { get_ticks, subscribe } from '../../api/capital' import { get_ticks, subscribe } from '../../api/capital'
import { strategyStore } from '../../store/strategy' import { strategyStore } from '../../store/strategy'
const store = strategyStore() const store = strategyStore()
const vt_symbol = ref<string>("") const vt_symbol = ref<string>()
const vt_symbols = reactive<string[]>([])
const exchange = ref<string>() const exchange = ref<string>()
const exchanges = reactive<string[]>([])
store.exchanges.forEach(exchange => {
exchanges.push(exchange)
})
const timer = ref(0) const timer = ref(0)
type TickData = { type TickData = {
@@ -58,8 +63,11 @@ type TickData = {
} }
const ticks_data = reactive<TickData[]>([]) const ticks_data = reactive<TickData[]>([])
const on_subscribe = (vt_symbol: string) => { const on_subscribe = () => {
subscribe(vt_symbol).then(res => { if (!vt_symbol.value) {
return
}
subscribe(vt_symbol.value).then(res => {
ElMessage({ ElMessage({
message: h('p', null, [ message: h('p', null, [
h('i', { style: 'color: green' }, "行情订阅成功"), h('i', { style: 'color: green' }, "行情订阅成功"),
@@ -83,9 +91,13 @@ const on_ticks = () => {
}) })
} }
const filter_vt_symbols = () => { watch(exchange, (newVal, oldVal) => {
vt_symbols.length = 0
} // let sp_vt_symbol: [] = store.vt_symbols.get(vt_symbol.value)
// sp_vt_symbol.forEach((record: string) => {
// vt_symbols.push(record)
// })
})
onMounted(() => { onMounted(() => {
clearInterval(timer.value) clearInterval(timer.value)