From facfa3bdb77a698b5a3b8edcd6069f7699a2df66 Mon Sep 17 00:00:00 2001 From: shilin Date: Sat, 8 Feb 2025 14:22:11 +0800 Subject: [PATCH] code --- src/api/admin/line-api-group.js | 5 +- src/views/admin/line-api-group/index.vue | 51 +++- src/views/admin/line-api-user/index.vue | 6 +- src/views/admin/line-pre-order/index.vue | 292 ++++++++++++++++++----- 4 files changed, 277 insertions(+), 77 deletions(-) diff --git a/src/api/admin/line-api-group.js b/src/api/admin/line-api-group.js index 7ecbaab..78e5d6a 100644 --- a/src/api/admin/line-api-group.js +++ b/src/api/admin/line-api-group.js @@ -43,10 +43,11 @@ export function delLineApiGroup(data) { data: data }) } -export function getUser() { +export function getUser(data) { return request({ url: '/api/v1/line-api-user/getUser', - method: 'post' + method: 'post', + data }) } export function userbind(data) { diff --git a/src/views/admin/line-api-group/index.vue b/src/views/admin/line-api-group/index.vue index 65c903c..1215ef9 100644 --- a/src/views/admin/line-api-group/index.vue +++ b/src/views/admin/line-api-group/index.vue @@ -121,7 +121,24 @@ - + + + + + import { delLineApiGroup, getLineApiGroup, listLineApiGroup, updateLineApiGroup, getUser, userbind } from '@/api/admin/line-api-group' - export default { name: 'LineApiGroup', components: { @@ -183,7 +199,7 @@ export default { queryParams: { pageIndex: 1, pageSize: 10, - groupName: undefined, + groupName: undefined }, accounts: [], // 表单参数 @@ -193,10 +209,12 @@ export default { sid: undefined, // 表单校验 rules: { + exchangeType: [{ required: true, message: '交易所不能为空', trigger: 'blur' }], groupName: [{ required: true, message: '用户组名称不能为空', trigger: 'blur' }], pid: [{ required: true, message: '主账号不能为空', trigger: 'blur' }], sid: [{ required: true, message: '副账号不能为空', trigger: 'blur' }] - } + }, + exchangeTypes: [] } }, computed: { @@ -206,11 +224,23 @@ export default { }, created() { this.getList() - getUser().then(response => { - this.accounts = response.data + // 获取交易所字典数据 + this.getDicts('exchange_type').then(response => { + this.exchangeTypes = response.data + this.apiGetUser(this.exchangeTypes.length ? this.exchangeTypes[0].value : '') }) }, methods: { + onChange() { + this.exchangeTypes = [] + this.apiGetUser() + }, + // 获取用户 + apiGetUser(exchangeType) { + getUser({ exchangeType: exchangeType || this.form.exchangeType }).then(response => { + this.accounts = response.data + }) + }, /** 查询参数列表 */ getList() { this.loading = true @@ -229,7 +259,7 @@ export default { // 表单重置 reset() { this.form = { - + exchangeType: this.exchangeTypes.length ? this.exchangeTypes[0].value : '', id: undefined, groupName: undefined, apiUserId: undefined, @@ -263,9 +293,6 @@ export default { this.open = true this.title = '添加用户绑定从属关系表' this.isEdit = false - getUser().then(response => { - this.accounts = response.data - }) }, // 多选框选中数据 handleSelectionChange(selection) { @@ -301,8 +328,8 @@ export default { } }) } else { - const { groupName, pid, sid } = this.form - userbind({ group_name: groupName, user_id_str: `${pid},${sid}` }).then(response => { + const { groupName, pid, sid, exchangeType } = this.form + userbind({ group_name: groupName, user_id_str: `${pid},${sid}`, exchangeType }).then(response => { if (response.code === 200) { this.msgSuccess(response.msg) this.open = false diff --git a/src/views/admin/line-api-user/index.vue b/src/views/admin/line-api-user/index.vue index ac301da..1284ea5 100644 --- a/src/views/admin/line-api-user/index.vue +++ b/src/views/admin/line-api-user/index.vue @@ -357,7 +357,7 @@ export default { }, methods: { exchangeTypeFormat(row) { - return this.selectDictLabel(this.exchangeTypes, row.exchangeType) + return this.selectDictLabel(this.exchangeTypes || [], row.exchangeType) }, /** 查询参数列表 */ getList() { @@ -403,10 +403,10 @@ export default { this.fileOpen = false }, userIdFormat(row) { - return this.selectItemsLabel(this.userIdOptions, row.userId) + return this.selectItemsLabel(this.userIdOptions || [], row.userId) }, groupIdFormat(row) { - return this.selectItemsLabel(this.groupIdOptions, row.groupId) + return this.selectItemsLabel(this.groupIdOptions || [], row.groupId) }, // 关系 getLineUserItems() { diff --git a/src/views/admin/line-pre-order/index.vue b/src/views/admin/line-pre-order/index.vue index 90c8b56..ff97e05 100644 --- a/src/views/admin/line-pre-order/index.vue +++ b/src/views/admin/line-pre-order/index.vue @@ -131,14 +131,14 @@ >平仓 - + + + + + - - + --> + + + 取消委托 @@ -476,18 +499,18 @@ /> - - - 现货 - 合约 + + + 现货 + 合约 无对冲 - 现货对合约 - 合约对合约 - + 现货对合约 + 合约对合约 + @@ -624,6 +647,36 @@ placeholder="亏损百分比" /> + + + + + + + @@ -759,7 +830,7 @@ clearable multiple filterable - :remote-method="(e)=>getSymbol(e,2)" + :remote-method="(e)=>getSymbol(e,2,modeForm.exchangeType)" :loading="searchLoding" remote size="small" @@ -778,7 +849,7 @@ layout="prev, pager, next" :page.sync="symbol.pageIndex" :limit.sync="symbol.pageSize" - @pagination="getSymbol($event,2)" + @pagination="getSymbol($event,2,modeForm.exchangeType)" /> @@ -832,6 +903,23 @@ + + + + + @@ -939,6 +1027,24 @@ + + + + + 现货 @@ -980,7 +1086,7 @@ placeholder="请选择交易对" clearable filterable - :remote-method="(e)=>getSymbol(e,positionForm.close_type)" + :remote-method="(e)=>getSymbol(e,positionForm.close_type,positionForm.exchangeType)" :loading="searchLoding" remote size="small" @@ -999,7 +1105,7 @@ layout="prev, pager, next" :page.sync="symbol.pageIndex" :limit.sync="symbol.pageSize" - @pagination="getSymbol($event,2)" + @pagination="getSymbol($event,positionForm.close_type,positionForm.exchangeType)" /> @@ -1018,6 +1124,24 @@ + + + + + - + 现货 合约 @@ -1073,18 +1197,22 @@ export default { ], // :1=现货;2=合约;3=合约止盈;4=合约止损;5=现货止盈;6=现货止损;7=止损补仓;8=现货加仓;9=现货平仓;10 = 合约止损补仓,11=合约加仓;12=合约平仓 orderTypes: [ - { v: 1, l: '现货' }, - { v: 2, l: '合约' }, - { v: 3, l: '合约止盈' }, - { v: 4, l: '合约亏损' }, - { v: 5, l: '现货止盈' }, - { v: 6, l: '现货亏损' }, - { v: 7, l: '现货对冲' }, - { v: 8, l: '现货加仓' }, - { v: 9, l: '现货平仓' }, - { v: 10, l: '合约对冲' }, - { v: 11, l: '合约加仓' }, - { v: 12, l: '合约平仓' } + { v: 1, l: '主单' }, + { v: 2, l: '止盈' }, + { v: 3, l: '止损' }, + { v: 4, l: '平仓' } + // { v: 1, l: '现货' }, + // { v: 2, l: '合约' }, + // { v: 3, l: '合约止盈' }, + // { v: 4, l: '合约亏损' }, + // { v: 5, l: '现货止盈' }, + // { v: 6, l: '现货亏损' }, + // { v: 7, l: '现货对冲' }, + // { v: 8, l: '现货加仓' }, + // { v: 9, l: '现货平仓' }, + // { v: 10, l: '合约对冲' }, + // { v: 11, l: '合约加仓' }, + // { v: 12, l: '合约平仓' } ], buyer: [ { v: 'BUY', l: '买(多)' }, @@ -1095,17 +1223,27 @@ export default { { v: 0, l: '待触发' }, { v: 1, l: '已触发' }, { v: 2, l: '下单失败' }, - { v: 3, l: '已记录' }, + { v: 3, l: '未知' }, { v: 4, l: '已取消' }, { v: 5, l: '委托中' }, - { v: 6, l: '已平仓' }, - { v: 7, l: '已补单' }, - { v: 8, l: '补单失败' }, - { v: 9, l: '现货已成交' }, - { v: 10, l: '合约已补单' }, - { v: 11, l: '合约补单失败' }, - { v: 12, l: '合约已成交' }, - { v: 13, l: '已开仓' } + { v: 6, l: '已成交' }, + { v: 7, l: '未知' }, + { v: 8, l: '未知' }, + { v: 9, l: '已平仓' } + // { v: 0, l: '待触发' }, + // { v: 1, l: '已触发' }, + // { v: 2, l: '下单失败' }, + // { v: 3, l: '已记录' }, + // { v: 4, l: '已取消' }, + // { v: 5, l: '委托中' }, + // { v: 6, l: '已平仓' }, + // { v: 7, l: '已补单' }, + // { v: 8, l: '补单失败' }, + // { v: 9, l: '现货已成交' }, + // { v: 10, l: '合约已补单' }, + // { v: 11, l: '合约补单失败' }, + // { v: 12, l: '合约已成交' }, + // { v: 13, l: '已开仓' } ], statuss: [ { v: '0', l: '待触发' }, @@ -1184,6 +1322,7 @@ export default { symbolGroups: [], modeForm: {}, modeRules: { + exchangeType: [{ required: true, message: '交易所不能为空', trigger: 'blur' }], api_user_ids: [{ required: true, message: 'api用户不能为空', trigger: 'blur' }] }, mode: { @@ -1195,6 +1334,7 @@ export default { storeOpen: false, storeForm: {}, storeRules: { + exchangeType: [{ required: true, message: '交易所不能为空', trigger: 'blur' }], api_id: [{ required: true, message: 'api用户不能为空', trigger: 'blur' }], symbols: [{ required: true, message: '加仓交易对不能为空', trigger: 'blur' }], value: [{ required: true, message: '加仓数值不能为空', trigger: 'blur' }] @@ -1202,6 +1342,7 @@ export default { positionOpen: false, positionForm: {}, positionRules: { + exchangeType: [{ required: true, message: '交易所不能为空', trigger: 'blur' }], api_id: [{ required: true, message: 'api用户不能为空', trigger: 'blur' }] // symbol: [{ required: true, message: '交易对不能为空', trigger: 'blur' }] }, @@ -1209,6 +1350,7 @@ export default { // 取消委托 cancelOpen: false, cancelForm: { + exchangeType: '', api_id: undefined, order_type: 1, symbol: undefined, @@ -1229,7 +1371,7 @@ export default { return { color: '#f56c6c' } } else if (['已触发', '已平仓', '委托中'].includes(s)) { return { color: '#67c23a' } - } else if (['现货已成交', '已开仓'].includes(s)) { + } else if (['现货已成交', '已开仓', '已成交'].includes(s)) { return { color: '#e6a23c' } } else { return {} @@ -1238,8 +1380,8 @@ export default { } }, watch: { - 'form.order_type'(newValue) { - if (newValue === '1') { + 'form.symbol_type'(newValue) { + if (newValue === 1) { this.form.cover_type = 1 } else { this.form.cover_type = 2 @@ -1247,7 +1389,7 @@ export default { this.form.symbol_group_id = undefined this.form.symbol = undefined this.getSymbol({}) - this.getSymbolGroup(this.form.cover_type) + this.getSymbolGroup(this.form.cover_type, this.form.exchange_type) }, 'form.cover_type'(newValue) { if (newValue === 3) { @@ -1282,6 +1424,23 @@ export default { }) }, methods: { + exchangeTypeFormat(row) { + return this.selectDictLabel(this.exchangeTypes || [], row.exchangeType) + }, + onChangePosition() { + this.getLineApiUserItems(this.positionForm.exchangeType) + this.$set(this.positionForm, 'symbol', undefined) + this.getSymbol({}, this.positionForm.close_type, this.positionForm.exchangeType) + }, + onChangeCancel() { + this.cancelForm.api_id = undefined + this.getLineApiUserItems(this.cancelForm.exchangeType) + }, + onchangeMode() { + this.getListLineApiUser(this.modeForm.exchangeType) + this.getSymbol({}, 2, this.modeForm.exchangeType) + this.getSymbolGroup(2, this.modeForm.exchangeType) + }, onSelectAll() { if (this.form.api_id && this.form.api_id.length > 0) { this.form.api_id = [] @@ -1297,19 +1456,19 @@ export default { this.modeForm.api_user_ids = this.lineUsers.map(item => item.id) }, // 获取杠杆api用户 - getListLineApiUser() { - listLineApiUser({ pageIndex: 1, pageSize: 999, exchangeType: this.form.exchangeType }).then(response => { + getListLineApiUser(exchangeType) { + listLineApiUser({ pageIndex: 1, pageSize: 999, exchangeType: exchangeType || this.form.exchange_type }).then(response => { this.lineUsers = response.data.list this.lineTotal = response.data.count }) }, // 交易对列表 - getSymbol(e, type) { + getSymbol(e, type, exchangeType) { this.searchLoding = true const { pageIndex } = this.symbol const symbol = typeof e === 'object' ? '' : e const apiCall = this.title === '添加委托管理' && ([1, 3].includes(this.form.cover_type)) ? getSameSymbol : listLineSymbol - apiCall({ pageIndex, pageSize: 6, type: type || this.form.order_type, symbol, exchangeType: this.form.exchangeType }).then(res => { + apiCall({ pageIndex, pageSize: 6, type: type || this.form.order_type, symbol, exchangeType: exchangeType || this.form.exchange_type }).then(res => { this.symbol.total = res.data.count this.symbol.symbolList = res.data.list }).finally(() => { @@ -1317,8 +1476,9 @@ export default { }) }, // 获取交易对组 - getSymbolGroup(type = 2) { - listLineSymbolGroup({ pageIndex: 1, pageSize: 999, beginTime: undefined, endTime: undefined, type, exchangeType: this.form.exchangeType }).then(res => { + getSymbolGroup(type = 2, exchangeType) { + console.log(type, exchangeType, '??') + listLineSymbolGroup({ pageIndex: 1, pageSize: 999, beginTime: undefined, endTime: undefined, type, exchangeType: exchangeType || this.form.exchange_type }).then(res => { this.symbolGroups = res.data.list }) }, @@ -1400,6 +1560,7 @@ export default { onPosition() { this.title = '' this.positionForm = { + exchangeType: this.exchangeTypes.length ? this.exchangeTypes[0].value : '', api_id: undefined, symbol: undefined, rate: '0', @@ -1412,6 +1573,7 @@ export default { positionCancel() { this.positionOpen = false this.positionForm = { + exchangeType: this.exchangeTypes.length ? this.exchangeTypes[0].value : '', api_id: undefined, symbol: undefined, rate: '0', @@ -1437,6 +1599,7 @@ export default { onStore() { this.title = '' this.storeForm = { + exchangeType: this.exchangeTypes.length ? this.exchangeTypes[0].value : '', api_id: undefined, cover_account: 1, symbol_type: 1, @@ -1455,6 +1618,7 @@ export default { storeCancel() { this.storeOpen = false this.storeForm = { + exchangeType: this.exchangeTypes.length ? this.exchangeTypes[0].value : '', api_id: undefined, cover_account: 1, symbol_type: 1, @@ -1492,8 +1656,9 @@ export default { this.title = '' this.mode.modeTitle = title this.resetMode() - this.getSymbol({}, 2) - this.getSymbolGroup(2) + this.getListLineApiUser(this.modeForm.exchangeType) + this.getSymbol({}, 2, this.modeForm.exchangeType) + this.getSymbolGroup(2, this.modeForm.exchangeType) this.mode.modeOpen = true }, modeCancel() { @@ -1503,6 +1668,7 @@ export default { // 表单重置 resetMode() { this.modeForm = { + exchangeType: this.exchangeTypes.length ? this.exchangeTypes[0].value : '', api_user_ids: undefined, symbol: undefined, group_id: undefined, @@ -1566,7 +1732,7 @@ export default { buy_price: undefined, site: 'BUY', order_sn: undefined, - order_type: '1', + order_type: 0, cover_rate: undefined, desc: undefined, status: undefined, @@ -1575,6 +1741,11 @@ export default { close_type: undefined, direction: undefined, + symbol_type: 1, + hedge_buy_type: 1, + HedgeBuyTotal: undefined, + HedgeTakeProfit: undefined, + HedgeStopLoss: undefined, exchange_type: this.exchangeTypes.length ? this.exchangeTypes[0].value : '', scale_type: 2, main_order_type: 'LIMIT', @@ -1612,9 +1783,9 @@ export default { return this.selectItemsLabel(this.apiIdOptions, row.apiId) }, // 关系 - getLineApiUserItems() { - this.getItems(getMainUser, undefined).then(res => { - this.apiIdOptions = this.setItems(res, 'id', 'apiName') + getLineApiUserItems(exchangeType) { + this.getItems(getMainUser, { pageSize: 10000, exchangeType: exchangeType || this.form.exchange_type }).then(res => { + this.apiIdOptions = this.setItems(res || [], 'id', 'apiName') }) }, // 文件 @@ -1703,6 +1874,7 @@ export default { onCancel() { this.cancelOpen = true this.$refs.formCancel?.resetFields() + this.cancelForm.exchangeType = this.exchangeTypes.length ? this.exchangeTypes[0].value : '' }, handleCancel(row) { if (typeof row === 'string') {