admin
2 天以前 ec060ce444cdd1c48a54686cadbc8950478eedcf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    document.addEventListener("DOMContentLoaded", function() {
            //把对象赋值到JS中
            try {
                new QWebChannel(qt.webChannelTransport, function(channel) {
                    window.pyjs = channel.objects.Bridge;
                    console.log("回调成功");
                });
            } catch (e) {
 
            }
        });
 
        $(function() {
            new VConsole();
            var app = new Vue({
                el: "#app",
                data: {
                    account_available_money: 0,
                    delegate_records: [],
                    delegate_records_updatetime: '',
                    delegates: [],//[{id:1,'code_info':["000333","美的集团"],'l_down_cancel_rate':0.3,'deal_big_money_info':[0,10000,0,0,0,100000],left_money:'200万'}],
                    now_timestamp: Date.now(),
                    warning_ids_info: { // ID: 生效时间
                    },
                    last_cancel_rate_dict: { // 上一次的撤单比例
                        // ID: 撤单比例
                    },
                    code_names: {},
                    deal_statistic_info: {},
                },
                mounted: function() {
                    setTimeout(function() {
                        app.get_delegate_list();
                        app.list_delegate_records('');
                    }, 500);
 
                    setInterval(function() {
                        if (is_trade_time()) {
                            app.get_delegate_list();
                        }
                    }, 2000);
 
                    setInterval(function() {
                        app.now_timestamp = Date.now();
                    }, 1000);
 
                    setInterval(function() {
                        if (is_trade_time()) {
                            app.list_delegate_records();
                        }
                    }, 3000);
 
                },
                methods: {
                    refresh_data: function() {
                        http_util.sync_trade_data("delegate_list", function(res) {
                            if (res.code === 0) {
                                layer.msg("刷新成功");
                            } else {
                                layer.msg(res.msg);
                            }
                        });
                        this.get_delegate_list();
                    },
 
                    get_delegate_list: function() {
                        http_util.get_delegated_buy_code_infos(function(res) {
                            if (res.code == 0) {
                                let data = res.data;
                                app.account_available_money = data.account_available_money;
                                app.delegates = data.delegates;
                                // 记录上一次的数据
                                app.delegates.forEach(function(item) {
                                    // if (!(item.id in app.last_cancel_rate_dict)){
                                    //     app.last_cancel_rate_dict[item.id] = 0;
                                    // }
 
                                    if (item.id in app.last_cancel_rate_dict) {
                                        // 实撤变大
                                        if (item.l_down_watch_indexes_info.current[3] -
                                            app.last_cancel_rate_dict[item.id] >= 5) {
                                            app.warning_ids_info[item.id] = Date.now() +
                                                1000 * 9;
                                            // 变化5%以上才计数
                                            app.last_cancel_rate_dict[item.id] = item
                                                .l_down_watch_indexes_info.current[3]
                                        }
                                        if (item.l_down_watch_indexes_info.current[3] <
                                            app.last_cancel_rate_dict[item.id]) {
                                            // 变小的时候赋值
                                            app.last_cancel_rate_dict[item.id] = item
                                                .l_down_watch_indexes_info.current[3]
                                            delete app.warning_ids_info[item.id];
                                        }
                                    } else {
                                        app.last_cancel_rate_dict[item.id] = item
                                            .l_down_watch_indexes_info.current[3];
                                    }
                                });
                            }
                        });
 
                    },
                    parseMoneyAsW: function(money_str) {
                        if (money_str.indexOf('亿') >= 0) {
                            return parseFloat(money_str.replace("亿", "")) * 10000
                        } else if (money_str.indexOf('万') >= 0) {
                            return parseFloat(money_str.replace("万", ""))
                        } else {
                            return parseFloat(money_str) / 10000
                        }
                    },
                    toMoneyDesc: function(money) {
                        if (Math.abs(money) > 100000000) {
                            return (money / 100000000.0).toFixed(1) + "亿";
                        } else if (Math.abs(money) > 10000) {
                            return (money / 10000.0).toFixed(1) + "万";
                        } else {
                            return money + "";
                        }
                    },
                    update_l_down_cancel_rate: function(item) {
                        // 修改撤单比例
                        let code = item.code_info[0];
                        let prompt_index = layer.prompt({
                            title: 'L后撤单比例修改(保留2位小数:0-2)',
                            formType: 0, //输入框类型,支持0(文本)默认1(密码)2(多行文本)
                            value: '', //初始时的值,默认空字符
                            maxlength: 20, //可输入文本的最大长度,默认500
                            area: ['200px', '150px'], //自定义文本域宽高
                            // 绑定enter事件
                            success: function(layero, index) {
                                $(layero).on('keydown', function(e) {
                                    if (e.keyCode === 13) {
                                        // 绑定enter
                                        var val = $('.layui-layer-input').val();
                                        if (isNaN(val)) {
                                            layer.msg("输入格式有误")
                                            return;
                                        }
                                        let rate = parseFloat(val)
                                        http_util.set_l_down_rate(code, rate,
                                            function(res) {
                                                if (res.code == 0) {
                                                    layer.msg("修改成功")
                                                    layer.close(prompt_index)
                                                    app.get_delegate_list();
                                                } else {
                                                    layer.msg(res.msg)
                                                }
                                            });
                                    }
                                });
                            }
                        }, function(val, index) {
                            if (isNaN(val)) {
                                layer.msg("输入格式有误")
                                return;
                            }
                            let rate = parseFloat(val)
 
                            http_util.set_l_down_rate(code, rate, function(res) {
                                if (res.code == 0) {
                                    layer.msg("修改成功")
                                    layer.close(prompt_index)
                                    app.get_delegate_list();
                                } else {
                                    layer.msg(res.msg)
                                }
                            });
                        });
                    },
 
                    reset_l_down_cancel_rate: function(item) {
                        // 将撤单比例设置和原来一样
                        let code = item.code_info[0];
                        let rate = item.l_down_cancel_rate;
                        http_util.set_l_down_rate(code, rate,
                            function(res) {
                                if (res.code == 0) {
                                    layer.msg("立改成功")
                                    app.get_delegate_list();
                                } else {
                                    layer.msg(res.msg)
                                }
                            });
                    },
 
                    audo_increase_l_down_cancel_rate: function(item) {
                        let code = item.code_info[0];
                        let rate = item.l_down_cancel_rate + 0.1;
                        http_util.set_l_down_rate(code, rate,
                            function(res) {
                                if (res.code == 0) {
                                    layer.msg("变大成功")
                                    app.get_delegate_list();
                                } else {
                                    layer.msg(res.msg)
                                }
                            });
                    },
 
 
                    audo_decrease_l_down_cancel_rate: function(item) {
                        let code = item.code_info[0];
                        let rate = item.l_down_cancel_rate - 0.1;
                        http_util.set_l_down_rate(code, rate,
                            function(res) {
                                if (res.code == 0) {
                                    layer.msg("变小成功")
                                    app.get_delegate_list();
                                } else {
                                    layer.msg(res.msg)
                                }
                            });
                    },
 
 
                    forbiddenBuy: function(item) {
                        let code = item.code_info[0];
                        http_util.do_action_for_code(code, '', 0, function(res) {
 
 
                        });
 
                        this.cancelOrder(item);
                    },
                    cancelOrder: function(item) {
                        let code = item.code_info[0];
                        http_util.cancel_order(code, function() {
                            layer.msg("撤单成功");
                        })
 
 
                    },
                    viewDetail: function(item) {
                        pyjs.add_code_to_ths(item.code_info[0]);
                    },
 
                    open_trade_queue: function(item) {
                        let code = item.code_info[0];
                        let url = window.location.protocol + "//" + window.location.host +
                            "/kp/trade_queue.html?code=" + code;
                        let params = {
                            "url": url,
                            "title": code,
                            "key": "trade_queue",
                            "size": [400, 400]
                        };
                        pyjs.open_webview_window(JSON.stringify(params))
 
                    },
                    open_l2_down_watch_index_overview: function(code, name) {
                        let url = window.location.protocol + "//" + window.location.host +
                            "/kp/l_down_cancel_indexes.html?code=" + code;
                        let params = {
                            "url": url,
                            "title": "L后囊括(" + name + ")",
                            "key": "l_down_watch_index",
                            "size": [400, 400]
                        };
                        pyjs.open_webview_window(JSON.stringify(params))
                    },
                    getOrderStatusDesc: function(orderStatus) {
                        switch (orderStatus) {
                            case 0:
                                return "预埋";
                            case 1:
                                return "未知";
                            case 2:
                                return "交易所已接收";
                            case 3:
                                return "部分成交";
                            case 4:
                                return "全部成交";
                            case 5:
                                return "部成部撤";
                            case 6:
                                return "全部撤单";
                            case 7:
                                return "交易所已拒绝";
                            default:
                                return "发往交易核心";
                        }
 
                    },
                    getReversedDelegateRecords: function() {
                        return this.delegate_records.slice().reverse();
                    },
 
                    list_delegate_records: function() {
                        http_util.list_delegate_records(app.delegate_records_updatetime, function(
                            res) {
                            res = JSON.parse(res);
                            console.log("委托列表", res);
                            if (res.code == 0) {
                                if (res.data.list.length > 0) {
                                    var index_dict = {};
                                    for (var i = 0; i < app.delegate_records.length; i++) {
                                        index_dict[app.delegate_records[i].orderLocalID] = i;
                                    }
                                    res.data.list.forEach(function(e) {
                                        if (e.orderLocalID in index_dict) {
                                            app.$set(app.delegate_records, index_dict[e
                                                .orderLocalID], e);
                                        } else {
                                            app.delegate_records.push(e);
                                        }
                                        app.code_names[e.securityID] = e.securityName;
                                    });
                                }
                                app.delegate_records_updatetime = res.data.update_time;
                            }
                        });
                    },
                }
 
 
            });
 
 
 
        });