-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth.go
47 lines (42 loc) · 1.16 KB
/
auth.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
package kalshi
import "context"
// LoginRequest is described here:
// https://trading-api.readme.io/reference/login.
type LoginRequest struct {
Email string `json:"email,omitempty"`
Password string `json:"password,omitempty"`
}
// LoginResponse is described here:
// https://trading-api.readme.io/reference/login.
type LoginResponse struct {
Token string `json:"token,omitempty"`
UserID string `json:"user_id,omitempty"`
}
// Login is described here:
// https://trading-api.readme.io/reference/login.
//
// The Client will stay authenticated after Login is called since it stores the
// token in the cookie state.
func (c *Client) Login(ctx context.Context, req LoginRequest) (*LoginResponse, error) {
var resp LoginResponse
err := c.request(ctx, request{
Method: "POST",
Endpoint: "login",
JSONRequest: req,
JSONResponse: &resp,
})
if err != nil {
return nil, err
}
return &resp, nil
}
// Logout is described here:
// https://trading-api.readme.io/reference/logout.
func (c *Client) Logout(ctx context.Context) error {
return c.request(ctx, request{
Method: "POST",
Endpoint: "logout",
JSONRequest: nil,
JSONResponse: nil,
})
}