-
Notifications
You must be signed in to change notification settings - Fork 0
/
requester-interface.go
465 lines (373 loc) · 16.7 KB
/
requester-interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
package gOanda
import "github.com/sirupsen/logrus"
type Requester interface {
// account
GetAccounts(GetAccountsRequest) (*GetAccountsResponse, error)
GetAccount(GetAccountRequest) (*GetAccountResponse, error)
GetAccountSummary(GetAccountSummaryRequest) (*GetAccountSummaryResponse, error)
GetAccountInstruments(GetAccountInstrumentsRequest) (*GetAccountInstrumentsResponse, error)
PatchAccountConfiguration(PatchAccountConfigurationRequest) (*PatchAccountConfigurationResponse, error)
// instruments
GetInstrumentCandles(GetInstrumentCandlesRequest) (*GetInstrumentCandlesResponse, error)
GetInstrumentOrderBook(GetInstrumentOrderBookRequest) (*GetInstrumentOrderBookResponse, error)
GetInstrumentPositionBook(GetInstrumentPositionBookRequest) (*GetInstrumentPositionBookResponse, error)
// orders
PostOrder(PostOrderRequest) (*PostOrderResponse, error)
GetOrders(GetOrdersRequest) (*GetOrdersResponse, error)
GetPendingOrders(GetPendingOrdersRequest) (*GetPendingOrdersResponse, error)
GetOrder(GetOrderRequest) (*GetOrderResponse, error)
PutReplaceOrder(PutReplaceOrderRequest) (*PutReplaceOrderResponse, error)
PutCancelOrder(PutCancelOrderRequest) (*PutCancelOrderResponse, error)
PutUpdateOrderClientExtensions(PutUpdateOrderClientExtensionsRequest) (*PutUpdateOrderClientExtensionsResponse, error)
// trades
GetTrades(GetTradesRequest) (*GetTradesResponse, error)
GetOpenTrades(GetOpenTradesRequest) (*GetOpenTradesResponse, error)
GetTrade(GetTradeRequest) (*GetTradeResponse, error)
PutCloseTrade(PutCloseTradeRequest) (*PutCloseTradeResponse, error)
PutUpdateTradeClientExtensions(PutUpdateTradeClientExtensionsRequest) (*PutUpdateTradeClientExtensionsResponse, error)
PutUpdateTradeDependentOrders(PutUpdateTradeDependentOrdersRequest) (*PutUpdateTradeDependentOrdersResponse, error)
// positions
GetPositions(GetPositionsRequest) (*GetPositionsResponse, error)
GetOpenPositions(GetOpenPositionsRequest) (*GetOpenPositionsResponse, error)
GetInstrumentsPosition(GetInstrumentsPositionRequest) (*GetInstrumentsPositionResponse, error)
PutClosePosition(PutClosePositionRequest) (*PutClosePositionResponse, error)
// transactions
GetTransactions(GetTransactionsRequest) (*GetTransactionsResponse, error)
GetTransaction(GetTransactionRequest) (*GetTransactionResponse, error)
GetRangeOfTransactions(GetRangeOfTransactionsRequest) (*GetRangeOfTransactionsResponse, error)
GetTransactionsSinceId(GetTransactionsSinceIdRequest) (*GetTransactionsSinceIdResponse, error)
GetTransactionsStream(GetTransactionsStreamRequest) (*GetTransactionsStreamResponse, error)
// pricing
GetInstrumentPricing(GetInstrumentPricingRequest) (*GetInstrumentPricingResponse, error)
GetPricingStream(GetPricingStreamRequest) (*GetPricingStreamResponse, error)
}
type GetAccountsRequest struct{}
type GetAccountsResponse struct {
Accounts []AccountProperties
}
type GetAccountRequest struct{}
type GetAccountResponse struct {
Account Account
}
type GetAccountSummaryRequest struct{}
type GetAccountSummaryResponse struct {
Account AccountSummary
LastTransactionID TransactionID
}
type GetAccountInstrumentsRequest struct{}
type GetAccountInstrumentsResponse struct {
Instruments []Instrument
LastTransactionID TransactionID
}
type PatchAccountConfigurationRequest struct{}
type PatchAccountConfigurationResponse struct{}
type GetInstrumentCandlesRequest struct {
InstrumentName InstrumentName
Count int
Granularity CandlestickGranularity
From DateTime
To DateTime
}
type GetInstrumentCandlesResponse struct {
Instrument InstrumentName
Granularity CandlestickGranularity
Candles []Candlestick
}
type GetInstrumentOrderBookRequest struct{}
type GetInstrumentOrderBookResponse struct{}
type GetInstrumentPositionBookRequest struct{}
type GetInstrumentPositionBookResponse struct{}
type PostOrderRequest struct {
Order AnOrderRequest
}
type PostOrderResponse struct {
OrderCreateTransaction Transaction `json:"orderCreateTransaction"`
OrderFillTransaction OrderFillTransaction `json:"orderFillTransaction"`
OrderCancelTransaction OrderCancelTransaction `json:"orderCancelTransaction"`
OrderReissueTransaction Transaction `json:"orderReissueTransaction"`
OrderReissueRejectTransaction Transaction `json:"orderReissueRejectTransaction"`
RelatedTransactionIDs []TransactionID `json:"relatedTransactionIDs"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type PostOrderRawResponse struct {
OrderCreateTransaction RawTransaction `json:"orderCreateTransaction"`
OrderFillTransaction OrderFillTransaction `json:"orderFillTransaction"`
OrderCancelTransaction OrderCancelTransaction `json:"orderCancelTransaction"`
OrderReissueTransaction RawTransaction `json:"orderReissueTransaction"`
OrderReissueRejectTransaction RawTransaction `json:"orderReissueRejectTransaction"`
RelatedTransactionIDs []TransactionID `json:"relatedTransactionIDs"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
func (p *PostOrderRawResponse) ToPostOrderResponse() PostOrderResponse {
return PostOrderResponse{
OrderCreateTransaction: p.OrderCreateTransaction.ToTransaction(),
OrderFillTransaction: p.OrderFillTransaction,
OrderCancelTransaction: p.OrderCancelTransaction,
OrderReissueTransaction: p.OrderReissueTransaction.ToTransaction(),
OrderReissueRejectTransaction: p.OrderReissueRejectTransaction.ToTransaction(),
RelatedTransactionIDs: p.RelatedTransactionIDs,
LastTransactionID: p.LastTransactionID,
ErrorCode: p.ErrorCode,
ErrorMessage: p.ErrorMessage,
}
}
type GetOrdersRequest struct {
Ids []OrderID
State OrderStateFilter
InstrumentName InstrumentName
Count int
BeforeID OrderID
}
type GetRawOrdersResponse struct {
Orders []RawOrder `json:"orders"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type GetOrdersResponse struct {
Orders []Order `json:"orders"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
func (g *GetRawOrdersResponse) Unmarshal() (*GetOrdersResponse, error) {
unmarshalledOrders := make([]Order, 0)
for _, marshalledOrder := range g.Orders {
unmarshalledOrder, err := marshalledOrder.ToOrder()
if err != nil {
logrus.Error("Could not unmarshal order: ", marshalledOrder)
return nil, err
}
unmarshalledOrders = append(unmarshalledOrders, unmarshalledOrder)
}
return &GetOrdersResponse{
Orders: unmarshalledOrders,
LastTransactionID: g.LastTransactionID,
ErrorCode: g.ErrorCode,
ErrorMessage: g.ErrorMessage,
}, nil
}
type GetPendingOrdersRequest struct{}
type GetRawPendingOrdersResponse struct {
Orders []RawOrder `json:"orders"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
func (g *GetRawPendingOrdersResponse) Unmarshal() (*GetPendingOrdersResponse, error) {
unmarshalledOrders := make([]Order, 0)
for _, marshalledOrder := range g.Orders {
unmarshalledOrder, err := marshalledOrder.ToOrder()
if err != nil {
logrus.Error("Could not unmarshal order: ", marshalledOrder)
return nil, err
}
unmarshalledOrders = append(unmarshalledOrders, unmarshalledOrder)
}
return &GetPendingOrdersResponse{
Orders: unmarshalledOrders,
LastTransactionID: g.LastTransactionID,
ErrorCode: g.ErrorCode,
ErrorMessage: g.ErrorMessage,
}, nil
}
type GetPendingOrdersResponse struct {
Orders []Order `json:"orders"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type GetOrderRequest struct {
Id OrderID
}
type GetRawOrderResponse struct {
Order RawOrder `json:"order"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
func (g *GetRawOrderResponse) Unmarshal() (*GetOrderResponse, error) {
unmarshalledOrder, err := g.Order.ToOrder()
if err != nil {
logrus.Error("Could not unmarshal order")
return nil, err
}
return &GetOrderResponse{
Order: unmarshalledOrder,
LastTransactionID: g.LastTransactionID,
ErrorCode: g.ErrorCode,
ErrorMessage: g.ErrorMessage,
}, nil
}
type GetOrderResponse struct {
Order Order `json:"order"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type PutReplaceOrderRequest struct {
Order AnOrderRequest
OrderID OrderID
}
type PutReplaceRawOrderResponse struct {
OrderCreateTransaction RawTransaction `json:"orderCreateTransaction"`
OrderFillTransaction OrderFillTransaction `json:"orderFillTransaction"`
OrderCancelTransaction OrderCancelTransaction `json:"orderCancelTransaction"`
OrderReissueTransaction RawTransaction `json:"orderReissueTransaction"`
OrderReissueRejectTransaction RawTransaction `json:"orderReissueRejectTransaction"`
RelatedTransactionIDs []TransactionID `json:"relatedTransactionIDs"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type PutReplaceOrderResponse struct {
OrderCreateTransaction Transaction `json:"orderCreateTransaction"`
OrderFillTransaction OrderFillTransaction `json:"orderFillTransaction"`
OrderCancelTransaction OrderCancelTransaction `json:"orderCancelTransaction"`
OrderReissueTransaction Transaction `json:"orderReissueTransaction"`
OrderReissueRejectTransaction Transaction `json:"orderReissueRejectTransaction"`
RelatedTransactionIDs []TransactionID `json:"relatedTransactionIDs"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
func (p *PutReplaceRawOrderResponse) ToPutReplaceOrderResponse() PutReplaceOrderResponse {
return PutReplaceOrderResponse{
OrderCreateTransaction: p.OrderCreateTransaction.ToTransaction(),
OrderFillTransaction: p.OrderFillTransaction,
OrderCancelTransaction: p.OrderCancelTransaction,
OrderReissueTransaction: p.OrderReissueTransaction.ToTransaction(),
OrderReissueRejectTransaction: p.OrderReissueRejectTransaction.ToTransaction(),
RelatedTransactionIDs: p.RelatedTransactionIDs,
LastTransactionID: p.LastTransactionID,
ErrorCode: p.ErrorCode,
ErrorMessage: p.ErrorMessage,
}
}
type PutCancelOrderRequest struct {
OrderSpecifier OrderSpecifier
}
type PutCancelOrderResponse struct {
OrderCancelTransaction OrderCancelTransaction `json:"orderCancelTransaction"`
OrderCancelRejectTransaction OrderCancelRejectTransaction `json:"orderCancelRejectTransaction"`
RelatedTransactionIDs []TransactionID `json:"relatedTransactionIDs"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type PutUpdateOrderClientExtensionsRequest struct{}
type PutUpdateOrderClientExtensionsResponse struct{}
type GetTradesRequest struct {
Ids []TradeID `json:"ids"`
State TradeStateFilter `json:"state"`
InstrumentName InstrumentName `json:"instrument"`
Count int64 `json:"count"`
BeforeID TradeID `json:"beforeID"`
}
type GetTradesResponse struct {
Trades []Trade `json:"trades"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type GetOpenTradesRequest struct{}
type GetOpenTradesResponse struct {
Trades []Trade `json:"trades"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type GetTradeRequest struct {
TradeSpecifier TradeSpecifier
}
type GetTradeResponse struct {
Trade Trade `json:"trade"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type PutCloseTradeRequest struct {
TradeSpecifier TradeSpecifier
}
type PutCloseTradeResponse struct {
OrderCreateTransaction MarketOrderTransaction `json:"orderCreateTransaction"`
OrderFillTransaction OrderFillTransaction `json:"orderFillTransaction"`
OrderCancelTransaction OrderCancelTransaction `json:"orderCancelTransaction"`
OrderRejectTransaction MarketOrderRejectTransaction `json:"orderRejectTransaction"`
RelatedTransactionsIDs []TransactionID `json:"relatedTransactionsIDs"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type PutUpdateTradeClientExtensionsRequest struct{}
type PutUpdateTradeClientExtensionsResponse struct{}
type PutUpdateTradeDependentOrdersRequest struct{}
type PutUpdateTradeDependentOrdersResponse struct{}
type GetPositionsRequest struct{}
type GetPositionsResponse struct{}
type GetOpenPositionsRequest struct{}
type GetOpenPositionsResponse struct{}
type GetInstrumentsPositionRequest struct{}
type GetInstrumentsPositionResponse struct{}
type PutClosePositionRequest struct{}
type PutClosePositionResponse struct{}
type GetTransactionsRequest struct{}
type GetTransactionsResponse struct{}
type GetTransactionRequest struct {
TransactionID TransactionID `json:"transactionID"`
}
type GetRawTransactionResponse struct {
Transaction RawTransaction `json:"transaction"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
func (g *GetRawTransactionResponse) Unmarshal() (*GetTransactionResponse, error) {
unmarshalledTransaction := g.Transaction.ToTransaction()
return &GetTransactionResponse{
Transaction: unmarshalledTransaction,
LastTransactionID: g.LastTransactionID,
ErrorCode: g.ErrorCode,
ErrorMessage: g.ErrorMessage,
}, nil
}
type GetTransactionResponse struct {
Transaction Transaction `json:"transaction"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type GetRangeOfTransactionsRequest struct {
To TransactionID
From TransactionID
}
type GetRangeOfTransactionsResponse struct {
Transactions []Transaction `json:"transactions"`
LastTransactionID TransactionID `json:"lastTransactionID"`
ErrorCode string `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
}
type GetTransactionsSinceIdRequest struct {
TransactionId TransactionID
}
type GetTransactionsSinceIdResponse struct {
Transactions []Transaction
LastTransactionID TransactionID
}
type GetTransactionsStreamRequest struct{}
type GetTransactionsStreamResponse struct{}
type GetInstrumentPricingRequest struct {
Instruments []InstrumentName
Since DateTime
IncludeUnitsAvailable bool
IncludeHomeConversions bool
}
type GetInstrumentPricingResponse struct {
Prices []Price
}
type GetPricingStreamRequest struct{}
type GetPricingStreamResponse struct{}