Skip to content

Commit

Permalink
Style: Fix README code indent and contents
Browse files Browse the repository at this point in the history
  • Loading branch information
eynzhang committed Apr 20, 2020
1 parent 8401378 commit b5239dd
Showing 1 changed file with 147 additions and 147 deletions.
294 changes: 147 additions & 147 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ The SDK supports RESTful API invoking, and subscribe the market, account and ord
- [Trading](#trading)
- [Margin Loan](#margin-loan)
- [Subscription examples](#Subscription-examples)
- [Subscribe trade update](#Subscribe-trade-update)
- [Subscribe candlestick update](#Subscribe-candlestick-update)
- [Subscribe candlestick update](#subscribe-candlestick-update)
- [Subscribe account update](#subscribe-account-update)
- [Subscribe order update](#subscribe-order-update)
- [Subscribe account change](#subscribe-account-change)
- [Subscribe trade update](#subscribe-trade-update)
- [Unsubscribe](#unsubscribe)

## Quick Start
Expand All @@ -37,8 +37,8 @@ The SDK is compiled by Go 1.13.7, you can import this SDK in your Golang project

```go
import (
"fmt"
"github.com/huobirdcenter/huobi_golang/pkg/client"
"fmt"
"github.com/huobirdcenter/huobi_golang/pkg/client"
)

// Get the timestamp from Huobi server and print on console
Expand Down Expand Up @@ -350,7 +350,7 @@ resp, err := client.CancelOrdersByCriteria(&request)
#### Get order info

```go
client := new(client.OrderClient).Init(config.AccessKey, config.SecretKey, config.Host) resp, err := client.GetOrderById("1")
client := new(client.OrderClient).Init(config.AccessKey, config.SecretKey, config.Host) resp, err := client.GetOrderById("1")
```

#### Historical orders
Expand Down Expand Up @@ -395,7 +395,7 @@ resp, err := client.MarginOrdersRepay(orderId, request)
client := new(client.IsolatedMarginClient).Init(config.AccessKey, config.SecretKey, config.Host)
optionalRequest := getrequest.IsolatedMarginLoanOrdersOptionalRequest{
StartDate: "2020-1-1",
}
}

resp, err := client.MarginLoanOrders("btcusdt", optionalRequest)
```
Expand Down Expand Up @@ -462,54 +462,54 @@ if err != nil {

```go
// Initialize a new instance for account update websocket v2 client
client := new(accountwebsocketclient.SubscribeAccountWebSocketV2Client).Init(config.AccessKey, config.SecretKey, config.Host)

// Set the callback handlers
client.SetHandler(
// Authentication response handler
func(resp *auth.WebSocketV2AuthenticationResponse) {
if resp.IsSuccess() {
err := client.Subscribe("1", "1149")
if err != nil {
fmt.Printf("Subscribe error: %s\n", err)
} else {
fmt.Println("Sent subscription")
}
} else {
fmt.Printf("Authentication error, code: %d, message:%s\n", resp.Code, resp.Message)
}
},
// Response handler
func(resp interface{}) {
subResponse, ok := resp.(account.SubscribeAccountV2Response)
if ok {
if subResponse.Action == "sub" {
if subResponse.IsSuccess() {
fmt.Printf("Subscription topic %s successfully\n", subResponse.Ch)
} else {
fmt.Printf("Subscription topic %s error, code: %d, message: %s\n", subResponse.Ch, subResponse.Code, subResponse.Message)
}
} else if subResponse.Action == "push" {
if subResponse.Data != nil {
b := subResponse.Data
if b.ChangeTime == 0 {
fmt.Printf("Account overview, id: %d, currency: %s, balance: %s\n", b.AccountId, b.Currency, b.Balance)
} else {
fmt.Printf("Account update, id: %d, currency: %s, balance: %s, time: %d\n", b.AccountId, b.Currency, b.Balance, b.ChangeTime)
}
}
}
} else {
fmt.Printf("Received unknown response: %v\n", resp)
}
})

// Connect to the server and wait for the handler to handle the response
err := client.Connect(true)
if err != nil {
fmt.Printf("Client Connect error: %s\n", err)
return
}
client := new(accountwebsocketclient.SubscribeAccountWebSocketV2Client).Init(config.AccessKey, config.SecretKey, config.Host)

// Set the callback handlers
client.SetHandler(
// Authentication response handler
func(resp *auth.WebSocketV2AuthenticationResponse) {
if resp.IsSuccess() {
err := client.Subscribe("1", "1149")
if err != nil {
fmt.Printf("Subscribe error: %s\n", err)
} else {
fmt.Println("Sent subscription")
}
} else {
fmt.Printf("Authentication error, code: %d, message:%s\n", resp.Code, resp.Message)
}
},
// Response handler
func(resp interface{}) {
subResponse, ok := resp.(account.SubscribeAccountV2Response)
if ok {
if subResponse.Action == "sub" {
if subResponse.IsSuccess() {
fmt.Printf("Subscription topic %s successfully\n", subResponse.Ch)
} else {
fmt.Printf("Subscription topic %s error, code: %d, message: %s\n", subResponse.Ch, subResponse.Code, subResponse.Message)
}
} else if subResponse.Action == "push" {
if subResponse.Data != nil {
b := subResponse.Data
if b.ChangeTime == 0 {
fmt.Printf("Account overview, id: %d, currency: %s, balance: %s\n", b.AccountId, b.Currency, b.Balance)
} else {
fmt.Printf("Account update, id: %d, currency: %s, balance: %s, time: %d\n", b.AccountId, b.Currency, b.Balance, b.ChangeTime)
}
}
}
} else {
fmt.Printf("Received unknown response: %v\n", resp)
}
})

// Connect to the server and wait for the handler to handle the response
err := client.Connect(true)
if err != nil {
fmt.Printf("Client Connect error: %s\n", err)
return
}
```

### Subscribe order update
Expand All @@ -518,52 +518,52 @@ if err != nil {

```go
// Initialize a new instance
client := new(orderwebsocketclient.SubscribeOrderWebSocketV2Client).Init(config.AccessKey, config.SecretKey, config.Host)

// Set the callback handlers
client.SetHandler(
// Connected handler
func(resp *auth.WebSocketV2AuthenticationResponse) {
if resp.IsSuccess() {
// Subscribe if authentication passed
err := client.Subscribe("btcusdt", "1149")
if err != nil {
fmt.Printf("Subscribe error: %s\n", err)
} else {
fmt.Println("Sent subscription")
}
} else {
fmt.Printf("Authentication error, code: %d, message:%s\n", resp.Code, resp.Message)
}
},
// Response handler
func(resp interface{}) {
subResponse, ok := resp.(order.SubscribeOrderV2Response)
if ok {
if subResponse.Action == "sub" {
if subResponse.IsSuccess() {
fmt.Printf("Subscription topic %s successfully\n", subResponse.Ch)
} else {
fmt.Printf("Subscription topic %s error, code: %d, message: %s\n", subResponse.Ch, subResponse.Code, subResponse.Message)
}
} else if subResponse.Action == "push" {
if subResponse.Data != nil {
o := subResponse.Data
fmt.Printf("Order update, event: %s, symbol: %s, type: %s, status: %s\n",
o.EventType, o.Symbol, o.Type, o.OrderStatus)
}
}
} else {
fmt.Printf("Received unknown response: %v\n", resp)
}
})

// Connect to the server and wait for the handler to handle the response
err := client.Connect(true)
if err != nil {
fmt.Printf("Client Connect error: %s\n", err)
return
}
client := new(orderwebsocketclient.SubscribeOrderWebSocketV2Client).Init(config.AccessKey, config.SecretKey, config.Host)

// Set the callback handlers
client.SetHandler(
// Connected handler
func(resp *auth.WebSocketV2AuthenticationResponse) {
if resp.IsSuccess() {
// Subscribe if authentication passed
err := client.Subscribe("btcusdt", "1149")
if err != nil {
fmt.Printf("Subscribe error: %s\n", err)
} else {
fmt.Println("Sent subscription")
}
} else {
fmt.Printf("Authentication error, code: %d, message:%s\n", resp.Code, resp.Message)
}
},
// Response handler
func(resp interface{}) {
subResponse, ok := resp.(order.SubscribeOrderV2Response)
if ok {
if subResponse.Action == "sub" {
if subResponse.IsSuccess() {
fmt.Printf("Subscription topic %s successfully\n", subResponse.Ch)
} else {
fmt.Printf("Subscription topic %s error, code: %d, message: %s\n", subResponse.Ch, subResponse.Code, subResponse.Message)
}
} else if subResponse.Action == "push" {
if subResponse.Data != nil {
o := subResponse.Data
fmt.Printf("Order update, event: %s, symbol: %s, type: %s, status: %s\n",
o.EventType, o.Symbol, o.Type, o.OrderStatus)
}
}
} else {
fmt.Printf("Received unknown response: %v\n", resp)
}
})

// Connect to the server and wait for the handler to handle the response
err := client.Connect(true)
if err != nil {
fmt.Printf("Client Connect error: %s\n", err)
return
}
```

### Subscribe trade update
Expand All @@ -572,52 +572,52 @@ if err != nil {

```go
// Initialize a new instance
client := new(orderwebsocketclient.SubscribeTradeClearWebSocketV2Client).Init(config.AccessKey, config.SecretKey, config.Host)

// Set the callback handlers
client.SetHandler(
// Connected handler
func(resp *auth.WebSocketV2AuthenticationResponse) {
if resp.IsSuccess() {
// Subscribe if authentication passed
err := client.Subscribe("btcusdt", "1149")
if err != nil {
fmt.Printf("Subscribe error: %s\n", err)
} else {
fmt.Println("Sent subscription")
}
} else {
fmt.Printf("Authentication error, code: %d, message:%s\n", resp.Code, resp.Message)
}
},
// Response handler
func(resp interface{}) {
subResponse, ok := resp.(order.SubscribeTradeClearResponse)
if ok {
if subResponse.Action == "sub" {
if subResponse.IsSuccess() {
fmt.Printf("Subscription topic %s successfully\n", subResponse.Ch)
} else {
fmt.Printf("Subscription topic %s error, code: %d, message: %s\n", subResponse.Ch, subResponse.Code, subResponse.Message)
}
} else if subResponse.Action == "push" {
if subResponse.Data != nil {
o := subResponse.Data
fmt.Printf("Order update, symbol: %s, order id: %d, price: %s, volume: %s\n",
o.Symbol, o.OrderId, o.TradePrice, o.TradeVolume)
}
}
} else {
fmt.Printf("Received unknown response: %v\n", resp)
}
})

// Connect to the server and wait for the handler to handle the response
err := client.Connect(true)
if err != nil {
fmt.Printf("Client Connect error: %s\n", err)
return
}
client := new(orderwebsocketclient.SubscribeTradeClearWebSocketV2Client).Init(config.AccessKey, config.SecretKey, config.Host)

// Set the callback handlers
client.SetHandler(
// Connected handler
func(resp *auth.WebSocketV2AuthenticationResponse) {
if resp.IsSuccess() {
// Subscribe if authentication passed
err := client.Subscribe("btcusdt", "1149")
if err != nil {
fmt.Printf("Subscribe error: %s\n", err)
} else {
fmt.Println("Sent subscription")
}
} else {
fmt.Printf("Authentication error, code: %d, message:%s\n", resp.Code, resp.Message)
}
},
// Response handler
func(resp interface{}) {
subResponse, ok := resp.(order.SubscribeTradeClearResponse)
if ok {
if subResponse.Action == "sub" {
if subResponse.IsSuccess() {
fmt.Printf("Subscription topic %s successfully\n", subResponse.Ch)
} else {
fmt.Printf("Subscription topic %s error, code: %d, message: %s\n", subResponse.Ch, subResponse.Code, subResponse.Message)
}
} else if subResponse.Action == "push" {
if subResponse.Data != nil {
o := subResponse.Data
fmt.Printf("Order update, symbol: %s, order id: %d, price: %s, volume: %s\n",
o.Symbol, o.OrderId, o.TradePrice, o.TradeVolume)
}
}
} else {
fmt.Printf("Received unknown response: %v\n", resp)
}
})

// Connect to the server and wait for the handler to handle the response
err := client.Connect(true)
if err != nil {
fmt.Printf("Client Connect error: %s\n", err)
return
}
```

## Unsubscribe
Expand Down

0 comments on commit b5239dd

Please sign in to comment.