Browse Source

该当

master
lizhixin 4 years ago
parent
commit
00c25ed423
  1. 424
      src/pages/MainSec/OrderTable.vue
  2. 154
      src/pages/MainSec/SignalTable.vue
  3. 16
      src/pages/MainSec/index.vue
  4. 32
      src/pages/ReCheck/OrderTable.vue
  5. 15
      src/pages/ReCheck/index.vue
  6. 24
      src/pages/RobotSec/Account.vue
  7. 4
      src/pages/RobotSec/Modal/RobotSetting.vue
  8. 4
      src/utils/plugin/axios-plugin.js

424
src/pages/MainSec/OrderTable.vue

@ -1,132 +1,140 @@
<template>
<div>
<el-table :data="data" height="600" class="customer-no-border-table">
<el-table-column
v-for="i in columns"
:label="i.name"
:prop="i.prop"
:key="i.prop"
>
<template slot-scope="scope">
<!-- 卖卖类型 -->
<div v-if="i.customSlot == 'OrderType'">
<p>买入</p>
<p>卖出</p>
</div>
<!-- 手持资金 -->
<div v-else-if="i.customSlot == 'CapitalAfter'">
<p>{{ scope.row.CapitalAfterPurchase.toFixed(2) || 0 }}</p>
<p>{{ scope.row.CapitalAfterSale.toFixed(2) || 0 }}</p>
</div>
<!-- 买卖时间 -->
<div v-else-if="i.customSlot == 'KLineId'">
<p>
{{
scope.row.PurchaseKLineId
? moment(scope.row.PurchaseKLineId * 1000).format(
"YYYY-MM-DD HH:mm:ss"
)
: "-"
}}
</p>
<p>
{{
scope.row.SaleKLineId
? moment(scope.row.SaleKLineId * 1000).format(
"YYYY-MM-DD HH:mm:ss"
)
: "-"
}}
</p>
</div>
<!-- 买卖价格 -->
<div v-else-if="i.customSlot == 'Price'">
<p>{{ scope.row.PurchasePrice }}</p>
<p>{{ scope.row.SalePrice }}</p>
</div>
<!-- 买卖数量 -->
<div v-else-if="i.customSlot == 'Count'">
<p>{{ scope.row.PurchaseCoinCount || "-" }}</p>
<p>{{ scope.row.SaleCoinCount || "-" }}</p>
</div>
<!-- 成交总价 -->
<div v-else-if="i.customSlot == 'Total'">
<p>{{ scope.row.TotalPurchasePrice || "-" }}</p>
<p>{{ scope.row.TotalSalePrice || "-" }}</p>
</div>
<!-- 借币金额 -->
<div v-else-if="i.customSlot == 'BorrowAmount'">
<p>{{ scope.row.BorrowAmount.toFixed(2) || "-" }}</p>
</div>
<!-- 借币利息 -->
<div v-else-if="i.customSlot == 'BorrowFee'">
<p>{{ scope.row.BorrowFee.toFixed(2) || "-" }}</p>
</div>
<!-- 借币比例 -->
<div v-else-if="i.customSlot == 'BorrowRatio'">
<p>{{ scope.row.BorrowRatio.toFixed(2) || "-" }}%</p>
</div>
<!-- 最大浮亏 -->
<div v-else-if="i.customSlot == 'MaxLossRatio'">
<p>{{ scope.row.MaxLossPrice || "-" }}</p>
<p>{{ scope.row.MaxLossRatio || "-" }}%</p>
</div>
<!-- 盈亏 -->
<div v-else-if="i.customSlot == 'Profit'">
<p>{{ scope.row.Profit }}</p>
<p v-if="scope.row.Profit">
{{
(
(scope.row.Profit / scope.row.TotalPurchasePrice) *
100
).toFixed(2)
}}%
</p>
<p v-else>-</p>
</div>
<!-- 累计盈亏 -->
<div v-else-if="i.customSlot == 'TotalProfit'">
<p>{{ scope.row.TotalProfit }}</p>
<p v-if="scope.row.TotalProfit">
{{ scope.row.TotalProfitRatio }}%
</p>
<p v-else>-</p>
</div>
<div v-else>
<p>{{ scope.row[i.prop] }}</p>
</div>
</template>
</el-table-column>
</el-table>
<el-pagination
small
:hide-on-single-page="true"
layout="prev, pager, next"
:total="historyOrdersPagination.total"
:page-size="historyOrdersPagination.pageSize"
:current-page="historyOrdersPagination.current"
>
</el-pagination>
</div>
<card>
<el-tabs v-model="activeName">
<el-tab-pane label="历史订单" name="first">
<custom-base-table
:data="historyOrders"
:columns="OrderColumns.filter(item => !item.hidden)"
thead-classes="text-primary"
></custom-base-table>
<el-pagination
small
:hide-on-single-page="true"
layout="prev, pager, next"
:total="historyOrdersPagination.total"
:page-size="historyOrdersPagination.pageSize"
:current-page="historyOrdersPagination.current"
>
</el-pagination>
</el-tab-pane>
<el-tab-pane label="持仓订单" name="second">
<custom-base-table
:data="nowOrders"
:columns="OrderColumns"
thead-classes="text-primary"
></custom-base-table>
</el-tab-pane>
</el-tabs>
<card>
<h5 slot="header" class="title">账号配置信息</h5>
<div class="row">
<div class="col-md-3">
<base-input v-model="basic.CoinCount" label="持币数量" disabled>
</base-input>
</div>
<div class="col-md-3">
<base-input
v-model="basic.TotalPurchasePrice"
label="持仓总价"
disabled
>
</base-input>
</div>
<div class="col-md-3">
<base-input
v-model="basic.AvgPurchasePrice"
label="持仓均价"
disabled
>
</base-input>
</div>
<div class="col-md-3">
<base-input
v-model="basic.TotalPurchasePriceRatio"
label="持仓占比(%)"
disabled
>
</base-input>
</div>
<div class="col-md-3">
<base-input v-model="basic.FloatingPL" label="浮动盈亏(%)" disabled>
</base-input>
</div>
<div class="col-md-3">
<base-input
v-model="basic.TotalPurchasePriceProfit"
label="浮动持仓利润(已预扣手续费)"
disabled
>
</base-input>
</div>
<div class="col-md-3">
<base-input
v-model="basic.TotalProfit"
label="总利润(已预扣手续费)"
disabled
>
</base-input>
</div>
<div class="col-md-3">
<base-input v-model="basic.NewestPrice" label="最新成交价" disabled>
</base-input>
</div>
</div>
</card>
</card>
</template>
<script>
import { secondTradeColumns } from "../prePages/js/columns";
import { OrderColumns } from "../../pages/prePages/js/columns";
import CustomBaseTable from "../../components/CustomBaseTable";
import Bus from "../../common/bus";
import {
sendSock,
initWebSocket,
closeWebSocket
} from "../../utils/plugin/socket";
const S_PING = 100;
const R_PONG = 101;
const SUBSCRIBE = 102;
const ACCOUNT_INFO = 103;
const ORDER_PUBLISH = 104;
const TRADE_LOG = 105;
export default {
components: { CustomBaseTable },
props: {
robotId: { type: String, default: "" }
RobotId: { type: String, default: "60521323-28C3-AC14-0076-48B075584510" }
},
data() {
return {
columns: secondTradeColumns,
data: [],
historyOrdersPagination: { current: 1, pageSize: 15 }
activeName: "first",
OrderColumns,
historyOrders: [],
nowOrders: [],
basic: {},
historyOrdersPagination: { current: 1, pageSize: 15 },
pingInterval: null
};
},
mounted() {},
created() {
this.initOrders(); //
},
mounted() {
console.log("connecting");
this.initWs(); //ws
},
beforeDestroy() {
closeWebSocket();
localStorage.clear();
clearInterval(this.pingInterval);
},
methods: {
initOrders() {
this.initHistoryOrders();
@ -163,7 +171,185 @@ export default {
this.nowOrders = res.Data;
}
});
},
initWs() {
let that = this;
initWebSocket("ws://trapi.iheyinet.com").then(
rs => {
//
sendSock(
{
Notify: SUBSCRIBE,
RobotId: this.RobotId
},
that.wsCb
);
//ping
that.pingIntervalKeeper();
},
rj => {
that.$message.error("连接websocket失败,正在重连");
that.initWs();
}
);
},
wsCb(data) {
console.log("ws received", data);
if (data && data.Notify == ACCOUNT_INFO) {
this.dealAccountInfo(data);
} else if (data && data.Notify == ORDER_PUBLISH) {
this.dealOrder(data);
} else if (data && data.Notify == R_PONG) {
this.dealPong(data);
} else if (data && data.Notify == TRADE_LOG) {
Bus.$emit("tradeLog", data);
}
},
pingPkg() {
console.log("心跳包检测发送");
let timeStamp = Date.now();
let that = this;
sendSock(
{
Notify: S_PING,
TimeStamp: timeStamp
},
that.wsCb
);
localStorage.setItem("pingTimeStamp", timeStamp);
if (!localStorage.getItem("missPkg")) {
localStorage.setItem("missPkg", 1);
} else {
let missPkgCount = parseInt(localStorage.getItem("missPkg")) + 1;
localStorage.setItem("missPkg", missPkgCount);
console.log("丢包次数增加1", missPkgCount);
if (missPkgCount > 3) {
/**
* 1.停止ping包interval
* 2.关闭ws
* 3.重新获取订单列表
*/
console.log("达到丢包次数", missPkgCount);
clearInterval(this.pingInterval);
localStorage.clear();
closeWebSocket();
this.initOrders();
this.initWs();
}
}
},
//ping
pingIntervalKeeper() {
let that = this;
that.pingPkg();
this.pingInterval = setInterval(() => {
that.pingPkg();
}, 30000);
},
//pong
dealPong(data) {
//pongtimeStamp-1
let timeStamp = localStorage.getItem("pingTimeStamp");
let missPkgCount = parseInt(localStorage.getItem("missPkg"));
if (data.TimeStamp == timeStamp) {
missPkgCount--;
console.log("丢包次数减少1", missPkgCount);
localStorage.setItem("missPkg", missPkgCount);
}
},
//
dealAccountInfo(data) {
this.basic = { ...this.basic, ...data };
if (
this.nowOrders.length > 0 &&
data.NewestPrice &&
data.NewestPrice != 0
) {
this.nowOrders.forEach(item => {
let totalSalePrice = data.NewestPrice * item.PurchaseCoinCount; //
let saleFee = totalSalePrice * 0.02; //
let Profit =
totalSalePrice -
item.TotalPurchasePrice -
saleFee -
item.PurchaseFee;
item.Profit = Profit.toFixed(5); //
item.UnstableProfit = (
(data.NewestPrice / item.PurchasePrice - 1) *
100
).toFixed(5); //
// console.log(item.UnstableProfit, "");
});
}
},
//
dealOrder(data) {
//4|| 6
let targetIndex = -1;
for (let i = 0; i < this.nowOrders.length; i++) {
if (data.Id == this.nowOrders[i].Id) {
targetIndex = i;
break;
}
}
if (targetIndex == -1) {
this.nowOrders.push(data);
} else {
this.nowOrders[targetIndex] = {
...this.nowOrders[targetIndex],
...data
};
if (data.Status == 4 || data.Status == 6) {
this.nowOrders.splice(targetIndex, 1);
if (this.historyOrdersPagination.current == 1)
this.initHistoryOrders();
}
}
},
statusRender(status) {
switch (status) {
case 0:
return "已挂买单市价";
case 1:
return "已挂买单限价";
case 2:
return "部分购买";
case 3:
return "已购买";
case 4:
return "部分购买被撤销";
case 5:
return "购买被撤销";
case 6:
return "已挂卖单市价";
case 7:
return "已挂卖单限价";
case 8:
return "部分卖出";
case 9:
return "已卖出";
case 10:
return "部分卖出已撤销";
case 11:
return "卖出已撤销";
}
}
}
};
</script>
<style>
.el-pagination button:disabled {
background-color: transparent;
}
.el-pager li {
background-color: transparent;
}
</style>

154
src/pages/MainSec/SignalTable.vue

@ -1,40 +1,148 @@
<template>
<div>
<el-table :data="data" class="customer-no-border-table">
<el-table-column
v-for="i in secondLogColumns"
:label="i.name"
:prop="i.prop"
:key="i.prop"
>
<template slot-scope="scope">
<div v-if="i.customSlot == 'OrderType'"></div>
<div v-else>
<p>{{ scope.row[i.prop] }}</p>
</div>
</template>
</el-table-column>
</el-table>
</div>
<custom-base-table
:data="data"
:columns="columns"
thead-classes="text-primary"
>
<template slot="LogType" slot-scope="item">
{{ typeRender(item.row.item.LogType) }}
</template>
</custom-base-table>
</template>
<script>
import { secondLogColumns } from "../prePages/js/columns";
import Bus from "../../common/bus";
import CustomBaseTable from "../../components/CustomBaseTable";
import moment from "moment";
export default {
props: {
robotId: { type: String, default: "" }
RobotId: { type: String, default: "60521323-28C3-AC14-0076-48B075584510" }
},
components: { CustomBaseTable },
data() {
return {
secondLogColumns,
data: []
columns: [
{ name: "RobotId", prop: "RobotId" },
{ name: "内容", prop: "Content" },
{
name: "日志类型",
prop: "LogType",
customSlot: "LogType"
},
{
name: "订单Id",
prop: "SpotGoodsOrderId"
},
{ name: "创建时间", prop: "CreateTime" }
],
data: [],
noMoreData: false,
endTime: null,
scrollInstance: null,
nullPlusTime: 0
};
},
created() {
let endTime = moment();
this.endTime = endTime;
this.getLatestLog(endTime);
},
mounted() {
this.init();
Bus.$on("tradeLog", data => {
console.log(data, "received from ws Bus");
this.data.unshift(data);
});
this.initScroller();
},
destroyed() {
if (this.scrollInstance)
this.scrollInstance.removeEventListener("scroll", this.scrollerListener);
},
methods: {
init() {}
initScroller() {
let target = document.getElementById("tradeLog");
this.scrollInstance = target;
this.scrollInstance.addEventListener(
"scroll",
this.scrollerListener,
false
);
},
getPreday() {},
scrollerListener() {
// console.log(
// this.scrollInstance.scrollTop,
// this.scrollInstance.scrollHeight,
// this.scrollInstance.clientHeight
// );
if (
this.scrollInstance.scrollTop + this.scrollInstance.clientHeight ==
this.scrollInstance.scrollHeight
) {
if (!this.spinning && !this.noMoreData) this.getLatestLog(this.endTime);
}
},
typeRender(logType) {
switch (logType) {
case 0:
return "买入";
case 1:
return "卖出";
case 2:
return "做多";
case 3:
return "做空";
case 4:
return "大趋势看多";
case 5:
return "大趋势看空";
case 10:
return "自动卖出";
}
},
getLatestLog(endTime) {
this.spinning = true;
let _endTime = endTime.format("YYYY-MM-DD HH:mm:ss");
this.$http
.get(
`/Api/ExecutionLog/GetList?robotId=${this.RobotId}&endTime=${_endTime}`
)
.then(res => {
this.spinning = false;
if (res.Code == 200) {
if (res.Data.length > 0) {
if (this.data.length > 0) {
res.Data.forEach(item => this.data.push(item));
this.endTime = moment(
this.data[this.data.length - 1].CreateTime
);
} else {
this.data = res.Data;
}
} else {
this.noMoreData = true;
this.sMessage("danger", "已经没有更多日志了");
}
}
});
},
// showNotification
sMessage(type, message) {
this.$notify({
type: type,
message,
timeout: 1800
});
}
}
};
</script>
<style scoped></style>

16
src/pages/MainSec/index.vue

@ -2,8 +2,12 @@
<div>
<el-tabs value="1">
<el-tab-pane name="1" label="概况"> <Summary /></el-tab-pane>
<el-tab-pane name="2" label="交易清单"><OrderTable /> </el-tab-pane>
<el-tab-pane name="3" label="信号日志"> <SignalTable /></el-tab-pane>
<el-tab-pane name="2" label="交易清单"
><OrderTable :RobotId="RobotId" />
</el-tab-pane>
<el-tab-pane name="3" label="信号日志">
<SignalTable :RobotId="RobotId"
/></el-tab-pane>
<el-tab-pane name="4" label="资金日志"> </el-tab-pane>
</el-tabs>
</div>
@ -18,6 +22,14 @@ export default {
OrderTable,
SignalTable,
Summary
},
data() {
return {
RobotId: ""
};
},
created() {
this.RobotId = this.$route.params.id;
}
};
</script>

32
src/pages/ReCheck/OrderTable.vue

@ -33,8 +33,20 @@
</div>
<!-- 手持资金 -->
<div v-else-if="i.customSlot == 'CapitalAfter'">
<p>{{ scope.row.CapitalAfterPurchase.toFixed(2) || 0 }}</p>
<p>{{ scope.row.CapitalAfterSale.toFixed(2) || 0 }}</p>
<p>
{{
(scope.row.CapitalAfterPurchase &&
scope.row.CapitalAfterPurchase.toFixed(2)) ||
0
}}
</p>
<p>
{{
(scope.row.CapitalAfterSale &&
scope.row.CapitalAfterSale.toFixed(2)) ||
0
}}
</p>
</div>
<!-- 买卖时间 -->
<div v-else-if="i.customSlot == 'KLineId'">
@ -74,18 +86,22 @@
</div>
<!-- 借币金额 -->
<div v-else-if="i.customSlot == 'BorrowAmount'">
<p>{{ scope.row.BorrowAmount.toFixed(2) || "-" }}</p>
<div v-else-if="i.customSlot == 'LoanAmount'">
<p>
{{ scope.row.LoanAmount.toFixed(2) || "-" }}
</p>
</div>
<!-- 借币利息 -->
<div v-else-if="i.customSlot == 'BorrowFee'">
<p>{{ scope.row.BorrowFee.toFixed(2) || "-" }}</p>
<div v-else-if="i.customSlot == 'LoanFee'">
<p>
{{ scope.row.LoanFee.toFixed(2) || "-" }}
</p>
</div>
<!-- 借币比例 -->
<div v-else-if="i.customSlot == 'BorrowRatio'">
<p>{{ scope.row.BorrowRatio.toFixed(2) || "-" }}%</p>
<div v-else-if="i.customSlot == 'LoanRatio'">
<p>{{ scope.row.LoanRatio.toFixed(2) || "-" }}%</p>
</div>
<!-- 最大浮亏 -->

15
src/pages/ReCheck/index.vue

@ -139,10 +139,13 @@
></base-input>
<base-input v-model="vTForm.Balance" label="账户余额"></base-input>
<base-input
v-model="vTForm.MaxBorrowRatio"
v-model="vTForm.MaxLoanRatio"
label="最大借币比例"
></base-input>
<base-input
v-model="vTForm.MaxFollowPurchaseRatio"
label="限制追高比例"
></base-input>
<div>
<base-checkbox inline v-model="vTForm.IsEnableAdditionalQuantity">
启用增购
@ -279,8 +282,9 @@ export default {
TradeCoinCount: 10,
IsEnableAdditionalQuantity: false,
Balance: 10000,
MaxBorrowRatio: 20,
IsEnableRemedyForErrorCrossSignal: false
MaxLoanRatio: 20,
IsEnableRemedyForErrorCrossSignal: false,
MaxFollowPurchaseRatio: 20
},
logData: [],
PositionFund: 1,
@ -797,10 +801,11 @@ export default {
TradeCoinCount: parseFloat(this.vTForm.TradeCoinCount),
IsEnableAdditionalQuantity: this.vTForm
.IsEnableAdditionalQuantity,
MaxBorrowRatio: this.vTForm.MaxBorrowRatio,
MaxLoanRatio: this.vTForm.MaxLoanRatio,
Balance: this.vTForm.Balance,
IsEnableRemedyForErrorCrossSignal: this.vTForm
.IsEnableRemedyForErrorCrossSignal,
MaxFollowPurchaseRatio: this.vTForm.MaxFollowPurchaseRatio,
SymbolList: newExcelData
}
: {

24
src/pages/RobotSec/Account.vue

@ -22,6 +22,7 @@
:key="item.props"
:label="item.label"
:prop="item.props"
:width="item.width"
></el-table-column>
<el-table-column>
<base-button>删除</base-button>
@ -50,9 +51,6 @@
>
<base-button>操作</base-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="apiKeyVisible"
>添加API Key</el-dropdown-item
>
<el-dropdown-item command="moneyVisible"
>资金划转</el-dropdown-item
>
@ -314,19 +312,19 @@
const MainColumns = [
{ label: "登录名", props: "LoginName" },
{ label: "UID", props: "UID" },
{ label: "账户类型", props: "AccountType" },
{ label: "账户余额", props: "Balance" },
{ label: "保底运营资金", props: "Balance1" },
{ label: "可转资金", props: "account5" },
{ label: "交易所借款金额", props: "account6" }
{ label: "账户类型", props: "AccountType", width: 200 },
{ label: "账户余额", props: "Balance", width: 200 },
{ label: "保底运营资金", props: "Balance1", width: 200 },
{ label: "可转资金", props: "account5", width: 200 },
{ label: "交易所借款金额", props: "account6", width: 200 }
];
const SubColumns = [
{ label: "API Key", props: "AccessKey" },
{ label: "交易对", props: "Symbol" },
{ label: "账户余额", props: "Balance" },
{ label: "保底运营资金", props: "MinimumWorkingCapital" },
{ label: "可转资金", props: "RobotId" }
{ label: "API Key", props: "AccessKey", width: 370 },
{ label: "交易对", props: "Symbol", width: 200 },
{ label: "账户余额", props: "Balance", width: 190 },
{ label: "保底运营资金", props: "MinimumWorkingCapital", width: 190 },
{ label: "可转资金", props: "R", width: 200 }
];
import { Modal } from "@/components";

4
src/pages/RobotSec/Modal/RobotSetting.vue

@ -25,6 +25,10 @@
label="初始交易量"
v-model="form.TradeCoinCount"
></base-input>
<base-input
label="限制追高比例"
v-model="form.MaxFollowPurchaseRatio"
></base-input>
<span class="form-label">交易周期</span>
<el-select

4
src/utils/plugin/axios-plugin.js

@ -1,9 +1,9 @@
/* eslint-disable */
import axios from "axios";
// const rootUrl = "http://58.23.153.12:88/"; //test
const rootUrl = "http://58.23.153.12:88/"; //test
const rootUrl = "http://trapi.iheyinet.com"; //latest
// const rootUrl = "http://trapi.iheyinet.com"; //latest
const Axios = axios.create({
baseURL: rootUrl,

Loading…
Cancel
Save