Skip to content

Commit 27125b5

Browse files
authored
Merge pull request #63 from latesun/feature/add-more-fields
feat(go): add more fields
2 parents 0a9f3ff + 19fab0d commit 27125b5

File tree

3 files changed

+68
-22
lines changed

3 files changed

+68
-22
lines changed

go/_examples/main.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,34 @@ func main() {
4141

4242
// create callback functions for receive messages
4343
callOrder := gate.NewCallBack(func(msg *gate.UpdateMsg) {
44+
if msg.Event != "update" {
45+
return
46+
}
4447
// parse the message to struct we need
4548
var order []gate.SpotOrderMsg
4649
if err := json.Unmarshal(msg.Result, &order); err != nil {
47-
log.Printf("order Unmarshal err:%s", err.Error())
50+
log.Printf("order %s unmarshal err: %v", msg.Result, err)
4851
}
49-
log.Printf("%+v", order)
52+
log.Printf("order: %+v", order)
5053
})
5154

5255
callTrade := gate.NewCallBack(func(msg *gate.UpdateMsg) {
5356
var trade gate.SpotTradeMsg
5457
if err := json.Unmarshal(msg.Result, &trade); err != nil {
55-
log.Printf("trade Unmarshal err:%s", err.Error())
58+
log.Printf("trade %s unmarshal err: %v", msg.Result, err)
5659
}
57-
log.Printf("%+v", trade)
60+
log.Printf("trade: %+v", trade)
5861
})
5962

6063
// first, we need set callback function
6164
ws.SetCallBack(gate.ChannelSpotOrder, callOrder)
6265
ws.SetCallBack(gate.ChannelSpotPublicTrade, callTrade)
6366
// second, after set callback function, subscribe to any channel you are interested into
64-
if err := ws.Subscribe(gate.ChannelSpotPublicTrade, []string{"BTC_USDT"}); err != nil {
67+
if err := ws.Subscribe(gate.ChannelSpotOrder, []string{"BTC_USDT"}); err != nil {
6568
log.Printf("Subscribe err:%s", err.Error())
6669
return
6770
}
68-
if err := ws.Subscribe(gate.ChannelSpotBookTicker, []string{"BTC_USDT"}); err != nil {
71+
if err := ws.Subscribe(gate.ChannelSpotPublicTrade, []string{"BTC_USDT"}); err != nil {
6972
log.Printf("Subscribe err:%s", err.Error())
7073
return
7174
}

go/response_future.go

+27-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ type FuturesTicker struct {
2929
IndexPrice string `json:"index_price,omitempty"`
3030
// Exchange rate of base currency and settlement currency in Quanto contract. Not existed in contract of other types
3131
QuantoBaseRate string `json:"quanto_base_rate,omitempty"`
32-
33-
Low24h string `json:"low_24h"`
34-
High24h string `json:"high_24h"`
32+
Low24h string `json:"low_24h"`
33+
High24h string `json:"high_24h"`
3534
}
3635

3736
type FuturesTrade struct {
@@ -124,10 +123,19 @@ type FuturesOrder struct {
124123
// Order finished time. Not returned if order is open
125124
FinishTime int64 `json:"finish_time,omitempty"`
126125
FinishTimeMs int64 `json:"finish_time_ms,omitempty"`
127-
// How the order is finished. - filled: all filled - cancelled: manually cancelled - liquidated: cancelled because of liquidation - ioc: time in force is `IOC`, finish immediately - auto_deleveraged: finished by ADL - reduce_only: cancelled because of increasing position while `reduce-only` set
126+
// FinishAs indicates how the order was completed:
127+
// - filled: all filled
128+
// - cancelled: manually cancelled
129+
// - liquidated: cancelled due to liquidation
130+
// - ioc: time in force is IOC, finished immediately
131+
// - auto_deleveraged: finished by ADL
132+
// - reduce_only: cancelled due to increase in position while reduce-only set
133+
// - position_closed: cancelled due to position close
134+
// - stp: cancelled due to self trade prevention
135+
// - _new: order created
136+
// - _update: order filled, partially filled, or updated
137+
// - reduce_out: only reduce position, excluding pending orders hard to execute
128138
FinishAs string `json:"finish_as,omitempty"`
129-
// Order status - `open`: waiting to be traded - `finished`: finished
130-
Status string `json:"status,omitempty"`
131139
// Futures contract
132140
Contract string `json:"contract"`
133141
// Order size. Specify positive number to make a bid, and negative number to ask
@@ -160,6 +168,18 @@ type FuturesOrder struct {
160168

161169
StopProfitPrice string `json:"stop_profit_price"`
162170
StopLossPrice string `json:"stop_loss_price"`
171+
// StpId represents the ID associated with the self-trade prevention mechanism.
172+
StpId int64 `json:"stp_id,omitempty"`
173+
// StpAct represents the self-trade prevention (STP) action:
174+
// - cn: Cancel newest (keep old orders)
175+
// - co: Cancel oldest (keep new orders)
176+
// - cb: Cancel both (cancel both old and new orders)
177+
// If not provided, defaults to 'cn'. Requires STP group membership; otherwise, an error is returned.
178+
StpAct string `json:"stp_act,omitempty"`
179+
// BizInfo represents business-specific information related to the order. The exact content and format can vary depending on the use case.
180+
BizInfo string `json:"biz_info,omitempty"`
181+
// AmendText provides the custom data that the user remarked when amending the order
182+
AmendText string `json:"amend_text,omitempty"`
163183
}
164184

165185
type FuturesUserTrade struct {
@@ -177,6 +197,7 @@ type FuturesUserTrade struct {
177197
Fee float64 `json:"fee"`
178198
PointFee float64 `json:"point_fee"`
179199
}
200+
180201
type FuturesLiquidate struct {
181202
// Liquidation time
182203
Time int64 `json:"time,omitempty"`

go/response_spot.go

+32-10
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ type SpotBalancesMsg struct {
1414
}
1515

1616
type SpotCandleUpdateMsg struct {
17-
Time string `json:"t"`
18-
Volume string `json:"v"`
19-
Close string `json:"c"`
20-
High string `json:"h"`
21-
Low string `json:"l"`
22-
Open string `json:"o"`
23-
Name string `json:"n"`
24-
Amount string `json:"a"`
17+
Time string `json:"t"`
18+
Volume string `json:"v"`
19+
Close string `json:"c"`
20+
High string `json:"h"`
21+
Low string `json:"l"`
22+
Open string `json:"o"`
23+
Name string `json:"n"`
24+
Amount string `json:"a"`
25+
WindowClose bool `json:"w"`
2526
}
2627

2728
// SpotUpdateDepthMsg update order book
@@ -115,6 +116,8 @@ type SpotUserTradesMsg struct {
115116
PointFee string `json:"point_fee"`
116117
GtFee string `json:"gt_fee"`
117118
Text string `json:"text"`
119+
AmendText string `json:"amend_text"`
120+
BizInfo string `json:"biz_info"`
118121
}
119122

120123
type SpotTradeMsg struct {
@@ -136,8 +139,6 @@ type OrderMsg struct {
136139
CreateTime string `json:"create_time,omitempty"`
137140
// SpotOrderMsg last modification time
138141
UpdateTime string `json:"update_time,omitempty"`
139-
// SpotOrderMsg status - `open`: to be filled - `closed`: filled - `cancelled`: cancelled
140-
Status string `json:"status,omitempty"`
141142
// Currency pair
142143
CurrencyPair string `json:"currency_pair"`
143144
// SpotOrderMsg type. limit - limit order
@@ -162,6 +163,8 @@ type OrderMsg struct {
162163
FillPrice string `json:"fill_price,omitempty"`
163164
// Total filled in quote currency
164165
FilledTotal string `json:"filled_total,omitempty"`
166+
// Average fill price
167+
AvgDealPrice string `json:"avg_deal_price,omitempty"`
165168
// Fee deducted
166169
Fee string `json:"fee,omitempty"`
167170
// Fee currency unit
@@ -176,6 +179,25 @@ type OrderMsg struct {
176179
RebatedFee string `json:"rebated_fee,omitempty"`
177180
// Rebated fee currency unit
178181
RebatedFeeCurrency string `json:"rebated_fee_currency,omitempty"`
182+
// StpId represents the ID associated with the self-trade prevention mechanism.
183+
StpId int64 `json:"stp_id,omitempty"`
184+
// StpAct represents the self-trade prevention (STP) action:
185+
// - cn: Cancel newest (keep old orders)
186+
// - co: Cancel oldest (keep new orders)
187+
// - cb: Cancel both (cancel both old and new orders)
188+
// If not provided, defaults to 'cn'. Requires STP group membership; otherwise, an error is returned.
189+
StpAct string `json:"stp_act,omitempty"`
190+
// FinishAs indicates how the order was finished:
191+
// - open: processing
192+
// - filled: fully filled
193+
// - cancelled: manually cancelled
194+
// - ioc: finished immediately (IOC)
195+
// - stp: cancelled due to self-trade prevention
196+
FinishAs string `json:"finish_as,omitempty"`
197+
// BizInfo represents business-specific information related to the order. The exact content and format can vary depending on the use case.
198+
BizInfo string `json:"biz_info,omitempty"`
199+
// AmendText provides the custom data that the user remarked when amending the order
200+
AmendText string `json:"amend_text,omitempty"`
179201
}
180202

181203
type SpotOrderMsg struct {

0 commit comments

Comments
 (0)