Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
shaodan committed Mar 17, 2020
1 parent e5ae062 commit e51c7ca
Show file tree
Hide file tree
Showing 42 changed files with 187 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func marginOrders() {
client := new(client.IsolatedMarginClient).Init(config.AccessKey, config.SecretKey, config.Host)
request := postrequest.IsolatedMarginOrdersRequest{
Currency: "eos",
Amount: "0.001",
Symbol: "eosht",
Amount: "0.001",
Symbol: "eosht",
}
resp, err := client.Apply(request)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func runAll() {
orderwebsocketclientexample.RunAllExamples()
}


// Run performance test
func perfTest() {
logging.EnablePerformanceLog(true)
Expand All @@ -47,4 +46,4 @@ func perfTest() {
crossmarginclientexample.RunAllExamples()
walletclientexample.RunAllExamples()
etfclientexample.RunAllExamples()
}
}
26 changes: 13 additions & 13 deletions cmd/marketwebsocketclientexample/marketwebsocketclientexample.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ func reqAndSubscribeDepth() {
if depthResponse.Tick != nil {
if depthResponse.Tick.Asks != nil {
a := depthResponse.Tick.Asks
for i := len(a)-1; i >= 0; i-- {
for i := len(a) - 1; i >= 0; i-- {
fmt.Printf("%v - %v\n", a[i][0], a[i][1])
}
}
fmt.Println("---ask-bid-update--")
if depthResponse.Tick.Bids != nil {
b := depthResponse.Tick.Bids
for i:= 0; i < len(b); i++ {
for i := 0; i < len(b); i++ {
fmt.Printf("%v - %v\n", b[i][0], b[i][1])
}
}
Expand All @@ -123,14 +123,14 @@ func reqAndSubscribeDepth() {
if depthResponse.Data != nil {
if depthResponse.Data.Asks != nil {
a := depthResponse.Data.Asks
for i := len(a)-1; i >= 0; i-- {
for i := len(a) - 1; i >= 0; i-- {
fmt.Printf("%v - %v\n", a[i][0], a[i][1])
}
}
fmt.Println("---ask-bid-data--")
if depthResponse.Data.Bids != nil {
b := depthResponse.Data.Bids
for i:= 0; i < len(b); i++ {
for i := 0; i < len(b); i++ {
fmt.Printf("%v - %v\n", b[i][0], b[i][1])
}
}
Expand Down Expand Up @@ -189,13 +189,13 @@ func reqAndSubscribeMarketByPrice() {
t := depthResponse.Tick
fmt.Printf("MBP prevSeqNum: %d, seqNum: %d\n", t.PrevSeqNum, t.SeqNum)
if t.Asks != nil {
for i := len(t.Asks)-1; i >= 0; i-- {
for i := len(t.Asks) - 1; i >= 0; i-- {
fmt.Printf("%v - %v\n", t.Asks[i][0], t.Asks[i][1])
}
}
fmt.Println("---MBP-update--")
if t.Bids != nil {
for i:= 0; i < len(t.Bids); i++ {
for i := 0; i < len(t.Bids); i++ {
fmt.Printf("%v - %v\n", t.Bids[i][0], t.Bids[i][1])
}
}
Expand All @@ -207,14 +207,14 @@ func reqAndSubscribeMarketByPrice() {
fmt.Printf("MBP prevSeqNum: %d, seqNum: %d\n", d.PrevSeqNum, d.SeqNum)
if d.Asks != nil {
a := d.Asks
for i := len(a)-1; i >= 0; i-- {
for i := len(a) - 1; i >= 0; i-- {
fmt.Printf("%v - %v\n", a[i][0], a[i][1])
}
}
fmt.Println("---MBP-data--")
if depthResponse.Data.Bids != nil {
b := depthResponse.Data.Bids
for i:= 0; i < len(b); i++ {
for i := 0; i < len(b); i++ {
fmt.Printf("%v - %v\n", b[i][0], b[i][1])
}
}
Expand Down Expand Up @@ -381,13 +381,13 @@ func reqAndSubscribeLast24hCandlestick() {

if candlestickResponse.Data != nil {
t := candlestickResponse.Data
fmt.Printf("Candlestick data, id: %d, count: %v, volume: %v [%v-%v-%v-%v]\n",
t.Id, t.Count, t.Vol, t.Open, t.Close, t.Low, t.High)
}
fmt.Printf("Candlestick data, id: %d, count: %v, volume: %v [%v-%v-%v-%v]\n",
t.Id, t.Count, t.Vol, t.Open, t.Close, t.Low, t.High)
}
} else {
fmt.Printf("Unknown response: %v\n", resp)
}
} else {
fmt.Printf("Unknown response: %v\n", resp)
}

})

Expand Down
3 changes: 1 addition & 2 deletions cmd/orderclientexample/orderclientexample.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ func getLast48hOrders() {
}
}


func getMatchResultByCriteria() {
client := new(client.OrderClient).Init(config.AccessKey, config.SecretKey, config.Host)
request := new(getrequest.GetRequest).Init()
Expand Down Expand Up @@ -342,4 +341,4 @@ func getTransactFeeRate() {
fmt.Printf("Get fee error: %s\n", resp.Message)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ func reqOrdersV1() {
func(resp *model.WebSocketV1AuthenticationResponse) {
if resp.ErrorCode == 0 {
req := getrequest.RequestOrdersRequest{
AccountId:11136102,
Symbol:"btcusdt",
States:"submitted, created, canceled",
AccountId: 11136102,
Symbol: "btcusdt",
States: "submitted, created, canceled",
}
err := client.Request(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/gzip/gzipdecompresser.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ func GZipCompress(input string) ([]byte, error) {
}

return buf.Bytes(), nil
}
}
2 changes: 1 addition & 1 deletion internal/gzip/gzipdecompresser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ func Test_Decompress_Success(t *testing.T) {
if result != expected {
t.Errorf("expected: %s, actual: %s", expected, result)
}
}
}
2 changes: 1 addition & 1 deletion internal/httprequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ func HttpPost(url string, body string) (string, error) {
logger.StopAndLog("POST", url)

return string(result), err
}
}
2 changes: 1 addition & 1 deletion internal/model/pingmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ func ParsePingMessage(message string) *PingMessage {
}

return &result
}
}
10 changes: 5 additions & 5 deletions internal/model/websocketv1authenticationresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package model
import "encoding/json"

type WebSocketV1AuthenticationResponse struct {
Op string `json:"op"`
Timestamp int64 `json:"ts"`
ErrorCode int `json:"err-code"`
Data *struct {
Op string `json:"op"`
Timestamp int64 `json:"ts"`
ErrorCode int `json:"err-code"`
Data *struct {
UserId int `json:"user-id"`
}
}
Expand All @@ -23,4 +23,4 @@ func ParseWSV1AuthResp(message string) *WebSocketV1AuthenticationResponse {
}

return result
}
}
8 changes: 4 additions & 4 deletions internal/model/websocketv2authenticationresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import "encoding/json"

type WebSocketV2AuthenticationResponse struct {
Action string `json:"action"`
Ch string `json:"ch"`
Code int `json:"code"`
Data interface{}
Ch string `json:"ch"`
Code int `json:"code"`
Data interface{}
}

func (p *WebSocketV2AuthenticationResponse) IsAuth() bool {
Expand All @@ -21,4 +21,4 @@ func ParseWSV2AuthResp(message string) *WebSocketV2AuthenticationResponse {
}

return result
}
}
14 changes: 7 additions & 7 deletions internal/requestbuilder/privateurlbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
)

type PrivateUrlBuilder struct {
host string
akKey string
host string
akKey string
akValue string
smKey string
smKey string
smValue string
svKey string
svKey string
svValue string
tKey string
tKey string

signer *Signer
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func (p *PrivateUrlBuilder) BuildWithTime(method string, path string, utcDate ti

signature := p.signer.Sign(method, p.host, path, parameters)

url := fmt.Sprintf("https://%s%s?%s&Signature=%s",p.host, path, parameters, url.QueryEscape(signature))
url := fmt.Sprintf("https://%s%s?%s&Signature=%s", p.host, path, parameters, url.QueryEscape(signature))

return url
}
}
8 changes: 4 additions & 4 deletions internal/requestbuilder/privateurlbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

func TestPrivateUrlBuilder_Build_NoRequestParameter_Success(t *testing.T) {
builder := new(PrivateUrlBuilder).Init("access","secret", "api.huobi.pro")
utcDate := time.Date(2019,11,21,10,0,0, 0, time.UTC)
builder := new(PrivateUrlBuilder).Init("access", "secret", "api.huobi.pro")
utcDate := time.Date(2019, 11, 21, 10, 0, 0, 0, time.UTC)

result := builder.BuildWithTime("GET", "/v1/account/accounts", utcDate, nil)

Expand All @@ -20,8 +20,8 @@ func TestPrivateUrlBuilder_Build_NoRequestParameter_Success(t *testing.T) {
}

func TestPrivateUrlBuilder_Build_HasRequestParameter_Success(t *testing.T) {
builder := new(PrivateUrlBuilder).Init("access","secret", "api.huobi.pro")
utcDate := time.Date(2019,11,21,10,0,0, 0, time.UTC)
builder := new(PrivateUrlBuilder).Init("access", "secret", "api.huobi.pro")
utcDate := time.Date(2019, 11, 21, 10, 0, 0, 0, time.UTC)
reqParams := new(getrequest.GetRequest).Init()
reqParams.AddParam("account-id", "123")
reqParams.AddParam("currency", "btc")
Expand Down
2 changes: 1 addition & 1 deletion internal/requestbuilder/publicurlbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ func (p *PublicUrlBuilder) Build(path string, request *getrequest.GetRequest) st
result := fmt.Sprintf("https://%s%s", p.host, path)
return result
}
}
}
5 changes: 2 additions & 3 deletions internal/requestbuilder/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func (p *Signer) Init(key string) *Signer {
return p
}


func (p *Signer) Sign(method string, host string, path string, parameters string) string {
if method == "" || host == "" || path == "" || parameters == "" {
return ""
Expand All @@ -36,7 +35,7 @@ func (p *Signer) Sign(method string, host string, path string, parameters string
}

func (p *Signer) sign(payload string) string {
p.hash.Write([]byte (payload))
p.hash.Write([]byte(payload))
result := base64.StdEncoding.EncodeToString(p.hash.Sum(nil))
return result
}
}
2 changes: 1 addition & 1 deletion internal/requestbuilder/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func TestSigner_Sign_OneEmptyString_Success(t *testing.T) {
if result != expected {
t.Errorf("expected: %s, actual: %s", expected, result)
}
}
}
2 changes: 1 addition & 1 deletion logging/performancelogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ func (p *PerformanceLogger) StopAndLog(method string, url string) {

p.index++
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ func (p *RequestAccountWebSocketV1Client) handleMessage(msg string) (interface{}
result := account.RequestAccountV1Response{}
err := json.Unmarshal([]byte(msg), &result)
return result, err
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ func (p *SubscribeAccountWebSocketV1Client) handleMessage(msg string) (interface
result := account.SubscribeAccountV1Response{}
err := json.Unmarshal([]byte(msg), &result)
return result, err
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ func (p *MarketByPriceWebSocketClient) handleMessage(msg string) (interface{}, e
result := market.SubscribeMarketByPriceResponse{}
err := json.Unmarshal([]byte(msg), &result)
return result, err
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ func (p *SubscribeOrderWebSocketV2Client) handleMessage(msg string) (interface{}
result := &order.SubscribeOrderV2Response{}
err := json.Unmarshal([]byte(msg), result)
return result, err
}
}
12 changes: 6 additions & 6 deletions pkg/client/websocketclientbase/websocketv2clientbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ type AuthenticationV2ResponseHandler func(resp *model.WebSocketV2AuthenticationR

// The base class that responsible to get data from websocket authentication v2
type WebSocketV2ClientBase struct {
host string
conn *websocket.Conn
host string
conn *websocket.Conn

authenticationResponseHandler AuthenticationV2ResponseHandler
messageHandler MessageHandler
responseHandler ResponseHandler

stopReadChannel chan int
stopTickerChannel chan int
ticker *time.Ticker
lastReceivedTime time.Time
stopReadChannel chan int
stopTickerChannel chan int
ticker *time.Ticker
lastReceivedTime time.Time

requestBuilder *requestbuilder.WebSocketV2RequestBuilder
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/getrequest/getrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ func (p *GetRequest) AddParam(property string, value string) *GetRequest {
// Concat the property and value pair
func (p *GetRequest) BuildParams() string {
return p.urls.Encode()
}
}
3 changes: 1 addition & 2 deletions pkg/getrequest/getrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func TestAddParam_ValueEmpty_ReturnEmpty(t *testing.T) {
}
}


func TestBuildParam_NullParam_ReturnEmpty(t *testing.T) {
request := new(GetRequest).Init()

Expand Down Expand Up @@ -76,4 +75,4 @@ func TestBuildParam_TwoParams_ReturnOrderedTwoPairs(t *testing.T) {
if result != expected {
t.Errorf("expected: %s, actual: %s", expected, result)
}
}
}
Loading

0 comments on commit e51c7ca

Please sign in to comment.