---
# System prepended metadata

title: Untitled

---

PYT Protocol 
PYT Protocol trading protocol is a modified version of BTC OUCH 0.1 protocol. Some information about PYT Trade  protocol can be found in BTC OUCH 0.1 specification. 

1. messages sent from a trader to the broker(inbound messages)
Types of messages.
const (
	CreateOrderType      = types.Char('O')
	UpdateOrderType      = types.Char('U')
	CancelOrderType      = types.Char('C')
	SetOrderLeverageType = types.Char('L')
)
Lengths of messages(should stay separated initialized as constants).
const (
	CreateOrderLength      int = 103
	UpdateOrderLength      int = 102
	CancelOrderLength      int = 86
	SetOrderLeverageLength int = 80
)
CreateOrder is containing Create Order Message fields in useable format.
type CreateOrder struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderCID    types.Uint64    `json:"order_client_id"`
	OrderType   types.Char      `json:"order_type"`
	Price       types.Uint64    `json:"price"`
	Quantity    types.Uint64    `json:"quantity"`
	AccountID   types.Uint64    `json:"account_id"`
	Signature   types.Signature `json:"signature"`
}
CancelOrder is containing Cancel Order Message fields in useable format.
type CancelOrder struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderID     types.Uint64    `json:"order_id"`
	AccountID   types.Uint64    `json:"account_id"`
	Signature   types.Signature `json:"signature"`
}

SetOrderLeverage is containing SetOrderLeverage message fields in useable format.
type SetOrderLeverage struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	Leverage    types.Char      `json:"leverage"`
	Side        types.Char      `json:"side"`
	AccountID   types.Uint64    `json:"account_id"`
	Signature   types.Signature `json:"signature"`
}
UpdateOrder is a structure containing Update Order Message fields in usable format.
type UpdateOrder struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderID     types.Uint64    `json:"order_id"`
	Price       types.Uint64    `json:"price"`
	Quantity    types.Uint64    `json:"quantity"`
	AccountID   types.Uint64    `json:"account_id"`
	Signature   types.Signature `json:"signature"`
}
2. messages sent from the broker to a trader (outbound messages)
Types of messages
const (
	OrderCreatedType     = types.Char('O')
	OrderUpdatedType     = types.Char('U')
	OrderCancelledType   = types.Char('C')
	LeverageOrderSetType = types.Char('L')
	OrderAcceptedType    = types.Char('Y')
	OrderRejectedType    = types.Char('R')
	OrderExecutedType    = types.Char('E')
	ErrorType            = types.Char('!')
)
Lengths of messages(should stay separated initialized as constants)
const (
	OrderCreatedLength     int = 52
	OrderUpdatedLength     int = 43
	OrderCancelledLength   int = 27
	LeverageOrderSetLength int = 21
	OrderAcceptedLength    int = 35
	OrderRejectedLength    int = 36
	OrderExecutedLength    int = 44
	ErrorLength            int = 13
)
OrderAccepted is containing Order Accepted Event fields in useable format.
type OrderAccepted struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderCID    types.Uint64    `json:"order_client_id"`
	OrderID     types.Uint64    `json:"order_id"`
	AccountID   types.Uint64    `json:"account_id"`
	Timestamp   types.Timestamp `json:"timestamp"`
}
Error is containing Error Event fields in useable format.
type Error struct {
	MessageType   types.Char      `json:"message_type"`
	Timestamp     types.Timestamp `json:"timestamp"`
	Code          types.Uint16    `json:"code"`
	MessageLength types.Uint16    `json:"message_length"`
	Message       types.String    `json:"message"`
}
OrderCancelled is containing Order Cancelled Event fields in useable format.
type OrderCancelled struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderID     types.Uint64    `json:"order_id"`
	AccountID   types.Uint64    `json:"account_id"` // TODO: Is it better to remove from here?
	Timestamp   types.Timestamp `json:"timestamp"`
}
LeverageOrderSet is containing Leverage Order Set Event fields in useable format.
type LeverageOrderSet struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	Leverage    types.Char      `json:"leverage"`
	Side        types.Char      `json:"side"`
	AccountID   types.Uint64    `json:"account_id"`
	Timestamp   types.Timestamp `json:"timestamp"`
}
OrderCreated is containing Order Created Event fields in useable format.
type OrderCreated struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderCID    types.Uint64    `json:"order_client_id"`
	OrderID     types.Uint64    `json:"order_id"`
	OrderType   types.Char      `json:"order_type"`
	Price       types.Uint64    `json:"price"`
	Quantity    types.Uint64    `json:"quantity"`
	AccountID   types.Uint64    `json:"account_id"`
	Timestamp   types.Timestamp `json:"timestamp"`
}
OrderExecuted is containing Order Executed Event fields in useable format.
type OrderExecuted struct {
	MessageType      types.Char      `json:"message_type"`
	SymbolID         types.Uint16    `json:"symbol_id"`
	MakerOrderID     types.Uint64    `json:"maker_order_id"`
	TakerOrderID     types.Uint64    `json:"taker_order_id"`
	ExecutedPrice    types.Uint64    `json:"executed_price"`
	ExecutedQuantity types.Uint64    `json:"executed_quantity"`
	IsBuyerMaker     types.Char      `json:"is_buyer_maker"`
	Timestamp        types.Timestamp `json:"timestamp"`
}
OrderRejected is a structure containing Order Rejected Event fields in useable format.
type OrderRejected struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderCID    types.Uint64    `json:"order_client_id"`
	OrderID     types.Uint64    `json:"order_id"`
	AccountID   types.Uint64    `json:"account_id"`
	Timestamp   types.Timestamp `json:"timestamp"`
	Reason      types.Char      `json:"reason"`
}
OrderUpdated is containing Order Updated Event fields in useable format.
type OrderUpdated struct {
	MessageType types.Char      `json:"message_type"`
	SymbolID    types.Uint16    `json:"symbol_id"`
	OrderID     types.Uint64    `json:"order_id"`
	Price       types.Uint64    `json:"price"`
	Quantity    types.Uint64    `json:"quantity"`
	AccountID   types.Uint64    `json:"account_id"`
	Timestamp   types.Timestamp `json:"timestamp"`
}