Summary of the invention
Aiming at the above defects or improvement requirements of the prior art, the present invention provides a kind of expansible securities market datas
Displaying scheme is transmitted, the program is then to use interpretive program by defining agreement idl file, idl file is translated into correspondence
The actual code of language.The translation tool, protocol fields are numbered in order;It, can be by field name when client request data
The transmission enable bit of the field is set, it is determined whether needs in transmission over networks;Single precision and double-precision floating points are pressed simultaneously
The precision specified in idl file is transformed into integer, then carries out inverse operation automatically in client and obtains original value;When needing to show
When floating number, the source code that client can be generated according to idl file directly acquires precision, show by precision.
To achieve the above object, according to one aspect of the present invention, a kind of expansible securities market data biography is provided
Defeated display methods, comprising:
Document of agreement is defined using interface description language, includes the agreement word of securities market data in the document of agreement
Section;
The document of agreement is translated into the source code of preset language using translater, defines each agreement in the source code
The enable bit of field, and define enable bit setting interface;
Client using enable bit setting interface to needing the protocol fields of request data to carry out enabled setting, and to
Server end initiates request of data, includes the enable bit information of the protocol fields of requested data in the request of data;
Request of data described in the received server-side simultaneously obtains the enable bit information, and the enable bit information is used for institute
It states server and determines that the client needs the protocol fields of request data;
The server end determines the data of client institute request protocol field according to the enable bit information, and to
The client returns to the data of the protocol fields.
In the method for the present invention, by IDL document of agreement, the protocol fields of securities market data are defined, and provide function
Unified request and response structure body is arranged in interface, and body transmits request enable bit in subsequent assistance with this configuration.It then can be with
Using interpretive program, idl file is translated into the actual code of corresponding program language.The method of the present invention can be used in multiple terminals
(including Android, iOS, Windows, Linux, wechat small routine) and it is multilingual (C, C++, Java, Javascript,
ObjectC between), and the expansion field that can be convenient, and selection field transmission is arranged by enable bit.So as to subtract
Few volume of transmitted data, reduces transmission bandwidth.
In one embodiment of the present of invention, the display of the floating number of each protocol fields there is also defined in the document of agreement
Precision further includes having coding function and decoding functions in the source code, and the coding function is used in server end according to respectively
Corresponding floating number is encoded to obtain integer by the display precision of the floating number of protocol fields according to integer mode is snapped to, institute
Decoding functions are stated for returning the integer number decoder according to the display precision of the floating number of each protocol fields in client
Floating number.
In the embodiment of the present invention, by defining the display precision of each field, thus in server to client transmissions data
Before by floating-point encoding at integer, integer is decoded into floating number again after receiving data by client.It thus can be by most
The small coding for occupying the characteristics progress securities market data such as position coding, compression, transmission, decoding subtract to reduce volume of transmitted data
Few transmission bandwidth.
In one embodiment of the present of invention, the client is received and is decoded after obtaining floating number, according to the display essence
Degree shows the floating number in client.
In the embodiment of the present invention, by defining the display precision of each field, when client shows respective field, according to fixed
The display precision of justice is shown.So as to define different display precisions for different application scenarios, convenient for application program
Follow-up maintenance and extension.
In one embodiment of the present of invention, the enable bit setting interface includes the enable bit setting of respective protocol field
Function, client carry out enabled setting to respective protocol field using enable bit setting function.
In the embodiment of the present invention, function can be arranged in number when to server request data in client by enable bit
According to corresponding enable bit is arranged in request, which illustrates the data field that client needs to request, thus different visitors
Family end can request that different enable bits is arranged according to different data requirementss.Volume of transmitted data can either be reduced, transmission is reduced
Bandwidth also facilitates the follow-up maintenance and extension of program.
In one embodiment of the present of invention, the display of the floating number of each protocol fields there is also defined in the document of agreement
Precision further includes having Json coding function and Json decoding functions in the source code, and the Json coding function is for taking
Corresponding floating-point encoding is converted to Json categorical data, institute according to the display precision of the floating number of each protocol fields by business device end
Json decoding functions are stated for the received Json categorical data to be converted into structural body numerical value so as in client in client
End display.
Json coding/decoding function is additionally provided in the embodiment of the present invention, in source code, Json type can be carried out to data
The coding-decoding operation of data, so as to easily meet the needs that the web terminals such as wechat small routine are shown.
In one embodiment of the present of invention, the document of agreement defines quotation, the field that the quotation includes
For one or more below: opening price, closing price, yesterday receive valence, highest price, lowest price, when present value, limit-up valence, limit down valence, at
Friendship volume, exchange hand, five grades of buying price lattice, five grades buy quantity, five grades sell price or five grades are sold quantity.
It in the embodiment of the present invention, is defined for securities market data, especially for big in securities market data
It measures the single precision floating datum used and double-precision floating points has carried out special optimization, reduce transmission bandwidth, the program is simply easy
Understand, suitable for the various scenes for needing to carry out quotation transmission.
In one embodiment of the present of invention, enable bit is defined in the source code and obtains interface, the server end utilizes
The enable bit obtains the enable bit information that interface obtains the request of data.
In the embodiment of the present invention, definition has enable bit to obtain interface in source code, to send receiving client
Request of data after, can by enable bit obtain interface obtain request of data in enable bit information, so that it is determined that client
Need to request the data of which field, so as to return to different numbers to different clients according to the demand of different clients
According to.
It is another aspect of this invention to provide that additionally providing a kind of expansible securities market data transfer display system, packet
Include client and server end, in which:
The client and server end includes source code, wherein the source code is using translater that agreement is literary
Part is translated into preset language and is obtained, and the enable bit of each protocol fields is defined in the source code, and defines enable bit setting interface,
The document of agreement is defined using interface description language, includes the protocol fields of securities market data in the document of agreement;
The client is used for, and is enabled using enable bit setting interface to the protocol fields for needing request data
Setting, and request of data is initiated to server end, it include the enabled of the protocol fields of requested data in the request of data
Position information;
The server end is used for, and is received the request of data and is obtained the enable bit information, the enable bit information
Determine that the client needs the protocol fields of request data for the server;
The server end is used for, according to the data of enable bit information acquisition client institute request protocol field, and
The data of the protocol fields are returned to the client.
In system provided by the present invention, by IDL document of agreement, the protocol fields of securities market data are defined, and mention
Function interface has been supplied, unified request and response structure body are set, body transmits request enable bit in subsequent assistance with this configuration.
Then interpretive program can be used, idl file is translated into the actual code of corresponding program language.The method of the present invention can be used in
Multiple terminals (including Android, iOS, Windows, Linux, wechat small routine) and it is multilingual (C, C++, Java,
Javascript, ObjectC) between, and the expansion field that can be convenient, and selection field is arranged by enable bit and is passed
It is defeated.So as to reduce volume of transmitted data, transmission bandwidth is reduced.
In one embodiment of the present of invention, the display of the floating number of each protocol fields there is also defined in the document of agreement
Precision further includes having coding function and decoding functions in the source code, and the coding function is used in server end according to respectively
Corresponding floating number is encoded to obtain integer by the display precision of the floating number of protocol fields according to integer mode is snapped to, institute
Decoding functions are stated for returning the integer number decoder according to the display precision of the floating number of each protocol fields in client
Floating number.
In one embodiment of the present of invention, the client is received and is decoded after obtaining floating number, according to the display essence
Degree shows the floating number in client.
In general, through the invention it is contemplated above technical scheme is compared with the prior art, have following beneficial to effect
Fruit: the present invention can be used in multiple terminals (including Android, iOS, Windows, Linux, wechat small routine) and multilingual (C, C
++, Java, Javascript, ObjectC) between, according to extendible code field, may be selected field transmission, may specify precision
Display, coding, compression, transmission, decoding and the display that securities market data can be carried out by characteristics such as minimum occupancy position codings.It is special
It is not to have carried out special optimization for the single precision floating datum and double-precision floating points largely used in securities market data, subtracts
Few transmission bandwidth.The program is easily understood, suitable for the various scenes for needing to carry out quotation transmission.
Specific embodiment
In order to make the objectives, technical solutions, and advantages of the present invention clearer, with reference to the accompanying drawings and embodiments, right
The present invention is further elaborated.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, and
It is not used in the restriction present invention.As long as in addition, technical characteristic involved in the various embodiments of the present invention described below
Not constituting a conflict with each other can be combined with each other.
Existing quotation software, generallys use same data-interface, needs in different scenes using different fields,
However identical field is but transmitted by same data-interface, to transmit a large amount of inessential fields.
To solve the above-mentioned problems, as shown in Figure 1, the present invention provides a kind of expansible securities market data transmission is aobvious
Show method, visits method and use interface description language (Interface description language, IDL) document definition security
The protocol fields of market data, and enable bit setting interface is defined, idl file is then translated into various programs using translater
The source code of language.The enable bit of each field is defined in the source code, while defining the enable bit setting function of each field, side
Just code calls the function the field is arranged whether in transmission over networks.Enable bit corresponds to the position of byte, byte each in this way
It may include 8 enable bits.If including 32 fields in the data that some interface returns, and in certain scene, I only needs
Use 4 fields therein.So client request when, close remaining 28 enable bit.After server-side is requested in receiving end, warp
Decoding obtains enable bit, and server-side, according to the setting state of enable bit, only returns to corresponding 4 fields in returned data, from
And greatly save flow.
Specifically, as shown in Figure 1, the present invention provides a kind of expansible securities market datas to transmit display methods, packet
It includes:
S1, document of agreement is defined using interface description language, include the agreement of securities market data in the document of agreement
Field;
IDL is the abbreviation of Interface Description Language, refers to interface description language, is CORBA specification
A part, be the basis of Cross-border congestion management.IDL is a kind of computer language for description of software components interface.IDL passes through
A kind of mode of neutrality describes interface, so that the object that runs in different platform and the program write with different language can be with
It is in communication with each other exchange;For example, a component is write as with C++, another component is write as with Java.IDL is commonly used in far call
Software.In this case, the subject component on different operating system is usually called by remote client terminal, and these are right
As component may be to be write by different computer languages.IDL establishes the bridge communicated between two different operating systems.
Specifically, in embodiments of the present invention, securities market data can be described by IDL, such as is defined IDL and described language
Speech:
The most common request of data that we describe one kind herein in quotation transmission, exactly obtains a collection of stock
Present quotation.It can be seen that we are provided with precision to the floating number in structural body.Function interface is provided simultaneously, and setting is unified
Request and response structure body, the structural body will subsequent assistance transmit request enable bit.The precision is exactly client simultaneously
Display precision.
Specifically, quotation can be defined in the document of agreement, the field that the quotation includes is following
One or more: opening price, closing price, yesterday receive valence, highest price, lowest price, when present value, limit-up valence, limit down valence, transaction value,
Exchange hand, five grades of buying price lattice, five grades buy quantity, five grades sell price or five grades are sold quantity, it is described certainly in practical application scene
Market field is not limited solely to above-mentioned listed field.In embodiments of the present invention, in agreement text in include above-mentioned generation
Field shown in code.
S2, the source code that the document of agreement is translated into preset language using translater, definition is each in the source code
The enable bit of protocol fields, and define enable bit setting interface;
Specifically, for idl file defined in step S1 using translater to translating, are as follows:
struct SecQuote:public Thoth::protocol::Message
{
public:
static::Thoth::protocol::FieldType I_TYPE(){return::Thoth::protocol::
FT_MESSAGE;}
SecQuote():sDtSecCode(""),sSecName(""),fClose(0),fOpen(0),fMax(0),
fMin(0),fNow(0),fAmout(0)
{
}
void SetEnable_sDtSecCode(bool bEnable){xMAP.SetEnable(0,bEnable);}
void SetEnable_sSecName(bool bEnable){xMAP.SetEnable(1,bEnable);}
void SetEnable_fClose(bool bEnable){xMAP.SetEnable(2,bEnable);}
void SetEnable_fOpen(bool bEnable){xMAP.SetEnable(3,bEnable);}
void SetEnable_fMax(bool bEnable){xMAP.SetEnable(4,bEnable);}
void SetEnable_fMin(bool bEnable){xMAP.SetEnable(5,bEnable);}
void SetEnable_fNow(bool bEnable){xMAP.SetEnable(6,bEnable);}
void SetEnable_fAmout(bool bEnable){xMAP.SetEnable(7,bEnable);}
void SetEnable_vBuyp(bool bEnable){xMAP.SetEnable(8,bEnable);}
void SetEnable_vBuyv(bool bEnable){xMAP.SetEnable(9,bEnable);}
void SetEnable_vSellp(bool bEnable){xMAP.SetEnable(10,bEnable);}
void SetEnable_vSellv(bool bEnable){xMAP.SetEnable(11,bEnable);}
PMAP GetEnable(){return xMAP;}
void Encode(Thoth::protocol::BaseOutputStream&os)const
{
::Thoth::protocol::BaseOutputStream ostream(os.getBaseBuffer());
ostream.write((uint16_t)0,sDtSecCode);
ostream.write((uint16_t)1,sSecName);
ostream.write((uint16_t)2,fClose,2);
ostream.write((uint16_t)3,fOpen,2);
ostream.write((uint16_t)4,fMax,2);
ostream.write((uint16_t)5,fMin,2);
ostream.write((uint16_t)6,fNow,2);
ostream.write((uint16_t)7,fAmout,2);
ostream.write((uint16_t)8,vBuyp,2);
ostream.write((uint16_t)9,vBuyv,2);
ostream.write((uint16_t)10,vSellp,2);
ostream.write((uint16_t)11,vSellv,2);
}
void Decode(Thoth::protocol::BaseInputStream&is)
{
::Thoth::protocol::BaseInputStream istream(is.getBaseBuffer());
istream.read((uint16_t)0,sDtSecCode);
istream.read((uint16_t)1,sSecName);
istream.read((uint16_t)2,fClose,2);
istream.read((uint16_t)3,fOpen,2);
istream.read((uint16_t)4,fMax,2);
istream.read((uint16_t)5,fMin,2);
istream.read((uint16_t)6,fNow,2);
istream.read((uint16_t)7,fAmout,2);
istream.read((uint16_t)8,vBuyp,2);
istream.read((uint16_t)9,vBuyv,2);
istream.read((uint16_t)10,vSellp,2);
istream.read((uint16_t)11,vSellv,2);
}
JsonValue EncodeToJson()const
{
JsonValue xJsonValue;
XJsonValue [" sDtSecCode "]=JsonValue::Write (sDtSecCode);
XJsonValue [" sSecName "]=JsonValue::Write (sSecName);
XJsonValue [" fClose "]=JsonValue::Write (fClose, 2);
XJsonValue [" fOpen "]=JsonValue::Write (fOpen, 2);
XJsonValue [" fMax "]=JsonValue::Write (fMax, 2);
XJsonValue [" fMin "]=JsonValue::Write (fMin, 2);
XJsonValue [" fNow "]=JsonValue::Write (fNow, 2);
XJsonValue [" fAmout "]=JsonValue::Write (fAmout, 2);
XJsonValue [" vBuyp "]=JsonValue::Write (vBuyp, 2);
XJsonValue [" vBuyv "]=JsonValue::Write (vBuyv, 2);
XJsonValue [" vSellp "]=JsonValue::Write (vSellp, 2);
XJsonValue [" vSellv "]=JsonValue::Write (vSellv, 2);
return xJsonValue;
}
void DecodeFromJson(const JsonValue&xJsonValue)const
{
xJsonValue.Read(sDtSecCode,2);
xJsonValue.Read(sSecName,2);
xJsonValue.Read(fClose,2);
xJsonValue.Read(fOpen,2);
xJsonValue.Read(fMax,2);
xJsonValue.Read(fMin,2);
xJsonValue.Read(fNow,2);
xJsonValue.Read(fAmout,2);
xJsonValue.Read(vBuyp,2);
xJsonValue.Read(vBuyv,2);
xJsonValue.Read(vSellp,2);
xJsonValue.Read(vSellv,2);
}
public:
PMAP xMAP;
std::string sDtSecCode;
std::string sSecName;
float fClose;
float fOpen;
float fMax;
float fMin;
float fNow;
float fAmout;
vector<float>vBuyp;
vector<float>vBuyv;
vector<float>vSellp;
vector<float>vSellv;
};
In above-mentioned example, the idl file of definition is translated into the source code of C Plus Plus by we, in the c++ file of generation
In, we define such as lower interface:
Interface is arranged in enable bit, and the field is arranged whether in network transmission in such as SetEnable_sDtSecCode;
Enable bit obtains interface, and GetEnable obtains the enable bit of total body;
Coding function, Encode, to other ports such as floating number according to snapping to integer mode encoding and decoding;
Decoding functions, Decode carry out inverse operation to floating number and obtain original value;
Json coding, EncodeToJson convert field according to floating number precision, the web terminals such as small routine are facilitated to show;
Json decoding, DecodeFromJson are converted into structural body numerical value from Json categorical data;
From above-mentioned code as it can be seen that enable bit setting interface includes the enable bit setting function of respective protocol field,
Client carries out enabled setting to respective protocol field using enable bit setting function.
Meanwhile also definition has enable bit to obtain interface in the source code, the server end utilizes the enable bit
Obtain the enable bit information that interface obtains the request of data.
S3, client using enable bit setting interface to needing the protocol fields of request data to carry out enabled setting,
And request of data is initiated to server end, it include the enable bit letter of the protocol fields of requested data in the request of data
Breath;
Specifically, when client is needed to server request data, request is defined by translater and influences structural body,
To which enable bit be arranged.Specifically:
struct QuoteReq:public Thoth::protocol::Message,public Thoth::
protocol::Request
{
public:
QuoteReq()
{
}
void SetRequestPMAP(const PMAP&xPMAP){xMAP.SetRequestPMAP(xPMAP);}
void Encode(Thoth::protocol::BaseOutputStream&os)const
{
::Thoth::protocol::BaseOutputStream ostream(os.getBaseBuffer());
ostream.SetRequestPMAP(xMAP);
ostream.Write((uint16_t)0,vDtSecCode);
}
void Decode(Thoth::protocol::BaseInputStream&is)
{
::Thoth::protocol::BaseInputStream istream(is.getBaseBuffer());
istream.GetRequestPMAP(xMAP);
istream.Read((uint16_t)0,vDtSecCode);
}
public:
PMAP xMAP;
std::vector<std::string>vDtSecCode;
};
struct QuoteRsp:public Thoth::protocol::Message,public Thoth::
protocol::Response{
public:
QuoteRsp()
{
}
void Encode(Thoth::protocol::BaseOutputStream&os)const
{
::Thoth::protocol::BaseOutputStream ostream(os.getBaseBuffer());
ostream.Write((uint16_t)0,vQuote);
}
void Decode(Thoth::protocol::BaseInputStream&is)
{
::Thoth::protocol::BaseInputStream istream(is.getBaseBuffer());
istream.GetRequestPMAP(xMAP);
istream.Read((uint16_t)0,vQuote);
}
public:
std::vector<SecQuote>vQuote;
};
Appealing structure body is inherited in Thoth::protocol::Request, which will carry out volume solution to PMAP enable bit
Code facilitates client transmitting enable bit to server-side.Client encodes enable bit by Encode function.
Request of data described in S4, the received server-side simultaneously obtains the enable bit information, and the enable bit information is used
Determine that the client needs the protocol fields of request data in the server;
After received server-side to the request of data of client, server-side is obtained from network parameter by Decode function
Get PMAP.The enable bit that function GetEnable obtains total body is obtained by enable bit, the enable bit identifies institute
State the protocol fields that client needs request data.When data are transmitted, configured transmission is determined according to enable bit.
S5, the server end determine the data of client institute request protocol field according to the enable bit information,
And the data of the protocol fields are returned to the client.
The requested data of the client are returned to the client by server end.
Further, in existing quotation software, the data transmission of single precision and double precision is fixed to use 4 bytes
With 8 bytes, flow is wasted very much for fractional value floating number.Specifically, in quotation, such as opening price, closing price,
Yesterday receives valence, highest price, lowest price, limit-up valence, limit down valence, exchange hand etc. field, is floating point type.But floating number is in network
It is fixed to generally require 1 or 2 byte transmission i.e. but if transmitting using integer using 4 bytes or 8 bytes when transmission
It can.So server-side is before transmitting the data, and according to the precision specified in agreement, such as numerical value: 12.88, precision: 2, it is converted into
Integer 1288, the original number for needing 8 directly to transmit only need 2 bytes now.The coding/decoding function of server-side is automatic
After conversion, it is sent to client.Number is automatically converted to 12.88, is restored by client according to specified precision.
To achieve the goals above, as shown in the embodiment in step S1 and S2, the method for the present invention is in the document of agreement
In there is also defined each protocol fields floating number display precision, further include having coding function and decoding letter in the source code
Number, the coding function be used for server end according to the display precision of the floating number of each protocol fields by corresponding floating number according to
It snaps to integer mode to be encoded to obtain integer, the decoding functions are used in client according to each protocol fields
The integer number decoder is returned floating number by the display precision of floating number.
In addition it can which Json coding/decoding function is arranged, field can be converted according to floating number precision, facilitate small routine etc.
Web terminal is shown.Specifically, to achieve the goals above, the method for the present invention there is also defined each agreement word in the document of agreement
The display precision of the floating number of section further includes having Json coding function and Json decoding functions in the source code, the Json
Coding function is for converting corresponding floating-point encoding according to the display precision of the floating number of each protocol fields in server end
To Json categorical data, the Json decoding functions are used to that the received Json categorical data to be converted into structure in client
Body numerical value in client to show.
Further, in existing security software, client floating number display precision is unfavorable for subsequent by making an appointment
Extension.To solve the above-mentioned problems, the method for the present invention is shown when showing quotation according to the precision of each field
Show, client can call precision to obtain function and obtain the display precision of each field directly from the translated document of IDL at this time,
To be shown in client.Specifically, the method for the present invention further include:
S6, the client are received and are decoded after obtaining floating number, shown according to the display precision in client described in
Floating number.
Further, as shown in Fig. 2, the process for expansible securities market data processing a kind of in the embodiment of the present invention is shown
It is intended to, defines idl file first, define the protocol fields for having securities market data and corresponding display precision in idl file,
Then idl file is translated by interpretive program the source file of corresponding language, and realize enable bit handling function, user is in visitor
Enable bit is arranged by enable bit handling function in the end of family, and carries out enable bit coding, so that appealing structure body is generated, the request
Structural body is decoded appealing structure body by network data transmission to server end, server end, and carries out to enable bit
Decoding, to read the initial data of respective field according to enable bit, server end carries out conversion life to floating number according to precision
At integer, coding is carried out then to send the data to client.
Further, as shown in figure 3, the present invention also provides a kind of expansible securities market data transmission display systems
System, including client and server end, in which:
The client and server end includes source code, wherein the source code is using translater that agreement is literary
Part is translated into preset language and is obtained, and the enable bit of each protocol fields is defined in the source code, and defines enable bit setting interface,
The document of agreement is defined using interface description language, includes the protocol fields of securities market data in the document of agreement;
The client is used for, and is enabled using enable bit setting interface to the protocol fields for needing request data
Setting, and request of data is initiated to server end, it include the enabled of the protocol fields of requested data in the request of data
Position information;
The server end is used for, and is received the request of data and is obtained the enable bit information, the enable bit information
Determine that the client needs the protocol fields of request data for the server;
The server end is used for, according to the data of enable bit information acquisition client institute request protocol field, and
The data of the protocol fields are returned to the client.
Further, the display precision of the floating number of each protocol fields, the source be there is also defined in the document of agreement
It further include having coding function and decoding functions in code, the coding function is used in server end according to the floating of each protocol fields
Corresponding floating number is encoded to obtain integer by the display precision of points according to integer mode is snapped to, and the decoding functions are used
In the integer number decoder is returned floating number according to the display precision of the floating number of each protocol fields in client.
Further, the client is received and is decoded after obtaining floating number, aobvious in client according to the display precision
Show the floating number.
As it will be easily appreciated by one skilled in the art that the foregoing is merely illustrative of the preferred embodiments of the present invention, not to
The limitation present invention, any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should all include
Within protection scope of the present invention.