-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathorder_status.go
66 lines (60 loc) · 1.9 KB
/
order_status.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
package go5paisa
import (
"bytes"
"encoding/json"
"io/ioutil"
// "log"
)
// OrderForStatus represents details of an order in the OrderBook
type OrderForStatus struct {
Exchange string `json:"Exch"`
ExchangeType string `json:"ExchType"`
ScripCode int `json:"ScripCode"`
RemoteOrderID string `json:"RemoteOrderID"`
}
type OrderResponseList struct {
OrderList []OrderResponse `json:"OrdStatusResLst"`
}
// OrderResponse contains the order status details
type OrderResponse struct {
Exchange string `json:"Exch"`
ExchangeType string `json:"ExchType"`
ScripCode int `json:"ScripCode"`
ExchangeOrderID int `json:"ExchOrderID"`
ExchangeOrderTime string `json:"ExchOrderTime"`
OrderQty int `json:"OrderQty"`
OrderRate float32 `json:"OrderRate"`
PendingQty int `json:"PendingQty"`
Status string `json:"Status"`
Symbol string `json:"Symbol"`
TradedQty int `json:"TradedQty"`
}
// OrderStatusReqList contains a order status request list
type OrderStatusReqList struct {
OrderStatusList []OrderForStatus `json:"OrdStatusReqList"`
}
// GetOrderStatus fetches order book of the user
func (c *Client) GetOrderStatus(orderList OrderStatusReqList) (OrderResponseList, error) {
var orderStatus OrderResponseList
c.appConfig.head.RequestCode = orderStatusRequestCode
payloadBody := orderStatusPayloadBody{
ClientCode: c.clientCode,
OrdList: orderList.OrderStatusList,
}
payload := orderStatusPayload{
Head: c.appConfig.head,
Body: payloadBody,
}
jsonValue, _ := json.Marshal(payload)
res, err := c.connection.Post(baseURL+orderStatusRoute, contentType, bytes.NewBuffer(jsonValue))
if err != nil {
return orderStatus, err
}
defer res.Body.Close()
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return orderStatus, err
}
parseResBody(resBody, &orderStatus)
return orderStatus, nil
}