Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
f0cii committed Apr 23, 2020
1 parent 52e156f commit c074aa4
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 19 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
)
func main() {
b := bitmex.New(bitmex.HostTestnet, "8K2Oi0bnRRZ7GK4UJnY-38oj", "9EmGvk8mKX5nWa11y1KyPPGn78Lv2ZEiLx3TH0YasE_oE06y")
b := bitmex.New(nil,
bitmex.HostTestnet, "8K2Oi0bnRRZ7GK4UJnY-38oj", "9EmGvk8mKX5nWa11y1KyPPGn78Lv2ZEiLx3TH0YasE_oE06y", true)
subscribeInfos := []bitmex.SubscribeInfo{
{Op: bitmex.BitmexWSOrderBookL2, Param: "XBTUSD"},
{Op: bitmex.BitmexWSOrder, Param: "XBTUSD"},
Expand Down
21 changes: 13 additions & 8 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ type RateLimit struct {

// BitMEX describes the API
type BitMEX struct {
Key string
Secret string
host string
proxyURL string
Key string
Secret string
host string
proxyURL string
debugMode bool

ctx context.Context
timeout time.Duration
Expand All @@ -53,10 +54,11 @@ type BitMEX struct {
}

// New allows the use of the public or private and websocket api
func New(host string, key string, secret string) *BitMEX {
func New(httpClient *http.Client, host string, key string, secret string, debugMode bool) *BitMEX {
b := &BitMEX{}
b.Key = key
b.Secret = secret
b.debugMode = debugMode
b.emitter = emission.NewEmitter()
b.orderBookLocals = make(map[string]*OrderBookLocal)
b.orderLocals = make(map[string]*swagger.Order)
Expand All @@ -68,10 +70,13 @@ func New(host string, key string, secret string) *BitMEX {
b.ctx = MakeContext(key, secret, host, 10)
b.timeout = 10 * time.Second
b.cfg = GetConfiguration(b.ctx)
b.httpClient = &http.Client{
Timeout: b.timeout,
if httpClient == nil {
httpClient = &http.Client{
Timeout: b.timeout,
}
}
b.cfg.HTTPClient = b.httpClient
b.httpClient = httpClient
b.cfg.HTTPClient = httpClient
b.client = swagger.NewAPIClient(b.cfg)
return b
}
Expand Down
4 changes: 2 additions & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newBitmexForTest() *BitMEX {
} else {
host = HostReal
}
bitmex := New(host, _key, _secret)
bitmex := New(nil, host, _key, _secret, true)
if _proxyURL != "" {
bitmex.SetHttpProxy(_proxyURL)
}
Expand All @@ -75,7 +75,7 @@ func newBitmexForTest2() *BitMEX {
} else {
host = HostReal
}
bitmex := New(host, _key2, _secret2)
bitmex := New(nil, host, _key2, _secret2, true)
if _proxyURL != "" {
bitmex.SetHttpProxy(_proxyURL)
}
Expand Down
3 changes: 2 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

func main() {
b := bitmex.New(bitmex.HostTestnet, "8K2Oi0bnRRZ7GK4UJnY-38oj", "9EmGvk8mKX5nWa11y1KyPPGn78Lv2ZEiLx3TH0YasE_oE06y")
b := bitmex.New(nil,
bitmex.HostTestnet, "8K2Oi0bnRRZ7GK4UJnY-38oj", "9EmGvk8mKX5nWa11y1KyPPGn78Lv2ZEiLx3TH0YasE_oE06y", true)
subscribeInfos := []bitmex.SubscribeInfo{
{Op: bitmex.BitmexWSOrderBookL2, Param: "XBTUSD"},
{Op: bitmex.BitmexWSOrder, Param: "XBTUSD"},
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ require (
github.com/frankrap/goalgo v0.0.0-20191222082958-86150f79a9c1 // indirect
github.com/gorilla/websocket v1.4.2
github.com/jpillora/backoff v1.0.0
github.com/micro/go-micro v1.14.0
github.com/micro/go-micro v1.18.0
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/pkg/errors v0.9.1
github.com/recws-org/recws v1.2.1 // indirect
github.com/recws-org/recws v1.2.1
github.com/tidwall/gjson v1.6.0
golang.org/x/net v0.0.0-20191011234655-491137f69257
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
)
91 changes: 91 additions & 0 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions swagger/order_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ func (a *OrderApiService) OrderGetOrders(ctx context.Context, localVarOptionals
localVarHttpResponse.Status,
string(localVarOptionalsJson),
string(bodyBytes),
)
)
}

if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
Expand Down Expand Up @@ -1131,7 +1131,7 @@ func (a *OrderApiService) OrderNew(ctx context.Context, symbol string, localVarO
localVarHttpResponse.Status,
string(localVarOptionalsJson),
string(bodyBytes),
)
)
}

if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/frankrap/bitmex-api/swagger"
"github.com/gorilla/websocket"
"github.com/pkg/errors"
"github.com/frankrap/bitmex-api/swagger"
"github.com/tidwall/gjson"
"log"
"net/url"
Expand Down

0 comments on commit c074aa4

Please sign in to comment.