diff --git a/config.json b/config.json index 89fdeea..f3b9184 100644 --- a/config.json +++ b/config.json @@ -3,11 +3,13 @@ "Master": { "Host": "www.bitmex.com", "Key": "123", - "Secret": "abc" + "Secret": "abc", + "Timeout": 20 }, "Dev": { "Host": "testnet.bitmex.com", "Key": "123", - "Secret": "abc" + "Secret": "abc", + "Timeout": 20 } } \ No newline at end of file diff --git a/config/config.go b/config/config.go index a1128f2..e2dd5cd 100644 --- a/config/config.go +++ b/config/config.go @@ -1,16 +1,17 @@ package config import ( - "os" "encoding/json" "github.com/vmpartner/bitmex/tools" + "os" ) type Config struct { - Host string - Key string - Secret string - DB struct { + Host string + Key string + Secret string + Timeout int64 + DB struct { Host string Login string Password string @@ -52,4 +53,4 @@ func LoadMasterConfig(path string) MasterConfig { tools.CheckErr(err) return config -} \ No newline at end of file +} diff --git a/main.go b/main.go index fd0ed7c..4a7dd69 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,13 @@ package main import ( + "fmt" + "github.com/vmpartner/bitmex/bitmex" "github.com/vmpartner/bitmex/config" "github.com/vmpartner/bitmex/rest" + "github.com/vmpartner/bitmex/tools" "github.com/vmpartner/bitmex/websocket" - "fmt" "strings" - "github.com/vmpartner/bitmex/bitmex" - "github.com/vmpartner/bitmex/tools" ) // Usage example @@ -15,7 +15,7 @@ func main() { // Load config cfg := config.LoadConfig("config.json") - ctx := rest.MakeContext(cfg.Key, cfg.Secret, cfg.Host) + ctx := rest.MakeContext(cfg.Key, cfg.Secret, cfg.Host, cfg.Timeout) // Get wallet w, response, err := rest.GetWallet(ctx) diff --git a/rest/rest.go b/rest/rest.go index e88958c..e6a3e18 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -6,11 +6,12 @@ import ( "net/http" ) -func MakeContext(key string, secret string, host string) context.Context { +func MakeContext(key string, secret string, host string, timeout int64) context.Context { return context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{ - Key: key, - Secret: secret, - Host: host, + Key: key, + Secret: secret, + Host: host, + Timeout: timeout, }) } @@ -76,4 +77,4 @@ func GetWallet(ctx context.Context) (swagger.Wallet, *http.Response, error) { wallet, response, err := client.UserApi.UserGetWallet(ctx, params) return wallet, response, err -} \ No newline at end of file +} diff --git a/swagger/configuration.go b/swagger/configuration.go index 2dfbb57..da12374 100644 --- a/swagger/configuration.go +++ b/swagger/configuration.go @@ -1,7 +1,7 @@ -/* +/* * BitMEX API * - * ## REST API for the BitMEX Trading Platform [View Changelog](/app/apiChangelog) #### Getting Started ##### Fetching Data All REST endpoints are documented below. You can try out any query right from this interface. Most table queries accept `count`, `start`, and `reverse` params. Set `reverse=true` to get rows newest-first. Additional documentation regarding filters, timestamps, and authentication is available in [the main API documentation](https://www.bitmex.com/app/restAPI). *All* table data is available via the [Websocket](/app/wsAPI). We highly recommend using the socket if you want to have the quickest possible data without being subject to ratelimits. ##### Return Types By default, all data is returned as JSON. Send `?_format=csv` to get CSV data or `?_format=xml` to get XML data. ##### Trade Data Queries *This is only a small subset of what is available, to get you started.* Fill in the parameters and click the `Try it out!` button to try any of these queries. * [Pricing Data](#!/Quote/Quote_get) * [Trade Data](#!/Trade/Trade_get) * [OrderBook Data](#!/OrderBook/OrderBook_getL2) * [Settlement Data](#!/Settlement/Settlement_get) * [Exchange Statistics](#!/Stats/Stats_history) Every function of the BitMEX.com platform is exposed here and documented. Many more functions are available. ##### Swagger Specification [⇩ Download Swagger JSON](swagger.json) ## All API Endpoints Click to expand a section. + * ## REST API for the BitMEX Trading Platform [View Changelog](/app/apiChangelog) #### Getting Started ##### Fetching Data All REST endpoints are documented below. You can try out any query right from this interface. Most table queries accept `count`, `start`, and `reverse` params. Set `reverse=true` to get rows newest-first. Additional documentation regarding filters, timestamps, and authentication is available in [the main API documentation](https://www.bitmex.com/app/restAPI). *All* table data is available via the [Websocket](/app/wsAPI). We highly recommend using the socket if you want to have the quickest possible data without being subject to ratelimits. ##### Return Types By default, all data is returned as JSON. Send `?_format=csv` to get CSV data or `?_format=xml` to get XML data. ##### Trade Data Queries *This is only a small subset of what is available, to get you started.* Fill in the parameters and click the `Try it out!` button to try any of these queries. * [Pricing Data](#!/Quote/Quote_get) * [Trade Data](#!/Trade/Trade_get) * [OrderBook Data](#!/OrderBook/OrderBook_getL2) * [Settlement Data](#!/Settlement/Settlement_get) * [Exchange Statistics](#!/Stats/Stats_history) Every function of the BitMEX.com platform is exposed here and documented. Many more functions are available. ##### Swagger Specification [⇩ Download Swagger JSON](swagger.json) ## All API Endpoints Click to expand a section. * * OpenAPI spec version: 1.2.0 * Contact: support@bitmex.com @@ -25,10 +25,11 @@ type BasicAuth struct { } type APIKey struct { - Key string - Prefix string - Secret string - Host string + Key string + Prefix string + Secret string + Host string + Timeout int64 } type Configuration struct {