123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- package lmaxapi
- import "sync/atomic"
- import "errors"
- import "fmt"
- import "time"
- const (
- MsgInit = iota
- MsgGetPosition
- MsgGetPositions
- MsgGetInstrument
- MsgGetInstruments
- MsgGetAccount
- MsgSetTick
- MsgSetOrder
- MsgGetOrders
- MsgSetRejected
- MsgSetAccount
- MsgSetAccountDetails
- MsgSetPosition
- MsgSetInstrument
- MsgSetExchangeRate
- MsgGetExchangeRate
- MsgGetTick
- MsgGetAllTick
- MsgGetInstument
- MsgGetAllInstrument
- MsgShutDown
- MsgMtfBindPrivate
- MsgMtfBindPublic
- MsgTimeout
- MsgEcho
- MsgClose
- MsgSetObStatus
- MsgSetExecution
- MsgSetOneExecution
- MsgCancelOrder
- MsgCloseOrder
- MsgAmendOrder
- MsgPlaceOrder
- MsgCloneAccount
- MsgLog
- MsgLoged
- MsgMatched
- MsgCount
- )
- var msgname = []string{
- "MsgInit",
- "MsgGetPosition",
- "MsgGetPositions",
- "MsgGetInstrument",
- "MsgGetInstruments",
- "MsgGetAccount",
- "MsgSetTick",
- "MsgSetOrder",
- "MsgGetOrders",
- "MsgSetRejected",
- "MsgSetAccount",
- "MsgSetAccountDetails",
- "MsgSetPosition",
- "MsgSetInstrument",
- "MsgSetExchangeRate",
- "MsgGetExchangeRate",
- "MsgGetTick",
- "MsgGetAllTick",
- "MsgGetInstument",
- "MsgGetAllInstrument",
- "MsgShutDown",
- "MsgMtfBindPrivate",
- "MsgMtfBindPublic",
- "MsgTimeout",
- "MsgEcho",
- "MsgClose",
- "MsgSetObStatus",
- "MsgSetExecution",
- "MsgSetOneExecution",
- "MsgCancelOrder",
- "MsgCloseOrder",
- "MsgAmendOrder",
- "MsgPlaceOrder",
- "MsgCloneAccount",
- "MsgLog",
- "MsgLoged",
- "MsgMatched",
- "MsgCount",
- }
- const (
- NeedLog = 1 << iota
- SendAsyn
- Public
- Private
- )
- var ErrTimeout = errors.New("timeout")
- var messageId int64
- type Message struct {
- Type int
- Flag int
- ClientId int64
- Id int64
- Err error
- SendTime int64
- RecvTime int64
- Data interface{}
- Ch chan *Message
- }
- func NewMessage(mtype int, clientId int64, data interface{}, id int64) *Message {
- err := error(nil)
- if id == 0 {
- id = atomic.AddInt64(&messageId, 1)
- }
- if mtype == MsgTimeout {
- err = ErrTimeout
- }
- return &Message{mtype, 0, clientId, id, err, 0, 0, data, nil}
- }
- func (msg *Message) GetId() int64 {
- return msg.Id
- }
- func (msg *Message) Name() string {
- return msgname[msg.Type]
- }
- func (msg *Message) String() string {
- return "[" + msgname[msg.Type] + "]" + fmt.Sprint(msg.Id, msg.Err, msg.Data, msg.SendTime, msg.RecvTime)
- }
- func getTime() int64 {
- return time.Now().UnixNano()
- }
|