Skip to content

Commit

Permalink
Release: v1.0.6-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-the-h committed Sep 28, 2021
1 parent e97ae6e commit 110cd70
Show file tree
Hide file tree
Showing 28 changed files with 566 additions and 558 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ Changelog
=========
All notable changes to this project will be documented in this file.

v1.0.6-alpha
------------

### Changed

- Fixed GET method requests issue

v1.0.5-alpha
------------

Expand Down
20 changes: 10 additions & 10 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ type Client struct {

// NewClient returns a pointer to a fresh Client
func NewClient(ctx context.Context, apiKey, secretKey, passphrase string, destination okex.Destination) (*Client, error) {
restURL := okex.RestUrl
wsPubURL := okex.PublicWsUrl
wsPriURL := okex.PrivateWsUrl
restURL := okex.RestURL
wsPubURL := okex.PublicWsURL
wsPriURL := okex.PrivateWsURL
switch destination {
case okex.AwsServer:
restURL = okex.AwsRestUrl
wsPubURL = okex.AwsPublicWsUrl
wsPriURL = okex.AwsPrivateWsUrl
restURL = okex.AwsRestURL
wsPubURL = okex.AwsPublicWsURL
wsPriURL = okex.AwsPrivateWsURL
case okex.DemoServer:
restURL = okex.DemoRestUrl
wsPubURL = okex.DemoPublicWsUrl
wsPriURL = okex.DemoPrivateWsUrl
restURL = okex.DemoRestURL
wsPubURL = okex.DemoPublicWsURL
wsPriURL = okex.DemoPrivateWsURL
}

r := rest.NewClient(apiKey, secretKey, passphrase, restURL, destination)
c := ws.NewClient(ctx, apiKey, secretKey, passphrase, map[bool]okex.BaseUrl{true: wsPriURL, false: wsPubURL})
c := ws.NewClient(ctx, apiKey, secretKey, passphrase, map[bool]okex.BaseURL{true: wsPriURL, false: wsPubURL})

return &Client{r, c, ctx}, nil
}
11 changes: 6 additions & 5 deletions api/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"github.com/amir-the-h/okex"
"net/http"
"strings"
"time"
)

Expand All @@ -25,17 +26,17 @@ type ClientRest struct {
secretKey []byte
passphrase string
destination okex.Destination
baseUrl okex.BaseUrl
baseURL okex.BaseURL
client *http.Client
}

// NewClient returns a pointer to a fresh ClientRest
func NewClient(apiKey, secretKey, passphrase string, baseUrl okex.BaseUrl, destination okex.Destination) *ClientRest {
func NewClient(apiKey, secretKey, passphrase string, baseURL okex.BaseURL, destination okex.Destination) *ClientRest {
c := &ClientRest{
apiKey: apiKey,
secretKey: []byte(secretKey),
passphrase: passphrase,
baseUrl: baseUrl,
baseURL: baseURL,
destination: destination,
client: http.DefaultClient,
}
Expand All @@ -52,7 +53,7 @@ func NewClient(apiKey, secretKey, passphrase string, baseUrl okex.BaseUrl, desti

// Do the http request to the server
func (c *ClientRest) Do(method, path string, private bool, params ...map[string]string) (*http.Response, error) {
u := fmt.Sprintf("%s%s", c.baseUrl, path)
u := fmt.Sprintf("%s%s", c.baseURL, path)
var (
r *http.Request
err error
Expand All @@ -68,7 +69,7 @@ func (c *ClientRest) Do(method, path string, private bool, params ...map[string]
if len(params) > 0 {
q := r.URL.Query()
for k, v := range params[0] {
q.Add(fmt.Sprint(k), fmt.Sprint(v))
q.Add(k, strings.ReplaceAll(v, "\"", ""))
}
r.URL.RawQuery = q.Encode()
if len(params[0]) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion api/rest/public_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package rest
import (
"encoding/json"
"github.com/amir-the-h/okex"
requests "github.com/amir-the-h/okex/requests/rest/public_data"
requests "github.com/amir-the-h/okex/requests/rest/public"
responses "github.com/amir-the-h/okex/responses/public_data"
"net/http"
)
Expand Down
2 changes: 1 addition & 1 deletion api/rest/sub_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package rest
import (
"encoding/json"
"github.com/amir-the-h/okex"
requests "github.com/amir-the-h/okex/requests/rest/sub_account"
requests "github.com/amir-the-h/okex/requests/rest/subaccount"
responses "github.com/amir-the-h/okex/responses/sub_account"
"net/http"
)
Expand Down
2 changes: 1 addition & 1 deletion api/rest/trade_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package rest
import (
"encoding/json"
"github.com/amir-the-h/okex"
requests "github.com/amir-the-h/okex/requests/rest/trade_data"
requests "github.com/amir-the-h/okex/requests/rest/tradedata"
responses "github.com/amir-the-h/okex/responses/trade_data"
"net/http"
)
Expand Down
4 changes: 2 additions & 2 deletions api/ws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ClientWs struct {
SubscribeChan chan *events.Subscribe
UnsubscribeCh chan *events.Unsubscribe
sendChan map[bool]chan []byte
url map[bool]okex.BaseUrl
url map[bool]okex.BaseURL
conn map[bool]*websocket.Conn
apiKey string
secretKey []byte
Expand All @@ -51,7 +51,7 @@ const (
)

// NewClient returns a pointer to a fresh ClientWs
func NewClient(ctx context.Context, apiKey, secretKey, passphrase string, url map[bool]okex.BaseUrl) *ClientWs {
func NewClient(ctx context.Context, apiKey, secretKey, passphrase string, url map[bool]okex.BaseURL) *ClientWs {
ctx, cancel := context.WithCancel(ctx)
c := &ClientWs{
apiKey: apiKey,
Expand Down
36 changes: 18 additions & 18 deletions definitions.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package okex_v5_go_sdk is generally a golang Api wrapper of Okex V5 API
// Package okex is generally a golang Api wrapper of Okex V5 API
//
// https://www.okex.com/docs-v5/en
package okex
Expand All @@ -11,7 +11,7 @@ import (
)

type (
BaseUrl string
BaseURL string
InstrumentType string
MarginMode string
ContractType string
Expand Down Expand Up @@ -48,25 +48,25 @@ type (
WithdrawalDestination uint8
WithdrawalState int8

JsonFloat64 float64
JsonInt64 int64
JsonTime time.Time
JSONFloat64 float64
JSONInt64 int64
JSONTime time.Time

ClientError error
)

const (
RestUrl = BaseUrl("https://www.okex.com")
PublicWsUrl = BaseUrl("wss://ws.okex.com:8443/ws/v5/public")
PrivateWsUrl = BaseUrl("wss://ws.okex.com:8443/ws/v5/private")
RestURL = BaseURL("https://www.okex.com")
PublicWsURL = BaseURL("wss://ws.okex.com:8443/ws/v5/public")
PrivateWsURL = BaseURL("wss://ws.okex.com:8443/ws/v5/private")

AwsRestUrl = BaseUrl("https://aws.okex.com")
AwsPublicWsUrl = BaseUrl("wss://wsaws.okex.com:8443/ws/v5/public")
AwsPrivateWsUrl = BaseUrl("wss://wsaws.okex.com:8443/ws/v5/private")
AwsRestURL = BaseURL("https://aws.okex.com")
AwsPublicWsURL = BaseURL("wss://wsaws.okex.com:8443/ws/v5/public")
AwsPrivateWsURL = BaseURL("wss://wsaws.okex.com:8443/ws/v5/private")

DemoRestUrl = BaseUrl("https://www.okex.com")
DemoPublicWsUrl = BaseUrl("wss://wspap.okex.com:8443/ws/v5/public?brokerId=9999")
DemoPrivateWsUrl = BaseUrl("wss://wspap.okex.com:8443/ws/v5/private?brokerId=9999")
DemoRestURL = BaseURL("https://www.okex.com")
DemoPublicWsURL = BaseURL("wss://wspap.okex.com:8443/ws/v5/public?brokerId=9999")
DemoPrivateWsURL = BaseURL("wss://wspap.okex.com:8443/ws/v5/private?brokerId=9999")

NormalServer = Destination(iota + 1)
AwsServer = NormalServer + 1
Expand Down Expand Up @@ -287,9 +287,9 @@ const (
CandleStick1m = CandleStickWsBarSize("candle1m")
)

func (t JsonTime) String() string { return time.Time(t).String() }
func (t JSONTime) String() string { return time.Time(t).String() }

func (t *JsonTime) UnmarshalJSON(s []byte) (err error) {
func (t *JSONTime) UnmarshalJSON(s []byte) (err error) {
r := strings.Replace(string(s), `"`, ``, -1)
if r == "" {
return
Expand All @@ -302,7 +302,7 @@ func (t *JsonTime) UnmarshalJSON(s []byte) (err error) {
*(*time.Time)(t) = time.UnixMilli(q)
return
}
func (t *JsonFloat64) UnmarshalJSON(s []byte) (err error) {
func (t *JSONFloat64) UnmarshalJSON(s []byte) (err error) {
r := strings.Replace(string(s), `"`, ``, -1)
if r == "" {
return
Expand All @@ -315,7 +315,7 @@ func (t *JsonFloat64) UnmarshalJSON(s []byte) (err error) {
*(*float64)(t) = q
return
}
func (t *JsonInt64) UnmarshalJSON(s []byte) (err error) {
func (t *JSONInt64) UnmarshalJSON(s []byte) (err error) {
r := strings.Replace(string(s), `"`, ``, -1)
if r == "" {
return
Expand Down
4 changes: 2 additions & 2 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type (
Event string `json:"event,omitempty"`
Msg string `json:"msg,omitempty"`
Op string `json:"op,omitempty"`
Code okex.JsonInt64 `json:"code"`
Id okex.JsonInt64 `json:"id,omitempty"`
Code okex.JSONInt64 `json:"code"`
Id okex.JSONInt64 `json:"id,omitempty"`
}
Login struct {
Event string `json:"event"`
Expand Down
Loading

0 comments on commit 110cd70

Please sign in to comment.