gocgate

package module
v0.0.0-...-777496b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2026 License: LGPL-2.1 Imports: 14 Imported by: 0

README

GoCGate

An unofficial Golang implementation of Moex Plaza II protocol.

It's under active development, do not use it, please.

Documentation

Index

Constants

View Source
const (
	CG_OK               = 0
	CG_EINTERNAL        = 0x20000
	CG_EINVALIDARGUMENT = 0x20001
	CG_EUNSUPPORTED     = 0x20002
	CG_ETIMEOUT         = 0x20003
	CG_EMORE            = 0x20004
	CG_EINCORRECTSTATE  = 0x20005
	CG_EDUPLICATEID     = 0x20006
	CG_EBUFFERTOOSMALL  = 0x20007
	CG_EOVERFLOW        = 0x20008
	CG_EUNDERFLOW       = 0x20009
	CG_EOF              = 0x20010
	CG_ERANGEE_END      = 0x20011
)

Errors

View Source
const (
	CG_STATE_CLOSED  = 0
	CG_STATE_ERROR   = 1
	CG_STATE_OPENING = 2
	CG_STATE_ACTIVE  = 3
)

Connection states

View Source
const (
	CG_MSG_OPEN        = 0x100
	CG_MSG_CLOSE       = 0x101
	CG_MSG_TIME        = 0x102
	CG_MSG_DATA        = 0x110
	CG_MSG_STREAM_DATA = 0x120
	CG_MSG_DATAARRAY   = 0x150
	CG_MSG_OBJFAILED   = 0x180
	CG_MSG_PARSEERR    = 0x190

	CG_MSG_TN_BEGIN    = 0x200
	CG_MSG_TN_COMMIT   = 0x210
	CG_MSG_TN_ROLLBACK = 0x220

	CG_MSG_P2MQ_RANGE_START = 0x1000
	CG_MSG_P2MQ_TIMEOUT     = 0x1001

	CG_MSG_P2REPL_RANGE_START  = 0x1100
	CG_MSG_P2REPL_LIFENUM      = 0x1110
	CG_MSG_P2REPL_CLEARDELETED = 0x1111
	CG_MSG_P2REPL_ONLINE       = 0x1112
	CG_MSG_P2REPL_REPLSTATE    = 0x1115
)

Message types

View Source
const (
	CG_SESS_ASSIGNED   = 0
	CG_SESS_ACTIVE     = 1
	CG_SESS_SUSPENDED  = 2
	CG_SESS_TERMINATED = 3
	CG_SESS_CLOSED     = 4
)

Session states

View Source
const (
	CG_REASON_UNDEFINED     = 0
	CG_REASON_USER          = 1
	CG_REASON_ERROR         = 2
	CG_REASON_DONE          = 3
	CG_REASON_SNAPSHOT_DONE = 4
)

Reasons

View Source
const (
	CG_BUY  = 1
	CG_SELL = 2
)

Order directions

View Source
const (
	CG_STYPE_FUT = 0x200   // futures
	CG_STYPE_CFD = 0x4000  // contract for difference
	CG_STYPE_SPR = 0x10000 // spread
	CG_STYPE_CLT = 0x40000 // collateral
)

Security types

View Source
const (
	CG_OSTATE_DEL     = 0
	CG_OSTATE_ACTIVE  = 1
	CG_OSTATE_FILLED  = 2
	CG_OSTATE_NEWPART = 3 //  Заявка добавлена в результате появления новой видимой части айсберга
)

Variables

View Source
var CG_CONNSTATE = map[uint32]string{
	CG_STATE_CLOSED:  "CG_STATE_CLOSED",
	CG_STATE_ERROR:   "CG_STATE_ERROR",
	CG_STATE_OPENING: "CG_STATE_OPENING",
	CG_STATE_ACTIVE:  "CG_STATE_ACTIVE",
}
View Source
var CG_ERR = map[uint32]string{
	CG_OK:               "CG_OK",
	CG_EINTERNAL:        "CG_EINTERNAL",
	CG_EINVALIDARGUMENT: "CG_EINVALIDARGUMENT",
	CG_EUNSUPPORTED:     "CG_EUNSUPPORTED",
	CG_ETIMEOUT:         "CG_ETIMEOUT",
	CG_EMORE:            "CG_EMORE",
	CG_EINCORRECTSTATE:  "CG_EINCORRECTSTATE",
	CG_EDUPLICATEID:     "CG_EDUPLICATEID",
	CG_EBUFFERTOOSMALL:  "CG_EBUFFERTOOSMALL",
	CG_EOVERFLOW:        "CG_EOVERFLOW",
	CG_EUNDERFLOW:       "CG_EUNDERFLOW",
	CG_EOF:              "CG_EOF",
	CG_ERANGEE_END:      "CG_ERANGEE_END",
}
View Source
var CG_ORDER_STATES = map[int8]string{
	CG_OSTATE_DEL:     "CG_OSTATE_DEL",
	CG_OSTATE_ACTIVE:  "CG_OSTATE_ACTIVE",
	CG_OSTATE_FILLED:  "CG_OSTATE_FILLED",
	CG_OSTATE_NEWPART: "CG_OSTATE_NEWPART",
}
View Source
var CG_STYPES = map[int32]string{
	CG_STYPE_FUT: "FUT",
	CG_STYPE_CFD: "CFD",
	CG_STYPE_SPR: "SPR",
	CG_STYPE_CLT: "CLT",
}
View Source
var CG_TIMEZONE, _ = time.LoadLocation("Europe/Moscow")
View Source
var CG_VALID_MSG = map[string]struct{}{
	"AddOrder":            {},
	"DelOrder":            {},
	"DelUserOrders":       {},
	"MoveOrder":           {},
	"IcebergAddOrder":     {},
	"IcebergDelOrder":     {},
	"IcebergMoveOrder":    {},
	"ChangePassword":      {},
	"ChangePasswordReply": {},
	"FORTS_MSG179":        {},
	"FORTS_MSG180":        {},
	"FORTS_MSG177":        {},
	"FORTS_MSG182":        {},
	"FORTS_MSG181":        {},
	"FORTS_MSG186":        {},
	"FORTS_MSG176":        {},
	"FORTS_MSG100":        {},
	"FORTS_MSG99":         {},
	"fut_sess_contents":   {},
	"common":              {},
	"sys_messages":        {},
	"session":             {},
	"deal":                {},
	"heartbeat":           {},
	"position":            {},
	"part":                {},
	"user_deal":           {},
	"orders_log":          {},
	"fut_vm":              {},
	"fee_all":             {},
	"fee_tn":              {},
	"money_clearing":      {},
}
View Source
var Configs = map[string]string{
	"pub":     "p2mq://FORTS_SRV;category=FORTS_MSG;name=qpub_%s;format=p2binfmt",
	"resp":    "p2mqreply://;ref=qpub_%s;name=qresp_%s",
	"info":    "p2repl://FORTS_REFDATA_REPL;name=qinfo_%s;tables=fut_sess_contents,session,sys_messages",
	"trade":   "p2repl://FORTS_TRADE_REPL;name=qexec_%s;tables=orders_log,user_deal",
	"pos":     "p2repl://FORTS_POS_REPL;name=qpos_%s;tables=position",
	"part":    "p2repl://FORTS_PART_REPL;name=qportf_%s;tables=part",
	"vm":      "p2repl://FORTS_VM_REPL;name=qvm_%s;tables=fut_vm",
	"penalty": "p2repl://FORTS_TNPENALTY_REPL;name=qpenalty_%s;tables=fee_all,fee_tn",
	"deals":   "p2repl://FORTS_DEALS_REPL;name=qdeals_%s;tables=deal,heartbeat",
	"clr":     "p2repl://FORTS_CLR_REPL;name=qclr_%s;tables=money_clearing",
	"pwd":     "p2mqpwdreply://;ref=qpub_pwd;name=qpwd",
}

Functions

func GetBCD

func GetBCD(pData unsafe.Pointer, offset uintptr) (float64, error)

GetBCD extracts a floating-point number from a binary-coded decimal (BCD) representation located at a specific offset within a data structure.

func GetTime

func GetTime(data []byte) time.Time

GetTime parses a byte slice representing a date and time and returns a time.

Types

type CGAPI

type CGAPI struct {
	Session        Session
	Securities     map[string]Security
	TsDelta        float64
	OrdersChan     chan Order
	TradesChan     chan Trade
	PositionsChan  chan Position
	PortfoliosChan chan Portfolio
	VarMarginChan  chan VarMargin
	PenaltyChan    chan Penalty
	ClearingChan   chan ClearingMoney
	// contains filtered or unexported fields
}

func NewCGateClient

func NewCGateClient(ctx context.Context, options *CGOptions, logger Logger) *CGAPI

func (*CGAPI) CancelOrder

func (api *CGAPI) CancelOrder() error

func (*CGAPI) ChangePassword

func (api *CGAPI) ChangePassword() error

func (*CGAPI) Connect

func (api *CGAPI) Connect(locLogin, locPasswd, ip string, port, processTimeout uint32) error

func (*CGAPI) MoveOrder

func (api *CGAPI) MoveOrder() error

func (*CGAPI) PlaceOrder

func (api *CGAPI) PlaceOrder() error

type CGOptions

type CGOptions struct {
	InstanceName string
	LsnNames     []string
	NeedPub      bool
}

type ClearingMoney

type ClearingMoney struct {
	ClientCode       string
	ReplRev, ReplAct int64
	AmountStart      float64
	AmountEnd        float64
	Free             float64
	Vm               float64
	Premium          float64
	Pay              float64
	FeeFut           float64
	FeeOpt           float64
	Go               float64
	AssetType        int8
}

ClearingMoney ...

func (*ClearingMoney) Decode

func (m *ClearingMoney) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type Deal

type Deal struct {
	ReplRev, ReplAct int64
	Price            float64
	ISINId           int32
}

Deal ...

func (*Deal) Decode

func (d *Deal) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type FieldDesc

type FieldDesc struct {
	Offs uintptr
	Size uint32
}

type Logger

type Logger interface {
	Info(format string, v ...any)
	Debug(format string, v ...any)
	Error(format string, v ...any)
	Fatal(format string, v ...any)
}

func ColouredLogger

func ColouredLogger(name string) Logger

type Order

type Order struct {
	OId              string
	Type             string
	Symbol           string
	Comment          string
	Status           string
	ClientCode       string
	Compliance       string
	ReplRev, ReplAct int64
	MtsCreate        float64
	Price            float64
	Qty              int64
	CId              int32
	ISINId           int32
}

Order ...

func (*Order) Decode

func (o *Order) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type Penalty

type Penalty struct {
	ReplRev, ReplAct int64
	Time             int64
	Fee              float64
	Points           int32
	TnType           int32
	ECode            int32
	Count            int32
	OrdersNum        int32
	P2Login          string
}

Penalty ...

func (*Penalty) Decode

func (p *Penalty) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type Portfolio

type Portfolio struct {
	ReplRev, ReplAct int64
	Free             float64
	Blocked          float64
	Old              float64
	Amount           float64
	VMReserve        float64
	VMIntercl        float64
	Fee              float64
	ClientCode       string
	LimitsSet        int8
}

Portfolio ...

func (*Portfolio) Decode

func (p *Portfolio) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type Position

type Position struct {
	Symbol           string
	ClientCode       string
	ReplRev, ReplAct int64
	Qty              int64
	Buys             int64
	Sells            int64
	OpenQty          int64
	WAPrice          float64
	NetVolume        float64
	ISINId           int32
	AccountType      int8
}

Position ...

func (*Position) Decode

func (p *Position) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type Security

type Security struct {
	ReplRev, ReplAct int64
	Go               float64
	MaxPrice         float64
	MinPrice         float64
	PriceStep        float64
	StepPrice        float64
	Mult             float64
	Scale            int32
	MinOrderSize     int32
	Lot              int32
	ISINId           int32
	State            int32
	Signs            int32
	ISINShort        string
	SecType          string
	BaseCode         string
	Currency         string
	Exchange         string
	ExpirationDate   time.Time
}

Security ...

func (*Security) Decode

func (s *Security) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type Session

type Session struct {
	ReplRev, ReplAct int64
	State            int32
	MonOn            int8
	EveOn            int8
	Begin            time.Time
	End              time.Time
	InterClBegin     time.Time
	InterClEnd       time.Time
	EveBegin         time.Time
	EveEnd           time.Time
	MonBegin         time.Time
	MonEnd           time.Time
}

Session ...

func (*Session) Decode

func (s *Session) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

func (*Session) String

func (s *Session) String() string

type StdLogger

type StdLogger struct {
	// contains filtered or unexported fields
}

func (StdLogger) Debug

func (l StdLogger) Debug(format string, v ...any)

func (StdLogger) Error

func (l StdLogger) Error(format string, v ...any)

func (StdLogger) Fatal

func (l StdLogger) Fatal(format string, v ...any)

func (StdLogger) Info

func (l StdLogger) Info(format string, v ...any)

type SysMessage

type SysMessage struct {
	ReplRev int64
	ReplAct int64
	Time    time.Time
	Status  int8
	Urgency int8
	Body    string
}

SysMessage...

func (*SysMessage) Decode

func (m *SysMessage) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type Trade

type Trade struct {
	ReplRev, ReplAct int64
	MtsCreate        float64
	Price            float64
	Qty              int64
	Comiss           float64
	Status           int64
	TId              int64
	CId              int32
	ISINId           int32
	OId              string
	Type             string
	Symbol           string
	Comment          string
	ClientCode       string
	Login            string
}

Trade ...

func (*Trade) Decode

func (t *Trade) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

type VarMargin

type VarMargin struct {
	ReplRev, ReplAct int64
	ISINId           int32
	Margin           float64
	ClientCode       string
}

VarMargin ...

func (*VarMargin) Decode

func (vm *VarMargin) Decode(msg *C.cg_msg_streamdata_t, fields map[string]FieldDesc) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL