| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import Long from 'long'
- import { Package40 } from '../../../utils/websocket/package'
- import { FunCode } from '../../../constants/enum/funcode'
- import { QuoteRequest } from './interface'
- import { subscribeListToByteArrary } from './build/encode'
- import { parseSubscribeRsp } from './build/decode'
- import { globalCache } from '../../../stores/index'
- import socket from '../index'
- /**
- * 向行情服务器发送请求
- * @param params
- */
- function quoteServerMiddleware(params: QuoteRequest): Promise<Proto.GoodsQuoteRsp[]> {
- const { Token, LoginID } = globalCache.getValue('loginInfo');
- const content = subscribeListToByteArrary(params.data, Token, Long.fromNumber(LoginID));
- return new Promise((resolve, reject) => {
- socket.sendQuoteServer({
- data: {
- rspCode: FunCode.QuoteSubscribeRsp,
- payload: new Package40(FunCode.QuoteSubscribeReq, content)
- },
- success: (raw) => {
- if (raw.content) {
- parseSubscribeRsp(raw.content).then((res) => {
- resolve(res);
- }).catch((err) => {
- console.warn('报文解析失败', err);
- reject('报文解析失败')
- })
- } else {
- reject('数据异常');
- }
- },
- fail: (err) => {
- console.error('服务器请求失败', err);
- reject(err);
- }
- })
- })
- }
- /**
- * 向行情服务器发送请求
- * @param params
- */
- export function quoteServerRequest(params: QuoteRequest) {
- const { success, fail, complete } = params;
- quoteServerMiddleware(params).then((res) => {
- success && success(res);
- }).catch((msg) => {
- fail && fail({ msg });
- }).finally(() => {
- complete && complete();
- })
- }
|