From 49a96f96815807c7538002889095588124df0536 Mon Sep 17 00:00:00 2001 From: vitams Date: Tue, 10 Apr 2018 02:18:06 +0500 Subject: [PATCH] Init --- .gitignore | 1 + bitmex/bitmex.go | 21 + bitmex/bitmex_test.go | 13 + config.json | 13 + config/config.go | 40 + config/config_test.go | 25 + main.go | 76 ++ rest/rest.go | 79 ++ swagger/access_token.go | 26 + swagger/affiliate.go | 47 + swagger/announcement.go | 28 + swagger/announcement_api.go | 197 +++ swagger/api_client.go | 483 ++++++++ swagger/api_key.go | 36 + swagger/api_key_api.go | 574 +++++++++ swagger/api_response.go | 44 + swagger/auth_util.go | 53 + swagger/chat.go | 32 + swagger/chat_api.go | 356 ++++++ swagger/chat_channel.go | 17 + swagger/configuration.go | 57 + swagger/connected_users.go | 17 + swagger/error_error.go | 17 + swagger/execution.go | 112 ++ swagger/execution_api.go | 342 ++++++ swagger/funding.go | 28 + swagger/funding_api.go | 148 +++ swagger/index_composite.go | 31 + swagger/inline_response_200.go | 15 + swagger/instrument.go | 210 ++++ swagger/instrument_api.go | 531 ++++++++ swagger/instrument_interval.go | 17 + swagger/insurance.go | 24 + swagger/insurance_api.go | 148 +++ swagger/leaderboard.go | 22 + swagger/leaderboard_api.go | 98 ++ swagger/liquidation.go | 24 + swagger/liquidation_api.go | 148 +++ swagger/margin.go | 99 ++ swagger/model_error.go | 15 + swagger/notification.go | 38 + swagger/notification_api.go | 126 ++ swagger/order.go | 84 ++ swagger/order_api.go | 1241 +++++++++++++++++++ swagger/order_book.go | 32 + swagger/order_book_api.go | 174 +++ swagger/order_book_l2.go | 23 + swagger/position.go | 200 +++ swagger/position_api.go | 572 +++++++++ swagger/quote.go | 30 + swagger/quote_api.go | 283 +++++ swagger/schema_api.go | 161 +++ swagger/settlement.go | 32 + swagger/settlement_api.go | 148 +++ swagger/stats.go | 26 + swagger/stats_api.go | 215 ++++ swagger/stats_history.go | 27 + swagger/stats_usd.go | 25 + swagger/trade.go | 38 + swagger/trade_api.go | 284 +++++ swagger/trade_bin.go | 43 + swagger/transaction.go | 41 + swagger/user.go | 46 + swagger/user_api.go | 2079 ++++++++++++++++++++++++++++++++ swagger/user_commission.go | 21 + swagger/user_preferences.go | 67 + swagger/wallet.go | 67 + swagger/x_any.go | 14 + tools/tools.go | 7 + tools/tools_test.go | 16 + websocket/websocket.go | 67 + websocket/websocket_test.go | 74 ++ 72 files changed, 10565 insertions(+) create mode 100644 .gitignore create mode 100644 bitmex/bitmex.go create mode 100644 bitmex/bitmex_test.go create mode 100644 config.json create mode 100644 config/config.go create mode 100644 config/config_test.go create mode 100644 main.go create mode 100644 rest/rest.go create mode 100644 swagger/access_token.go create mode 100644 swagger/affiliate.go create mode 100644 swagger/announcement.go create mode 100644 swagger/announcement_api.go create mode 100644 swagger/api_client.go create mode 100644 swagger/api_key.go create mode 100644 swagger/api_key_api.go create mode 100644 swagger/api_response.go create mode 100644 swagger/auth_util.go create mode 100644 swagger/chat.go create mode 100644 swagger/chat_api.go create mode 100644 swagger/chat_channel.go create mode 100644 swagger/configuration.go create mode 100644 swagger/connected_users.go create mode 100644 swagger/error_error.go create mode 100644 swagger/execution.go create mode 100644 swagger/execution_api.go create mode 100644 swagger/funding.go create mode 100644 swagger/funding_api.go create mode 100644 swagger/index_composite.go create mode 100644 swagger/inline_response_200.go create mode 100644 swagger/instrument.go create mode 100644 swagger/instrument_api.go create mode 100644 swagger/instrument_interval.go create mode 100644 swagger/insurance.go create mode 100644 swagger/insurance_api.go create mode 100644 swagger/leaderboard.go create mode 100644 swagger/leaderboard_api.go create mode 100644 swagger/liquidation.go create mode 100644 swagger/liquidation_api.go create mode 100644 swagger/margin.go create mode 100644 swagger/model_error.go create mode 100644 swagger/notification.go create mode 100644 swagger/notification_api.go create mode 100644 swagger/order.go create mode 100644 swagger/order_api.go create mode 100644 swagger/order_book.go create mode 100644 swagger/order_book_api.go create mode 100644 swagger/order_book_l2.go create mode 100644 swagger/position.go create mode 100644 swagger/position_api.go create mode 100644 swagger/quote.go create mode 100644 swagger/quote_api.go create mode 100644 swagger/schema_api.go create mode 100644 swagger/settlement.go create mode 100644 swagger/settlement_api.go create mode 100644 swagger/stats.go create mode 100644 swagger/stats_api.go create mode 100644 swagger/stats_history.go create mode 100644 swagger/stats_usd.go create mode 100644 swagger/trade.go create mode 100644 swagger/trade_api.go create mode 100644 swagger/trade_bin.go create mode 100644 swagger/transaction.go create mode 100644 swagger/user.go create mode 100644 swagger/user_api.go create mode 100644 swagger/user_commission.go create mode 100644 swagger/user_preferences.go create mode 100644 swagger/wallet.go create mode 100644 swagger/x_any.go create mode 100644 tools/tools.go create mode 100644 tools/tools_test.go create mode 100644 websocket/websocket.go create mode 100644 websocket/websocket_test.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..757fee3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea \ No newline at end of file diff --git a/bitmex/bitmex.go b/bitmex/bitmex.go new file mode 100644 index 0000000..b0f2a69 --- /dev/null +++ b/bitmex/bitmex.go @@ -0,0 +1,21 @@ +package bitmex + +import ( + "encoding/json" +) + +type Response struct { + Success bool `json:"success,omitempty"` + Subscribe string `json:"subscribe,omitempty"` + Request interface{} `json:"request,omitempty"` + Table string `json:"table,omitempty"` + Action string `json:"action,omitempty"` + Data interface{} `json:"data,omitempty"` +} + +func DecodeMessage(message []byte) (Response, error) { + var res Response + err := json.Unmarshal(message, &res) + + return res, err +} diff --git a/bitmex/bitmex_test.go b/bitmex/bitmex_test.go new file mode 100644 index 0000000..bbc2441 --- /dev/null +++ b/bitmex/bitmex_test.go @@ -0,0 +1,13 @@ +package bitmex + +import ( + "testing" +) + +func TestDecodeMessage(t *testing.T) { + message := []byte(`{"Success":true,"Subscribe":"","Request":"","Table":"order","Action":"partial","Data":""}`) + res, err := DecodeMessage(message) + if err != nil || res.Success != true || res.Table != "order" { + t.Error("Error decode message") + } +} diff --git a/config.json b/config.json new file mode 100644 index 0000000..89fdeea --- /dev/null +++ b/config.json @@ -0,0 +1,13 @@ +{ + "IsDev": false, + "Master": { + "Host": "www.bitmex.com", + "Key": "123", + "Secret": "abc" + }, + "Dev": { + "Host": "testnet.bitmex.com", + "Key": "123", + "Secret": "abc" + } +} \ No newline at end of file diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..f64e6e4 --- /dev/null +++ b/config/config.go @@ -0,0 +1,40 @@ +package config + +import ( + "os" + "encoding/json" + "gitlab.com/vitams/bitmex/tools" +) + +type Config struct { + Host string + Key string + Secret string +} + +type MasterConfig struct { + IsDev bool + Master Config + Dev Config +} + +func LoadConfig(path string) Config { + config := LoadMasterConfig(path) + if config.IsDev { + return config.Dev + } + + return config.Master +} + +func LoadMasterConfig(path string) MasterConfig { + file, err := os.Open(path) + tools.CheckErr(err) + defer file.Close() + decoder := json.NewDecoder(file) + config := MasterConfig{} + err = decoder.Decode(&config) + tools.CheckErr(err) + + return config +} \ No newline at end of file diff --git a/config/config_test.go b/config/config_test.go new file mode 100644 index 0000000..c3175a3 --- /dev/null +++ b/config/config_test.go @@ -0,0 +1,25 @@ +package config + +import ( + "testing" +) + +func TestGetConfig(t *testing.T) { + config := LoadConfig("../config.json") + if config.Host == "" { + t.Error("No config") + } + if config.Key == "" { + t.Error("No config") + } + if config.Secret == "" { + t.Error("No config") + } +} + +func TestGetMasterConfig(t *testing.T) { + config := LoadMasterConfig("../config.json") + if config.Master.Host == "" { + t.Error("No config") + } +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..fd0ed7c --- /dev/null +++ b/main.go @@ -0,0 +1,76 @@ +package main + +import ( + "github.com/vmpartner/bitmex/config" + "github.com/vmpartner/bitmex/rest" + "github.com/vmpartner/bitmex/websocket" + "fmt" + "strings" + "github.com/vmpartner/bitmex/bitmex" + "github.com/vmpartner/bitmex/tools" +) + +// Usage example +func main() { + + // Load config + cfg := config.LoadConfig("config.json") + ctx := rest.MakeContext(cfg.Key, cfg.Secret, cfg.Host) + + // Get wallet + w, response, err := rest.GetWallet(ctx) + tools.CheckErr(err) + fmt.Printf("Status: %v, wallet amount: %v\n", response.StatusCode, w.Amount) + + // Connect to WS + conn := websocket.Connect(cfg.Host) + defer conn.Close() + + // Listen read WS + chReadFromWS := make(chan []byte, 100) + go websocket.ReadFromWSToChannel(conn, chReadFromWS) + + // Listen write WS + chWriteToWS := make(chan interface{}, 100) + go websocket.WriteFromChannelToWS(conn, chWriteToWS) + + // Authorize + chWriteToWS <- websocket.GetAuthMessage(cfg.Key, cfg.Secret) + + // Read first response message + message := <-chReadFromWS + if !strings.Contains(string(message), "Welcome to the BitMEX") { + fmt.Println(string(message)) + panic("No welcome message") + } + + // Read auth response success + message = <-chReadFromWS + res, err := bitmex.DecodeMessage(message) + tools.CheckErr(err) + if res.Success != true || res.Request.(map[string]interface{})["op"] != "authKey" { + panic("No auth response success") + } + + // Listen websocket before subscribe + go func() { + for { + message := <-chReadFromWS + res, err := bitmex.DecodeMessage(message) + tools.CheckErr(err) + + // Your logic here + fmt.Printf("%+v\n", res) + } + }() + + // Subscribe + messageWS := websocket.Message{Op: "subscribe"} + messageWS.AddArgument("orderBookL2:XBTUSD") + messageWS.AddArgument("order") + messageWS.AddArgument("position") + chWriteToWS <- messageWS + + // Loop forever + select {} +} diff --git a/rest/rest.go b/rest/rest.go new file mode 100644 index 0000000..e88958c --- /dev/null +++ b/rest/rest.go @@ -0,0 +1,79 @@ +package rest + +import ( + "context" + "github.com/vmpartner/bitmex/swagger" + "net/http" +) + +func MakeContext(key string, secret string, host string) context.Context { + return context.WithValue(context.TODO(), swagger.ContextAPIKey, swagger.APIKey{ + Key: key, + Secret: secret, + Host: host, + }) +} + +func GetClient(ctx context.Context) *swagger.APIClient { + c := ctx.Value(swagger.ContextAPIKey).(swagger.APIKey) + cfg := &swagger.Configuration{ + BasePath: "https://" + c.Host + "/api/v1", + DefaultHeader: make(map[string]string), + UserAgent: "Swagger-Codegen/1.0.0/go", + ExpireTime: 5, //seconds + } + + return swagger.NewAPIClient(cfg) +} + +func NewOrder(ctx context.Context, params map[string]interface{}) (swagger.Order, *http.Response, error) { + client := GetClient(ctx) + order, response, err := client.OrderApi.OrderNew(ctx, "XBTUSD", params) + + return order, response, err +} + +func AmendOrder(ctx context.Context, params map[string]interface{}) (swagger.Order, *http.Response, error) { + client := GetClient(ctx) + order, response, err := client.OrderApi.OrderAmend(ctx, params) + + return order, response, err +} + +func GetOrder(ctx context.Context, params map[string]interface{}) ([]swagger.Order, *http.Response, error) { + client := GetClient(ctx) + orders, response, err := client.OrderApi.OrderGetOrders(ctx, params) + + return orders, response, err +} + +func GetPosition(ctx context.Context, params map[string]interface{}) ([]swagger.Position, *http.Response, error) { + client := GetClient(ctx) + positions, response, err := client.PositionApi.PositionGet(ctx, params) + + return positions, response, err +} + +func GetTrade(ctx context.Context, params map[string]interface{}) ([]swagger.Trade, *http.Response, error) { + client := GetClient(ctx) + positions, response, err := client.TradeApi.TradeGet(params) + + return positions, response, err +} + +func CancelOrder(ctx context.Context, params map[string]interface{}) ([]swagger.Order, *http.Response, error) { + client := GetClient(ctx) + orders, response, err := client.OrderApi.OrderCancel(ctx, params) + + return orders, response, err +} + +func GetWallet(ctx context.Context) (swagger.Wallet, *http.Response, error) { + params := map[string]interface{}{ + "currency": "", + } + client := GetClient(ctx) + wallet, response, err := client.UserApi.UserGetWallet(ctx, params) + + return wallet, response, err +} \ No newline at end of file diff --git a/swagger/access_token.go b/swagger/access_token.go new file mode 100644 index 0000000..35c4e95 --- /dev/null +++ b/swagger/access_token.go @@ -0,0 +1,26 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type AccessToken struct { + Id string `json:"id"` + + // time to live in seconds (2 weeks by default) + Ttl float64 `json:"ttl,omitempty"` + + Created time.Time `json:"created,omitempty"` + + UserId float64 `json:"userId,omitempty"` +} diff --git a/swagger/affiliate.go b/swagger/affiliate.go new file mode 100644 index 0000000..16c3301 --- /dev/null +++ b/swagger/affiliate.go @@ -0,0 +1,47 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type Affiliate struct { + Account float32 `json:"account"` + + Currency string `json:"currency"` + + PrevPayout float32 `json:"prevPayout,omitempty"` + + PrevTurnover float32 `json:"prevTurnover,omitempty"` + + PrevComm float32 `json:"prevComm,omitempty"` + + PrevTimestamp time.Time `json:"prevTimestamp,omitempty"` + + ExecTurnover float32 `json:"execTurnover,omitempty"` + + ExecComm float32 `json:"execComm,omitempty"` + + TotalReferrals float32 `json:"totalReferrals,omitempty"` + + TotalTurnover float32 `json:"totalTurnover,omitempty"` + + TotalComm float32 `json:"totalComm,omitempty"` + + PayoutPcnt float64 `json:"payoutPcnt,omitempty"` + + PendingPayout float32 `json:"pendingPayout,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` + + ReferrerAccount float64 `json:"referrerAccount,omitempty"` +} diff --git a/swagger/announcement.go b/swagger/announcement.go new file mode 100644 index 0000000..b8db808 --- /dev/null +++ b/swagger/announcement.go @@ -0,0 +1,28 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Public Announcements +type Announcement struct { + Id float32 `json:"id"` + + Link string `json:"link,omitempty"` + + Title string `json:"title,omitempty"` + + Content string `json:"content,omitempty"` + + Date time.Time `json:"date,omitempty"` +} diff --git a/swagger/announcement_api.go b/swagger/announcement_api.go new file mode 100644 index 0000000..f131c21 --- /dev/null +++ b/swagger/announcement_api.go @@ -0,0 +1,197 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type AnnouncementApiService service + +/* AnnouncementApiService Get site announcements. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. + @return []Announcement*/ +func (a *AnnouncementApiService) AnnouncementGet(localVarOptionals map[string]interface{}) ([]Announcement, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Announcement + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/announcement" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* AnnouncementApiService Get urgent (banner) announcements. + * @param ctx context.Context Authentication Context + @return []Announcement*/ +func (a *AnnouncementApiService) AnnouncementGetUrgent(ctx context.Context, ) ([]Announcement, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Announcement + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/announcement/urgent" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/api_client.go b/swagger/api_client.go new file mode 100644 index 0000000..c4b98d0 --- /dev/null +++ b/swagger/api_client.go @@ -0,0 +1,483 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "bytes" + "encoding/json" + "encoding/xml" + "fmt" + "errors" + "io" + "mime/multipart" + "golang.org/x/oauth2" + "golang.org/x/net/context" + "net/http" + "net/url" + "time" + "os" + "path/filepath" + "reflect" + "regexp" + "strings" + "unicode/utf8" + "strconv" +) + +var ( + jsonCheck = regexp.MustCompile("(?i:[application|text]/json)") + xmlCheck = regexp.MustCompile("(?i:[application|text]/xml)") +) + +// APIClient manages communication with the BitMEX API API v1.2.0 +// In most cases there should be only one, shared, APIClient. +type APIClient struct { + cfg *Configuration + common service // Reuse a single struct instead of allocating one for each service on the heap. + + // API Services + APIKeyApi *APIKeyApiService + AnnouncementApi *AnnouncementApiService + ChatApi *ChatApiService + ExecutionApi *ExecutionApiService + FundingApi *FundingApiService + InstrumentApi *InstrumentApiService + InsuranceApi *InsuranceApiService + LeaderboardApi *LeaderboardApiService + LiquidationApi *LiquidationApiService + NotificationApi *NotificationApiService + OrderApi *OrderApiService + OrderBookApi *OrderBookApiService + PositionApi *PositionApiService + QuoteApi *QuoteApiService + SchemaApi *SchemaApiService + SettlementApi *SettlementApiService + StatsApi *StatsApiService + TradeApi *TradeApiService + UserApi *UserApiService +} + +type service struct { + client *APIClient +} + +// NewAPIClient creates a new API client. Requires a userAgent string describing your application. +// optionally a custom http.Client to allow for advanced features such as caching. +func NewAPIClient(cfg *Configuration) *APIClient { + if cfg.HTTPClient == nil { + cfg.HTTPClient = http.DefaultClient + } + + c := &APIClient{} + c.cfg = cfg + c.common.client = c + + // API Services + c.APIKeyApi = (*APIKeyApiService)(&c.common) + c.AnnouncementApi = (*AnnouncementApiService)(&c.common) + c.ChatApi = (*ChatApiService)(&c.common) + c.ExecutionApi = (*ExecutionApiService)(&c.common) + c.FundingApi = (*FundingApiService)(&c.common) + c.InstrumentApi = (*InstrumentApiService)(&c.common) + c.InsuranceApi = (*InsuranceApiService)(&c.common) + c.LeaderboardApi = (*LeaderboardApiService)(&c.common) + c.LiquidationApi = (*LiquidationApiService)(&c.common) + c.NotificationApi = (*NotificationApiService)(&c.common) + c.OrderApi = (*OrderApiService)(&c.common) + c.OrderBookApi = (*OrderBookApiService)(&c.common) + c.PositionApi = (*PositionApiService)(&c.common) + c.QuoteApi = (*QuoteApiService)(&c.common) + c.SchemaApi = (*SchemaApiService)(&c.common) + c.SettlementApi = (*SettlementApiService)(&c.common) + c.StatsApi = (*StatsApiService)(&c.common) + c.TradeApi = (*TradeApiService)(&c.common) + c.UserApi = (*UserApiService)(&c.common) + + return c +} + +func atoi(in string) (int, error) { + return strconv.Atoi(in) +} + +// selectHeaderContentType select a content type from the available list. +func selectHeaderContentType(contentTypes []string) string { + if len(contentTypes) == 0 { + return "" + } + if contains(contentTypes, "application/json") { + return "application/json" + } + return contentTypes[0] // use the first content type specified in 'consumes' +} + +// selectHeaderAccept join all accept types and return +func selectHeaderAccept(accepts []string) string { + if len(accepts) == 0 { + return "" + } + + if contains(accepts, "application/json") { + return "application/json" + } + + return strings.Join(accepts, ",") +} + +// contains is a case insenstive match, finding needle in a haystack +func contains(haystack []string, needle string) bool { + for _, a := range haystack { + if strings.ToLower(a) == strings.ToLower(needle) { + return true + } + } + return false +} + +// Verify optional parameters are of the correct type. +func typeCheckParameter(obj interface{}, expected string, name string) error { + // Make sure there is an object. + if obj == nil { + return nil + } + + // Check the type is as expected. + if reflect.TypeOf(obj).String() != expected { + return fmt.Errorf("Expected %s to be of type %s but received %s.", name, expected, reflect.TypeOf(obj).String()) + } + return nil +} + +// parameterToString convert interface{} parameters to string, using a delimiter if format is provided. +func parameterToString(obj interface{}, collectionFormat string) string { + var delimiter string + + switch collectionFormat { + case "pipes": + delimiter = "|" + case "ssv": + delimiter = " " + case "tsv": + delimiter = "\t" + case "csv": + delimiter = "," + } + + if reflect.TypeOf(obj).Kind() == reflect.Slice { + return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") + } + + return fmt.Sprintf("%v", obj) +} + +// callAPI do the request. +func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) { + return c.cfg.HTTPClient.Do(request) +} + +// Change base path to allow switching to mocks +func (c *APIClient) ChangeBasePath(path string) { + c.cfg.BasePath = path +} + +// prepareRequest build the request +func (c *APIClient) prepareRequest( + ctx context.Context, + path string, method string, + postBody interface{}, + headerParams map[string]string, + queryParams url.Values, + formParams url.Values, + fileName string, + fileBytes []byte) (localVarRequest *http.Request, err error) { + + var body *bytes.Buffer + + if len(formParams) > 0 { + tmpBody := make(map[string]string) + for k, v := range formParams { + tmpBody[k] = v[0] + } + bodyBytes, err := json.Marshal(tmpBody) + if err != nil { + return nil, err + } + postBody = string(bodyBytes) + formParams = url.Values{} + } + + // Detect postBody type and post. + if postBody != nil { + contentType := headerParams["Content-Type"] + if contentType == "" { + contentType = detectContentType(postBody) + headerParams["Content-Type"] = contentType + } + + body, err = setBody(postBody, contentType) + if err != nil { + return nil, err + } + } + + // add form paramters and file if available. + if len(formParams) > 0 || (len(fileBytes) > 0 && fileName != "") { + if body != nil { + return nil, errors.New("Cannot specify postBody and multipart form at the same time.") + } + body = &bytes.Buffer{} + w := multipart.NewWriter(body) + + for k, v := range formParams { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return nil, err + } + } else { // form value + w.WriteField(k, iv) + } + } + } + if len(fileBytes) > 0 && fileName != "" { + w.Boundary() + //_, fileNm := filepath.Split(fileName) + part, err := w.CreateFormFile("file", filepath.Base(fileName)) + if err != nil { + return nil, err + } + _, err = part.Write(fileBytes) + if err != nil { + return nil, err + } + // Set the Boundary in the Content-Type + headerParams["Content-Type"] = w.FormDataContentType() + } + + // Set Content-Length + headerParams["Content-Length"] = fmt.Sprintf("%d", body.Len()) + w.Close() + } + + // Setup path and query paramters + url, err := url.Parse(path) + if err != nil { + return nil, err + } + + // Adding Query Param + query := url.Query() + for k, v := range queryParams { + for _, iv := range v { + query.Add(k, iv) + } + } + + // Encode the parameters. + url.RawQuery = query.Encode() + + // Generate a new request + if body != nil { + localVarRequest, err = http.NewRequest(method, url.String(), body) + } else { + localVarRequest, err = http.NewRequest(method, url.String(), nil) + } + if err != nil { + return nil, err + } + + // add header parameters, if any + if len(headerParams) > 0 { + headers := http.Header{} + for h, v := range headerParams { + headers.Set(h, v) + } + localVarRequest.Header = headers + } + + // Override request host, if applicable + if c.cfg.Host != "" { + localVarRequest.Host = c.cfg.Host + } + + // Add the user agent to the request. + localVarRequest.Header.Add("User-Agent", c.cfg.UserAgent) + + // Walk through any authentication. + if ctx != nil { + // OAuth2 authentication + if tok, ok := ctx.Value(ContextOAuth2).(oauth2.TokenSource); ok { + // We were able to grab an oauth2 token from the context + var latestToken *oauth2.Token + if latestToken, err = tok.Token(); err != nil { + return nil, err + } + + latestToken.SetAuthHeader(localVarRequest) + } + + // Basic HTTP Authentication + if auth, ok := ctx.Value(ContextBasicAuth).(BasicAuth); ok { + localVarRequest.SetBasicAuth(auth.UserName, auth.Password) + } + + // AccessToken Authentication + if auth, ok := ctx.Value(ContextAccessToken).(string); ok { + localVarRequest.Header.Add("Authorization", "Bearer "+auth) + } + + // before setting auth header, remove Api-Nonce, Api-Key, Api-Signature + localVarRequest.Header.Del("Api-Nonce") + localVarRequest.Header.Del("Api-Key") + localVarRequest.Header.Del("Api-Signature") + + // APIKey Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + if postBody != nil { + SetAuthHeader(localVarRequest, auth, c.cfg, method, path, postBody.(string), queryParams) + } else { + SetAuthHeader(localVarRequest, auth, c.cfg, method, path, "", queryParams) + } + } + } + + for header, value := range c.cfg.DefaultHeader { + localVarRequest.Header.Add(header, value) + } + + return localVarRequest, nil +} + +// Add a file to the multipart request +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(path) + if err != nil { + return err + } + defer file.Close() + + part, err := w.CreateFormFile(fieldName, filepath.Base(path)) + if err != nil { + return err + } + _, err = io.Copy(part, file) + + return err +} + +// Prevent trying to import "fmt" +func reportError(format string, a ...interface{}) (error) { + return fmt.Errorf(format, a...) +} + +// Set request body from an interface{} +func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err error) { + if bodyBuf == nil { + bodyBuf = &bytes.Buffer{} + } + + if reader, ok := body.(io.Reader); ok { + _, err = bodyBuf.ReadFrom(reader) + } else if b, ok := body.([]byte); ok { + _, err = bodyBuf.Write(b) + } else if s, ok := body.(string); ok { + _, err = bodyBuf.WriteString(s) + } else if jsonCheck.MatchString(contentType) { + err = json.NewEncoder(bodyBuf).Encode(body) + } else if xmlCheck.MatchString(contentType) { + xml.NewEncoder(bodyBuf).Encode(body) + } + + if err != nil { + return nil, err + } + + if bodyBuf.Len() == 0 { + err = fmt.Errorf("Invalid body type %s\n", contentType) + return nil, err + } + return bodyBuf, nil +} + +// detectContentType method is used to figure out `Request.Body` content type for request header +func detectContentType(body interface{}) string { + contentType := "text/plain; charset=utf-8" + kind := reflect.TypeOf(body).Kind() + + switch kind { + case reflect.Struct, reflect.Map, reflect.Ptr: + contentType = "application/json; charset=utf-8" + case reflect.String: + contentType = "text/plain; charset=utf-8" + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = "application/json; charset=utf-8" + } + } + + return contentType +} + +// Ripped from https://github.com/gregjones/httpcache/blob/master/httpcache.go +type cacheControl map[string]string + +func parseCacheControl(headers http.Header) cacheControl { + cc := cacheControl{} + ccHeader := headers.Get("Cache-Control") + for _, part := range strings.Split(ccHeader, ",") { + part = strings.Trim(part, " ") + if part == "" { + continue + } + if strings.ContainsRune(part, '=') { + keyval := strings.Split(part, "=") + cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",") + } else { + cc[part] = "" + } + } + return cc +} + +// CacheExpires helper function to determine remaining time before repeating a request. +func CacheExpires(r *http.Response) (time.Time) { + // Figure out when the cache expires. + var expires time.Time + now, err := time.Parse(time.RFC1123, r.Header.Get("date")) + if err != nil { + return time.Now() + } + respCacheControl := parseCacheControl(r.Header) + + if maxAge, ok := respCacheControl["max-age"]; ok { + lifetime, err := time.ParseDuration(maxAge + "s") + if err != nil { + expires = now + } + expires = now.Add(lifetime) + } else { + expiresHeader := r.Header.Get("Expires") + if expiresHeader != "" { + expires, err = time.Parse(time.RFC1123, expiresHeader) + if err != nil { + expires = now + } + } + } + return expires +} + +func strlen(s string) (int) { + return utf8.RuneCountInString(s) +} diff --git a/swagger/api_key.go b/swagger/api_key.go new file mode 100644 index 0000000..ddbc89d --- /dev/null +++ b/swagger/api_key.go @@ -0,0 +1,36 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Persistent API Keys for Developers +type ApiKey struct { + Id string `json:"id"` + + Secret string `json:"secret"` + + Name string `json:"name"` + + Nonce float32 `json:"nonce"` + + Cidr string `json:"cidr,omitempty"` + + Permissions []XAny `json:"permissions,omitempty"` + + Enabled bool `json:"enabled,omitempty"` + + UserId float32 `json:"userId"` + + Created time.Time `json:"created,omitempty"` +} diff --git a/swagger/api_key_api.go b/swagger/api_key_api.go new file mode 100644 index 0000000..4a1171f --- /dev/null +++ b/swagger/api_key_api.go @@ -0,0 +1,574 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type APIKeyApiService service + +/* APIKeyApiService Disable an API Key. + * @param ctx context.Context Authentication Context + @param apiKeyID API Key ID (public component). + @return ApiKey*/ +func (a *APIKeyApiService) APIKeyDisable(ctx context.Context, apiKeyID string) (ApiKey, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload ApiKey + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/apiKey/disable" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("apiKeyID", parameterToString(apiKeyID, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* APIKeyApiService Enable an API Key. + * @param ctx context.Context Authentication Context + @param apiKeyID API Key ID (public component). + @return ApiKey*/ +func (a *APIKeyApiService) APIKeyEnable(ctx context.Context, apiKeyID string) (ApiKey, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload ApiKey + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/apiKey/enable" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("apiKeyID", parameterToString(apiKeyID, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* APIKeyApiService Get your API Keys. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "reverse" (bool) If true, will sort results newest first. + @return []ApiKey*/ +func (a *APIKeyApiService) APIKeyGet(ctx context.Context, localVarOptionals map[string]interface{}) ([]ApiKey, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []ApiKey + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/apiKey" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* APIKeyApiService Create a new API Key. + API Keys can also be created via [this Python script](https://github.com/BitMEX/market-maker/blob/master/generate-api-key.py) See the [API Key Documentation](/app/apiKeys) for more information on capabilities. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "name" (string) Key name. This name is for reference only. + @param "cidr" (string) CIDR block to restrict this key to. To restrict to a single address, append \"/32\", e.g. 207.39.29.22/32. Leave blank or set to 0.0.0.0/0 to allow all IPs. Only one block may be set. <a href=\"http://software77.net/cidr-101.html\">More on CIDR blocks</a> + @param "permissions" (string) Key Permissions. All keys can read margin and position data. Additional permissions must be added. Available: [\"order\", \"orderCancel\", \"withdraw\"]. + @param "enabled" (bool) Set to true to enable this key on creation. Otherwise, it must be explicitly enabled via /apiKey/enable. + @param "token" (string) OTP Token (YubiKey, Google Authenticator) + @return ApiKey*/ +func (a *APIKeyApiService) APIKeyNew(ctx context.Context, localVarOptionals map[string]interface{}) (ApiKey, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload ApiKey + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/apiKey" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["name"], "string", "name"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["cidr"], "string", "cidr"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["permissions"], "string", "permissions"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["enabled"], "bool", "enabled"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["token"], "string", "token"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["name"].(string); localVarOk { + localVarFormParams.Add("name", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["cidr"].(string); localVarOk { + localVarFormParams.Add("cidr", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["permissions"].(string); localVarOk { + localVarFormParams.Add("permissions", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["enabled"].(bool); localVarOk { + localVarFormParams.Add("enabled", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["token"].(string); localVarOk { + localVarFormParams.Add("token", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* APIKeyApiService Remove an API Key. + * @param ctx context.Context Authentication Context + @param apiKeyID API Key ID (public component). + @return InlineResponse200*/ +func (a *APIKeyApiService) APIKeyRemove(ctx context.Context, apiKeyID string) (InlineResponse200, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Delete") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload InlineResponse200 + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/apiKey" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("apiKeyID", parameterToString(apiKeyID, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/api_response.go b/swagger/api_response.go new file mode 100644 index 0000000..130061d --- /dev/null +++ b/swagger/api_response.go @@ -0,0 +1,44 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/http" +) + +type APIResponse struct { + *http.Response `json:"-"` + Message string `json:"message,omitempty"` + // Operation is the name of the swagger operation. + Operation string `json:"operation,omitempty"` + // RequestURL is the request URL. This value is always available, even if the + // embedded *http.Response is nil. + RequestURL string `json:"url,omitempty"` + // Method is the HTTP method used for the request. This value is always + // available, even if the embedded *http.Response is nil. + Method string `json:"method,omitempty"` + // Payload holds the contents of the response body (which may be nil or empty). + // This is provided here as the raw response.Body() reader will have already + // been drained. + Payload []byte `json:"-"` +} + +func NewAPIResponse(r *http.Response) *APIResponse { + + response := &APIResponse{Response: r} + return response +} + +func NewAPIResponseWithError(errorMessage string) *APIResponse { + + response := &APIResponse{Message: errorMessage} + return response +} diff --git a/swagger/auth_util.go b/swagger/auth_util.go new file mode 100644 index 0000000..2940fda --- /dev/null +++ b/swagger/auth_util.go @@ -0,0 +1,53 @@ +package swagger + +import ( + "crypto/hmac" + "crypto/sha256" + "encoding/hex" + "fmt" + "net/http" + "net/http/httputil" + "net/url" + "strconv" + "strings" + "time" + "regexp" +) + +func SetAuthHeader(request *http.Request, apiKey APIKey, c *Configuration, httpMethod, path, postBody string, + queryParams url.Values) { + var expires = strconv.FormatInt(time.Now().Unix()+c.ExpireTime, 10) + request.Header.Add("api-key", apiKey.Key) + request.Header.Add("api-expires", expires) + p := regexp.MustCompile("/api.*").FindString(path) + request.Header.Add("api-signature", Signature(apiKey.Secret, httpMethod, p, queryParams.Encode(), + expires, postBody)) +} + +/** + * nonce: nonce or expires + */ +func Signature(apiSecret, method, path, query, nonce, bodyStr string) string { + str := "" + if "" == query { + str = strings.ToUpper(method) + path + nonce + bodyStr + } else { + str = strings.ToUpper(method) + path + "?" + query + nonce + bodyStr + } + return CalSignature(apiSecret, str) +} + +func CalSignature(apiSecret, payload string) string { + sig := hmac.New(sha256.New, []byte(apiSecret)) + sig.Write([]byte(payload)) + return hex.EncodeToString(sig.Sum(nil)) +} + +// Save a copy of this request for debugging. +func DebugHttpRequest(r *http.Request) { + requestDump, err := httputil.DumpRequest(r, true) + if err != nil { + fmt.Println(err) + } + fmt.Println(string(requestDump)) +} diff --git a/swagger/chat.go b/swagger/chat.go new file mode 100644 index 0000000..7744a7c --- /dev/null +++ b/swagger/chat.go @@ -0,0 +1,32 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Trollbox Data +type Chat struct { + Id float32 `json:"id,omitempty"` + + Date time.Time `json:"date"` + + User string `json:"user"` + + Message string `json:"message"` + + Html string `json:"html"` + + FromBot bool `json:"fromBot,omitempty"` + + ChannelID float64 `json:"channelID,omitempty"` +} diff --git a/swagger/chat_api.go b/swagger/chat_api.go new file mode 100644 index 0000000..63b3434 --- /dev/null +++ b/swagger/chat_api.go @@ -0,0 +1,356 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type ChatApiService service + +/* ChatApiService Get chat messages. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting ID for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "channelID" (float64) Channel id. GET /chat/channels for ids. Leave blank for all. + @return []Chat*/ +func (a *ChatApiService) ChatGet(localVarOptionals map[string]interface{}) ([]Chat, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Chat + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/chat" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["channelID"], "float64", "channelID"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["channelID"].(float64); localVarOk { + localVarQueryParams.Add("channelID", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* ChatApiService Get available channels. + + @return []ChatChannel*/ +func (a *ChatApiService) ChatGetChannels() ([]ChatChannel, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []ChatChannel + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/chat/channels" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* ChatApiService Get connected users. + Returns an array with browser users in the first position and API users (bots) in the second position. + + @return ConnectedUsers*/ +func (a *ChatApiService) ChatGetConnected() (ConnectedUsers, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload ConnectedUsers + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/chat/connected" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* ChatApiService Send a chat message. + * @param ctx context.Context Authentication Context + @param message + @param optional (nil or map[string]interface{}) with one or more of: + @param "channelID" (float64) Channel to post to. Default 1 (English). + @return Chat*/ +func (a *ChatApiService) ChatNew(ctx context.Context, message string, localVarOptionals map[string]interface{}) (Chat, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Chat + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/chat" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["channelID"], "float64", "channelID"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("message", parameterToString(message, "")) + if localVarTempParam, localVarOk := localVarOptionals["channelID"].(float64); localVarOk { + localVarFormParams.Add("channelID", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/chat_channel.go b/swagger/chat_channel.go new file mode 100644 index 0000000..5daecbf --- /dev/null +++ b/swagger/chat_channel.go @@ -0,0 +1,17 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type ChatChannel struct { + Id float32 `json:"id,omitempty"` + + Name string `json:"name"` +} diff --git a/swagger/configuration.go b/swagger/configuration.go new file mode 100644 index 0000000..2dfbb57 --- /dev/null +++ b/swagger/configuration.go @@ -0,0 +1,57 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/http" +) + +const ContextOAuth2 int = 1 +const ContextBasicAuth int = 2 +const ContextAccessToken int = 3 +const ContextAPIKey int = 4 + +type BasicAuth struct { + UserName string `json:"userName,omitempty"` + Password string `json:"password,omitempty"` +} + +type APIKey struct { + Key string + Prefix string + Secret string + Host string +} + +type Configuration struct { + BasePath string `json:"basePath,omitempty"` + Host string `json:"host,omitempty"` + Scheme string `json:"scheme,omitempty"` + DefaultHeader map[string]string `json:"defaultHeader,omitempty"` + UserAgent string `json:"userAgent,omitempty"` + HTTPClient *http.Client + + ExpireTime int64 +} + +func NewConfiguration() *Configuration { + cfg := &Configuration{ + BasePath: "https://www.bitmex.com/api/v1", + DefaultHeader: make(map[string]string), + UserAgent: "Swagger-Codegen/1.0.0/go", + ExpireTime: 5, //seconds + } + return cfg +} + +func (c *Configuration) AddDefaultHeader(key string, value string) { + c.DefaultHeader[key] = value +} diff --git a/swagger/connected_users.go b/swagger/connected_users.go new file mode 100644 index 0000000..454d8d3 --- /dev/null +++ b/swagger/connected_users.go @@ -0,0 +1,17 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type ConnectedUsers struct { + Users float32 `json:"users,omitempty"` + + Bots float32 `json:"bots,omitempty"` +} diff --git a/swagger/error_error.go b/swagger/error_error.go new file mode 100644 index 0000000..65bb636 --- /dev/null +++ b/swagger/error_error.go @@ -0,0 +1,17 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type ErrorError struct { + Message string `json:"message,omitempty"` + + Name string `json:"name,omitempty"` +} diff --git a/swagger/execution.go b/swagger/execution.go new file mode 100644 index 0000000..52c0843 --- /dev/null +++ b/swagger/execution.go @@ -0,0 +1,112 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Raw Order and Balance Data +type Execution struct { + ExecID string `json:"execID"` + + OrderID string `json:"orderID,omitempty"` + + ClOrdID string `json:"clOrdID,omitempty"` + + ClOrdLinkID string `json:"clOrdLinkID,omitempty"` + + Account float32 `json:"account,omitempty"` + + Symbol string `json:"symbol,omitempty"` + + Side string `json:"side,omitempty"` + + LastQty float32 `json:"lastQty,omitempty"` + + LastPx float64 `json:"lastPx,omitempty"` + + UnderlyingLastPx float64 `json:"underlyingLastPx,omitempty"` + + LastMkt string `json:"lastMkt,omitempty"` + + LastLiquidityInd string `json:"lastLiquidityInd,omitempty"` + + SimpleOrderQty float64 `json:"simpleOrderQty,omitempty"` + + OrderQty float32 `json:"orderQty,omitempty"` + + Price float64 `json:"price,omitempty"` + + DisplayQty float32 `json:"displayQty,omitempty"` + + StopPx float64 `json:"stopPx,omitempty"` + + PegOffsetValue float64 `json:"pegOffsetValue,omitempty"` + + PegPriceType string `json:"pegPriceType,omitempty"` + + Currency string `json:"currency,omitempty"` + + SettlCurrency string `json:"settlCurrency,omitempty"` + + ExecType string `json:"execType,omitempty"` + + OrdType string `json:"ordType,omitempty"` + + TimeInForce string `json:"timeInForce,omitempty"` + + ExecInst string `json:"execInst,omitempty"` + + ContingencyType string `json:"contingencyType,omitempty"` + + ExDestination string `json:"exDestination,omitempty"` + + OrdStatus string `json:"ordStatus,omitempty"` + + Triggered string `json:"triggered,omitempty"` + + WorkingIndicator bool `json:"workingIndicator,omitempty"` + + OrdRejReason string `json:"ordRejReason,omitempty"` + + SimpleLeavesQty float64 `json:"simpleLeavesQty,omitempty"` + + LeavesQty float32 `json:"leavesQty,omitempty"` + + SimpleCumQty float64 `json:"simpleCumQty,omitempty"` + + CumQty float32 `json:"cumQty,omitempty"` + + AvgPx float64 `json:"avgPx,omitempty"` + + Commission float64 `json:"commission,omitempty"` + + TradePublishIndicator string `json:"tradePublishIndicator,omitempty"` + + MultiLegReportingType string `json:"multiLegReportingType,omitempty"` + + Text string `json:"text,omitempty"` + + TrdMatchID string `json:"trdMatchID,omitempty"` + + ExecCost float32 `json:"execCost,omitempty"` + + ExecComm float32 `json:"execComm,omitempty"` + + HomeNotional float64 `json:"homeNotional,omitempty"` + + ForeignNotional float64 `json:"foreignNotional,omitempty"` + + TransactTime time.Time `json:"transactTime,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` +} diff --git a/swagger/execution_api.go b/swagger/execution_api.go new file mode 100644 index 0000000..6886dee --- /dev/null +++ b/swagger/execution_api.go @@ -0,0 +1,342 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type ExecutionApiService service + +/* ExecutionApiService Get all raw executions for your account. + This returns all raw transactions, which includes order opening and cancelation, and order status changes. It can be quite noisy. More focused information is available at `/execution/tradeHistory`. You may also use the `filter` param to target your query. Specify an array as a filter value, such as `{\"execType\": [\"Settlement\", \"Trade\"]}` to filter on multiple values. See [the FIX Spec](http://www.onixs.biz/fix-dictionary/5.0.SP2/msgType_8_8.html) for explanations of these fields. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Execution*/ +func (a *ExecutionApiService) ExecutionGet(ctx context.Context, localVarOptionals map[string]interface{}) ([]Execution, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Execution + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/execution" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* ExecutionApiService Get all balance-affecting executions. This includes each trade, insurance charge, and settlement. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Execution*/ +func (a *ExecutionApiService) ExecutionGetTradeHistory(ctx context.Context, localVarOptionals map[string]interface{}) ([]Execution, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Execution + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/execution/tradeHistory" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/funding.go b/swagger/funding.go new file mode 100644 index 0000000..35be1ab --- /dev/null +++ b/swagger/funding.go @@ -0,0 +1,28 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Swap Funding History +type Funding struct { + Timestamp time.Time `json:"timestamp"` + + Symbol string `json:"symbol"` + + FundingInterval time.Time `json:"fundingInterval,omitempty"` + + FundingRate float64 `json:"fundingRate,omitempty"` + + FundingRateDaily float64 `json:"fundingRateDaily,omitempty"` +} diff --git a/swagger/funding_api.go b/swagger/funding_api.go new file mode 100644 index 0000000..eadcd1c --- /dev/null +++ b/swagger/funding_api.go @@ -0,0 +1,148 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type FundingApiService service + +/* FundingApiService Get funding history. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Funding*/ +func (a *FundingApiService) FundingGet(localVarOptionals map[string]interface{}) ([]Funding, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Funding + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/funding" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/index_composite.go b/swagger/index_composite.go new file mode 100644 index 0000000..92e3043 --- /dev/null +++ b/swagger/index_composite.go @@ -0,0 +1,31 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type IndexComposite struct { + Timestamp time.Time `json:"timestamp"` + + Symbol string `json:"symbol,omitempty"` + + IndexSymbol string `json:"indexSymbol,omitempty"` + + Reference string `json:"reference,omitempty"` + + LastPrice float64 `json:"lastPrice,omitempty"` + + Weight float64 `json:"weight,omitempty"` + + Logged time.Time `json:"logged,omitempty"` +} diff --git a/swagger/inline_response_200.go b/swagger/inline_response_200.go new file mode 100644 index 0000000..a36e854 --- /dev/null +++ b/swagger/inline_response_200.go @@ -0,0 +1,15 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type InlineResponse200 struct { + Success bool `json:"success,omitempty"` +} diff --git a/swagger/instrument.go b/swagger/instrument.go new file mode 100644 index 0000000..62c4da1 --- /dev/null +++ b/swagger/instrument.go @@ -0,0 +1,210 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Tradeable Contracts, Indices, and History +type Instrument struct { + Symbol string `json:"symbol"` + + RootSymbol string `json:"rootSymbol,omitempty"` + + State string `json:"state,omitempty"` + + Typ string `json:"typ,omitempty"` + + Listing time.Time `json:"listing,omitempty"` + + Front time.Time `json:"front,omitempty"` + + Expiry time.Time `json:"expiry,omitempty"` + + Settle time.Time `json:"settle,omitempty"` + + RelistInterval time.Time `json:"relistInterval,omitempty"` + + InverseLeg string `json:"inverseLeg,omitempty"` + + SellLeg string `json:"sellLeg,omitempty"` + + BuyLeg string `json:"buyLeg,omitempty"` + + PositionCurrency string `json:"positionCurrency,omitempty"` + + Underlying string `json:"underlying,omitempty"` + + QuoteCurrency string `json:"quoteCurrency,omitempty"` + + UnderlyingSymbol string `json:"underlyingSymbol,omitempty"` + + Reference string `json:"reference,omitempty"` + + ReferenceSymbol string `json:"referenceSymbol,omitempty"` + + CalcInterval time.Time `json:"calcInterval,omitempty"` + + PublishInterval time.Time `json:"publishInterval,omitempty"` + + PublishTime time.Time `json:"publishTime,omitempty"` + + MaxOrderQty float32 `json:"maxOrderQty,omitempty"` + + MaxPrice float64 `json:"maxPrice,omitempty"` + + LotSize float32 `json:"lotSize,omitempty"` + + TickSize float64 `json:"tickSize,omitempty"` + + Multiplier float32 `json:"multiplier,omitempty"` + + SettlCurrency string `json:"settlCurrency,omitempty"` + + UnderlyingToPositionMultiplier float32 `json:"underlyingToPositionMultiplier,omitempty"` + + UnderlyingToSettleMultiplier float32 `json:"underlyingToSettleMultiplier,omitempty"` + + QuoteToSettleMultiplier float32 `json:"quoteToSettleMultiplier,omitempty"` + + IsQuanto bool `json:"isQuanto,omitempty"` + + IsInverse bool `json:"isInverse,omitempty"` + + InitMargin float64 `json:"initMargin,omitempty"` + + MaintMargin float64 `json:"maintMargin,omitempty"` + + RiskLimit float32 `json:"riskLimit,omitempty"` + + RiskStep float32 `json:"riskStep,omitempty"` + + Limit float64 `json:"limit,omitempty"` + + Capped bool `json:"capped,omitempty"` + + Taxed bool `json:"taxed,omitempty"` + + Deleverage bool `json:"deleverage,omitempty"` + + MakerFee float64 `json:"makerFee,omitempty"` + + TakerFee float64 `json:"takerFee,omitempty"` + + SettlementFee float64 `json:"settlementFee,omitempty"` + + InsuranceFee float64 `json:"insuranceFee,omitempty"` + + FundingBaseSymbol string `json:"fundingBaseSymbol,omitempty"` + + FundingQuoteSymbol string `json:"fundingQuoteSymbol,omitempty"` + + FundingPremiumSymbol string `json:"fundingPremiumSymbol,omitempty"` + + FundingTimestamp time.Time `json:"fundingTimestamp,omitempty"` + + FundingInterval time.Time `json:"fundingInterval,omitempty"` + + FundingRate float64 `json:"fundingRate,omitempty"` + + IndicativeFundingRate float64 `json:"indicativeFundingRate,omitempty"` + + RebalanceTimestamp time.Time `json:"rebalanceTimestamp,omitempty"` + + RebalanceInterval time.Time `json:"rebalanceInterval,omitempty"` + + OpeningTimestamp time.Time `json:"openingTimestamp,omitempty"` + + ClosingTimestamp time.Time `json:"closingTimestamp,omitempty"` + + SessionInterval time.Time `json:"sessionInterval,omitempty"` + + PrevClosePrice float64 `json:"prevClosePrice,omitempty"` + + LimitDownPrice float64 `json:"limitDownPrice,omitempty"` + + LimitUpPrice float64 `json:"limitUpPrice,omitempty"` + + BankruptLimitDownPrice float64 `json:"bankruptLimitDownPrice,omitempty"` + + BankruptLimitUpPrice float64 `json:"bankruptLimitUpPrice,omitempty"` + + PrevTotalVolume float32 `json:"prevTotalVolume,omitempty"` + + TotalVolume float32 `json:"totalVolume,omitempty"` + + Volume float32 `json:"volume,omitempty"` + + Volume24h float32 `json:"volume24h,omitempty"` + + PrevTotalTurnover float32 `json:"prevTotalTurnover,omitempty"` + + TotalTurnover float32 `json:"totalTurnover,omitempty"` + + Turnover float32 `json:"turnover,omitempty"` + + Turnover24h float32 `json:"turnover24h,omitempty"` + + PrevPrice24h float64 `json:"prevPrice24h,omitempty"` + + Vwap float64 `json:"vwap,omitempty"` + + HighPrice float64 `json:"highPrice,omitempty"` + + LowPrice float64 `json:"lowPrice,omitempty"` + + LastPrice float64 `json:"lastPrice,omitempty"` + + LastPriceProtected float64 `json:"lastPriceProtected,omitempty"` + + LastTickDirection string `json:"lastTickDirection,omitempty"` + + LastChangePcnt float64 `json:"lastChangePcnt,omitempty"` + + BidPrice float64 `json:"bidPrice,omitempty"` + + MidPrice float64 `json:"midPrice,omitempty"` + + AskPrice float64 `json:"askPrice,omitempty"` + + ImpactBidPrice float64 `json:"impactBidPrice,omitempty"` + + ImpactMidPrice float64 `json:"impactMidPrice,omitempty"` + + ImpactAskPrice float64 `json:"impactAskPrice,omitempty"` + + HasLiquidity bool `json:"hasLiquidity,omitempty"` + + OpenInterest float32 `json:"openInterest,omitempty"` + + OpenValue float32 `json:"openValue,omitempty"` + + FairMethod string `json:"fairMethod,omitempty"` + + FairBasisRate float64 `json:"fairBasisRate,omitempty"` + + FairBasis float64 `json:"fairBasis,omitempty"` + + FairPrice float64 `json:"fairPrice,omitempty"` + + MarkMethod string `json:"markMethod,omitempty"` + + MarkPrice float64 `json:"markPrice,omitempty"` + + IndicativeTaxRate float64 `json:"indicativeTaxRate,omitempty"` + + IndicativeSettlePrice float64 `json:"indicativeSettlePrice,omitempty"` + + SettledPrice float64 `json:"settledPrice,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` +} diff --git a/swagger/instrument_api.go b/swagger/instrument_api.go new file mode 100644 index 0000000..ac138fe --- /dev/null +++ b/swagger/instrument_api.go @@ -0,0 +1,531 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type InstrumentApiService service + +/* InstrumentApiService Get instruments. + This returns all instruments and indices, including those that have settled or are unlisted. Use this endpoint if you want to query for individual instruments or use a complex filter. Use `/instrument/active` to return active instruments, or use a filter like `{\"state\": \"Open\"}`. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Instrument*/ +func (a *InstrumentApiService) InstrumentGet(localVarOptionals map[string]interface{}) ([]Instrument, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Instrument + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/instrument" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* InstrumentApiService Get all active instruments and instruments that have expired in <24hrs. + + @return []Instrument*/ +func (a *InstrumentApiService) InstrumentGetActive() ([]Instrument, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Instrument + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/instrument/active" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* InstrumentApiService Helper method. Gets all active instruments and all indices. This is a join of the result of /indices and /active. + + @return []Instrument*/ +func (a *InstrumentApiService) InstrumentGetActiveAndIndices() ([]Instrument, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Instrument + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/instrument/activeAndIndices" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* InstrumentApiService Return all active contract series and interval pairs. + This endpoint is useful for determining which pairs are live. It returns two arrays of strings. The first is intervals, such as `[\"BVOL:daily\", \"BVOL:weekly\", \"XBU:daily\", \"XBU:monthly\", ...]`. These identifiers are usable in any query's `symbol` param. The second array is the current resolution of these intervals. Results are mapped at the same index. + + @return InstrumentInterval*/ +func (a *InstrumentApiService) InstrumentGetActiveIntervals() (InstrumentInterval, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload InstrumentInterval + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/instrument/activeIntervals" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* InstrumentApiService Show constituent parts of an index. + Composite indices are built from multiple external price sources. Use this endpoint to get the underlying prices of an index. For example, send a `symbol` of `.XBT` to get the ticks and weights of the constituent exchanges that build the \".XBT\" index. A tick with reference `\"BMI\"` and weight `null` is the composite index tick. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "account" (float64) + @param "symbol" (string) The composite index symbol. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []IndexComposite*/ +func (a *InstrumentApiService) InstrumentGetCompositeIndex(localVarOptionals map[string]interface{}) ([]IndexComposite, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []IndexComposite + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/instrument/compositeIndex" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["account"], "float64", "account"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["account"].(float64); localVarOk { + localVarQueryParams.Add("account", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* InstrumentApiService Get all price indices. + + @return []Instrument*/ +func (a *InstrumentApiService) InstrumentGetIndices() ([]Instrument, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Instrument + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/instrument/indices" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/instrument_interval.go b/swagger/instrument_interval.go new file mode 100644 index 0000000..4d62466 --- /dev/null +++ b/swagger/instrument_interval.go @@ -0,0 +1,17 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type InstrumentInterval struct { + Intervals []string `json:"intervals"` + + Symbols []string `json:"symbols"` +} diff --git a/swagger/insurance.go b/swagger/insurance.go new file mode 100644 index 0000000..0eb763d --- /dev/null +++ b/swagger/insurance.go @@ -0,0 +1,24 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Insurance Fund Data +type Insurance struct { + Currency string `json:"currency"` + + Timestamp time.Time `json:"timestamp"` + + WalletBalance float32 `json:"walletBalance,omitempty"` +} diff --git a/swagger/insurance_api.go b/swagger/insurance_api.go new file mode 100644 index 0000000..e57abc8 --- /dev/null +++ b/swagger/insurance_api.go @@ -0,0 +1,148 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type InsuranceApiService service + +/* InsuranceApiService Get insurance fund history. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Insurance*/ +func (a *InsuranceApiService) InsuranceGet(localVarOptionals map[string]interface{}) ([]Insurance, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Insurance + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/insurance" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/leaderboard.go b/swagger/leaderboard.go new file mode 100644 index 0000000..a9b6f5c --- /dev/null +++ b/swagger/leaderboard.go @@ -0,0 +1,22 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +// Information on Top Users +type Leaderboard struct { + Name string `json:"name"` + + IsRealName bool `json:"isRealName,omitempty"` + + IsMe bool `json:"isMe,omitempty"` + + Profit float64 `json:"profit,omitempty"` +} diff --git a/swagger/leaderboard_api.go b/swagger/leaderboard_api.go new file mode 100644 index 0000000..694b0d3 --- /dev/null +++ b/swagger/leaderboard_api.go @@ -0,0 +1,98 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type LeaderboardApiService service + +/* LeaderboardApiService Get current leaderboard. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "method" (string) Ranking type. Options: \"notional\", \"ROE\" + @return []Leaderboard*/ +func (a *LeaderboardApiService) LeaderboardGet(localVarOptionals map[string]interface{}) ([]Leaderboard, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Leaderboard + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/leaderboard" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["method"], "string", "method"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["method"].(string); localVarOk { + localVarQueryParams.Add("method", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/liquidation.go b/swagger/liquidation.go new file mode 100644 index 0000000..70ec45f --- /dev/null +++ b/swagger/liquidation.go @@ -0,0 +1,24 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +// Active Liquidations +type Liquidation struct { + OrderID string `json:"orderID"` + + Symbol string `json:"symbol,omitempty"` + + Side string `json:"side,omitempty"` + + Price float64 `json:"price,omitempty"` + + LeavesQty float32 `json:"leavesQty,omitempty"` +} diff --git a/swagger/liquidation_api.go b/swagger/liquidation_api.go new file mode 100644 index 0000000..f45d13b --- /dev/null +++ b/swagger/liquidation_api.go @@ -0,0 +1,148 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type LiquidationApiService service + +/* LiquidationApiService Get liquidation orders. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Liquidation*/ +func (a *LiquidationApiService) LiquidationGet(localVarOptionals map[string]interface{}) ([]Liquidation, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Liquidation + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/liquidation" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/margin.go b/swagger/margin.go new file mode 100644 index 0000000..2ac322f --- /dev/null +++ b/swagger/margin.go @@ -0,0 +1,99 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type Margin struct { + Account float32 `json:"account"` + + Currency string `json:"currency"` + + RiskLimit float32 `json:"riskLimit,omitempty"` + + PrevState string `json:"prevState,omitempty"` + + State string `json:"state,omitempty"` + + Action string `json:"action,omitempty"` + + Amount float32 `json:"amount,omitempty"` + + PendingCredit float32 `json:"pendingCredit,omitempty"` + + PendingDebit float32 `json:"pendingDebit,omitempty"` + + ConfirmedDebit float32 `json:"confirmedDebit,omitempty"` + + PrevRealisedPnl float32 `json:"prevRealisedPnl,omitempty"` + + PrevUnrealisedPnl float32 `json:"prevUnrealisedPnl,omitempty"` + + GrossComm float32 `json:"grossComm,omitempty"` + + GrossOpenCost float32 `json:"grossOpenCost,omitempty"` + + GrossOpenPremium float32 `json:"grossOpenPremium,omitempty"` + + GrossExecCost float32 `json:"grossExecCost,omitempty"` + + GrossMarkValue float32 `json:"grossMarkValue,omitempty"` + + RiskValue float32 `json:"riskValue,omitempty"` + + TaxableMargin float32 `json:"taxableMargin,omitempty"` + + InitMargin float32 `json:"initMargin,omitempty"` + + MaintMargin float32 `json:"maintMargin,omitempty"` + + SessionMargin float32 `json:"sessionMargin,omitempty"` + + TargetExcessMargin float32 `json:"targetExcessMargin,omitempty"` + + VarMargin float32 `json:"varMargin,omitempty"` + + RealisedPnl float32 `json:"realisedPnl,omitempty"` + + UnrealisedPnl float32 `json:"unrealisedPnl,omitempty"` + + IndicativeTax float32 `json:"indicativeTax,omitempty"` + + UnrealisedProfit float32 `json:"unrealisedProfit,omitempty"` + + SyntheticMargin float32 `json:"syntheticMargin,omitempty"` + + WalletBalance float32 `json:"walletBalance,omitempty"` + + MarginBalance float32 `json:"marginBalance,omitempty"` + + MarginBalancePcnt float64 `json:"marginBalancePcnt,omitempty"` + + MarginLeverage float64 `json:"marginLeverage,omitempty"` + + MarginUsedPcnt float64 `json:"marginUsedPcnt,omitempty"` + + ExcessMargin float32 `json:"excessMargin,omitempty"` + + ExcessMarginPcnt float64 `json:"excessMarginPcnt,omitempty"` + + AvailableMargin float32 `json:"availableMargin,omitempty"` + + WithdrawableMargin float32 `json:"withdrawableMargin,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` + + GrossLastValue float32 `json:"grossLastValue,omitempty"` + + Commission float64 `json:"commission,omitempty"` +} diff --git a/swagger/model_error.go b/swagger/model_error.go new file mode 100644 index 0000000..64161ae --- /dev/null +++ b/swagger/model_error.go @@ -0,0 +1,15 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type ModelError struct { + Error_ *ErrorError `json:"error,omitempty"` +} diff --git a/swagger/notification.go b/swagger/notification.go new file mode 100644 index 0000000..58ee935 --- /dev/null +++ b/swagger/notification.go @@ -0,0 +1,38 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Account Notifications +type Notification struct { + Id float32 `json:"id,omitempty"` + + Date time.Time `json:"date"` + + Title string `json:"title"` + + Body string `json:"body"` + + Ttl float32 `json:"ttl"` + + Type_ string `json:"type,omitempty"` + + Closable bool `json:"closable,omitempty"` + + Persist bool `json:"persist,omitempty"` + + WaitForVisibility bool `json:"waitForVisibility,omitempty"` + + Sound string `json:"sound,omitempty"` +} diff --git a/swagger/notification_api.go b/swagger/notification_api.go new file mode 100644 index 0000000..80e0b29 --- /dev/null +++ b/swagger/notification_api.go @@ -0,0 +1,126 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type NotificationApiService service + +/* NotificationApiService Get your current notifications. + This is an upcoming feature and currently does not return data. + * @param ctx context.Context Authentication Context + @return []Notification*/ +func (a *NotificationApiService) NotificationGet(ctx context.Context, ) ([]Notification, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Notification + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/notification" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/order.go b/swagger/order.go new file mode 100644 index 0000000..6401eaf --- /dev/null +++ b/swagger/order.go @@ -0,0 +1,84 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Placement, Cancellation, Amending, and History +type Order struct { + OrderID string `json:"orderID"` + + ClOrdID string `json:"clOrdID,omitempty"` + + ClOrdLinkID string `json:"clOrdLinkID,omitempty"` + + Account float32 `json:"account,omitempty"` + + Symbol string `json:"symbol,omitempty"` + + Side string `json:"side,omitempty"` + + SimpleOrderQty float64 `json:"simpleOrderQty,omitempty"` + + OrderQty float32 `json:"orderQty,omitempty"` + + Price float64 `json:"price,omitempty"` + + DisplayQty float32 `json:"displayQty,omitempty"` + + StopPx float64 `json:"stopPx,omitempty"` + + PegOffsetValue float64 `json:"pegOffsetValue,omitempty"` + + PegPriceType string `json:"pegPriceType,omitempty"` + + Currency string `json:"currency,omitempty"` + + SettlCurrency string `json:"settlCurrency,omitempty"` + + OrdType string `json:"ordType,omitempty"` + + TimeInForce string `json:"timeInForce,omitempty"` + + ExecInst string `json:"execInst,omitempty"` + + ContingencyType string `json:"contingencyType,omitempty"` + + ExDestination string `json:"exDestination,omitempty"` + + OrdStatus string `json:"ordStatus,omitempty"` + + Triggered string `json:"triggered,omitempty"` + + WorkingIndicator bool `json:"workingIndicator,omitempty"` + + OrdRejReason string `json:"ordRejReason,omitempty"` + + SimpleLeavesQty float64 `json:"simpleLeavesQty,omitempty"` + + LeavesQty float32 `json:"leavesQty,omitempty"` + + SimpleCumQty float64 `json:"simpleCumQty,omitempty"` + + CumQty float32 `json:"cumQty,omitempty"` + + AvgPx float64 `json:"avgPx,omitempty"` + + MultiLegReportingType string `json:"multiLegReportingType,omitempty"` + + Text string `json:"text,omitempty"` + + TransactTime time.Time `json:"transactTime,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` +} diff --git a/swagger/order_api.go b/swagger/order_api.go new file mode 100644 index 0000000..09de256 --- /dev/null +++ b/swagger/order_api.go @@ -0,0 +1,1241 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" + "fmt" + "io/ioutil" +) + +// Linger please +var ( + _ context.Context +) + +type OrderApiService service + +/* OrderApiService Amend the quantity or price of an open order. + Send an `orderID` or `origClOrdID` to identify the order you wish to amend. Both order quantity and price can be amended. Only one `qty` field can be used to amend. Use the `leavesQty` field to specify how much of the order you wish to remain open. This can be useful if you want to adjust your position's delta by a certain amount, regardless of how much of the order has already filled. Use the `simpleOrderQty` and `simpleLeavesQty` fields to specify order size in Bitcoin, rather than contracts. These fields will round up to the nearest contract. Like order placement, amending can be done in bulk. Simply send a request to `PUT /api/v1/order/bulk` with a JSON body of the shape: `{\"orders\": [{...}, {...}]}`, each object containing the fields used in this endpoint. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "orderID" (string) Order ID + @param "origClOrdID" (string) Client Order ID. See POST /order. + @param "clOrdID" (string) Optional new Client Order ID, requires `origClOrdID`. + @param "simpleOrderQty" (float64) Optional order quantity in units of the underlying instrument (i.e. Bitcoin). + @param "orderQty" (float32) Optional order quantity in units of the instrument (i.e. contracts). + @param "simpleLeavesQty" (float64) Optional leaves quantity in units of the underlying instrument (i.e. Bitcoin). Useful for amending partially filled orders. + @param "leavesQty" (float32) Optional leaves quantity in units of the instrument (i.e. contracts). Useful for amending partially filled orders. + @param "price" (float64) Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. + @param "stopPx" (float64) Optional trigger price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. Use a price below the current price for stop-sell orders and buy-if-touched orders. + @param "pegOffsetValue" (float64) Optional trailing offset from the current price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders; use a negative offset for stop-sell orders and buy-if-touched orders. Optional offset from the peg price for 'Pegged' orders. + @param "text" (string) Optional amend annotation. e.g. 'Adjust skew'. + @return Order*/ +func (a *OrderApiService) OrderAmend(ctx context.Context, localVarOptionals map[string]interface{}) (Order, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Put") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Order + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["orderID"], "string", "orderID"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["origClOrdID"], "string", "origClOrdID"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["clOrdID"], "string", "clOrdID"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["simpleOrderQty"], "float64", "simpleOrderQty"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["orderQty"], "float32", "orderQty"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["simpleLeavesQty"], "float64", "simpleLeavesQty"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["leavesQty"], "float32", "leavesQty"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["price"], "float64", "price"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["stopPx"], "float64", "stopPx"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["pegOffsetValue"], "float64", "pegOffsetValue"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["text"], "string", "text"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["orderID"].(string); localVarOk { + localVarFormParams.Add("orderID", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["origClOrdID"].(string); localVarOk { + localVarFormParams.Add("origClOrdID", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["clOrdID"].(string); localVarOk { + localVarFormParams.Add("clOrdID", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["simpleOrderQty"].(float64); localVarOk { + localVarFormParams.Add("simpleOrderQty", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["orderQty"].(float32); localVarOk { + localVarFormParams.Add("orderQty", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["simpleLeavesQty"].(float64); localVarOk { + localVarFormParams.Add("simpleLeavesQty", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["leavesQty"].(float32); localVarOk { + localVarFormParams.Add("leavesQty", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["price"].(float64); localVarOk { + localVarFormParams.Add("price", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["stopPx"].(float64); localVarOk { + localVarFormParams.Add("stopPx", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["pegOffsetValue"].(float64); localVarOk { + localVarFormParams.Add("pegOffsetValue", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["text"].(string); localVarOk { + localVarFormParams.Add("text", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderApiService Amend multiple orders for the same symbol. + Similar to POST /amend, but with multiple orders. `application/json` only. Ratelimited at 50%. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "orders" (string) An array of orders. + @return []Order*/ +func (a *OrderApiService) OrderAmendBulk(ctx context.Context, localVarOptionals map[string]interface{}) ([]Order, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Put") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Order + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order/bulk" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["orders"], "string", "orders"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["orders"].(string); localVarOk { + localVarFormParams.Add("orders", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderApiService Cancel order(s). Send multiple order IDs to cancel in bulk. + Either an orderID or a clOrdID must be provided. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "orderID" (string) Order ID(s). + @param "clOrdID" (string) Client Order ID(s). See POST /order. + @param "text" (string) Optional cancellation annotation. e.g. 'Spread Exceeded'. + @return []Order*/ +func (a *OrderApiService) OrderCancel(ctx context.Context, localVarOptionals map[string]interface{}) ([]Order, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Delete") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Order + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["orderID"], "string", "orderID"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["clOrdID"], "string", "clOrdID"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["text"], "string", "text"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["orderID"].(string); localVarOk { + localVarFormParams.Add("orderID", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["clOrdID"].(string); localVarOk { + localVarFormParams.Add("clOrdID", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["text"].(string); localVarOk { + localVarFormParams.Add("text", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderApiService Cancels all of your orders. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Optional symbol. If provided, only cancels orders for that symbol. + @param "filter" (string) Optional filter for cancellation. Use to only cancel some orders, e.g. `{\"side\": \"Buy\"}`. + @param "text" (string) Optional cancellation annotation. e.g. 'Spread Exceeded' + @return interface{}*/ +func (a *OrderApiService) OrderCancelAll(ctx context.Context, localVarOptionals map[string]interface{}) (interface{}, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Delete") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload interface{} + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order/all" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["text"], "string", "text"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarFormParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarFormParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["text"].(string); localVarOk { + localVarFormParams.Add("text", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderApiService Automatically cancel all your orders after a specified timeout. + Useful as a dead-man's switch to ensure your orders are canceled in case of an outage. If called repeatedly, the existing offset will be canceled and a new one will be inserted in its place. Example usage: call this route at 15s intervals with an offset of 60000 (60s). If this route is not called within 60 seconds, all your orders will be automatically canceled. This is also available via [WebSocket](https://www.bitmex.com/app/wsAPI#dead-man-s-switch-auto-cancel-). + * @param ctx context.Context Authentication Context + @param timeout Timeout in ms. Set to 0 to cancel this timer. + @return interface{}*/ +func (a *OrderApiService) OrderCancelAllAfter(ctx context.Context, timeout float64) (interface{}, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload interface{} + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order/cancelAllAfter" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("timeout", parameterToString(timeout, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderApiService Close a position. [Deprecated, use POST /order with execInst: 'Close'] + If no `price` is specified, a market order will be submitted to close the whole of your position. This will also close all other open orders in this symbol. + * @param ctx context.Context Authentication Context + @param symbol Symbol of position to close. + @param optional (nil or map[string]interface{}) with one or more of: + @param "price" (float64) Optional limit price. + @return Order*/ +func (a *OrderApiService) OrderClosePosition(ctx context.Context, symbol string, localVarOptionals map[string]interface{}) (Order, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Order + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order/closePosition" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["price"], "float64", "price"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("symbol", parameterToString(symbol, "")) + if localVarTempParam, localVarOk := localVarOptionals["price"].(float64); localVarOk { + localVarFormParams.Add("price", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderApiService Get your orders. + To get open orders only, send {\"open\": true} in the filter param. See <a href=\"http://www.onixs.biz/fix-dictionary/5.0.SP2/msgType_D_68.html\">the FIX Spec</a> for explanations of these fields. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Order*/ +func (a *OrderApiService) OrderGetOrders(ctx context.Context, localVarOptionals map[string]interface{}) ([]Order, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Order + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderApiService Create a new order. + ## Placing Orders This endpoint is used for placing orders. See individual fields below for more details on their use. #### Order Types All orders require a `symbol`. All other fields are optional except when otherwise specified. These are the valid `ordType`s: * **Limit**: The default order type. Specify an `orderQty` and `price`. * **Market**: A traditional Market order. A Market order will execute until filled or your bankruptcy price is reached, at which point it will cancel. * **MarketWithLeftOverAsLimit**: A market order that, after eating through the order book as far as permitted by available margin, will become a limit order. The difference between this type and `Market` only affects the behavior in thin books. Upon reaching the deepest possible price, if there is quantity left over, a `Market` order will cancel the remaining quantity. `MarketWithLeftOverAsLimit` will keep the remaining quantity in the books as a `Limit`. * **Stop**: A Stop Market order. Specify an `orderQty` and `stopPx`. When the `stopPx` is reached, the order will be entered into the book. * On sell orders, the order will trigger if the triggering price is lower than the `stopPx`. On buys, higher. * Note: Stop orders do not consume margin until triggered. Be sure that the required margin is available in your account so that it may trigger fully. * `Close` Stops don't require an `orderQty`. See Execution Instructions below. * **StopLimit**: Like a Stop Market, but enters a Limit order instead of a Market order. Specify an `orderQty`, `stopPx`, and `price`. * **MarketIfTouched**: Similar to a Stop, but triggers are done in the opposite direction. Useful for Take Profit orders. * **LimitIfTouched**: As above; use for Take Profit Limit orders. #### Execution Instructions The following `execInst`s are supported. If using multiple, separate with a comma (e.g. `LastPrice,Close`). * **ParticipateDoNotInitiate**: Also known as a Post-Only order. If this order would have executed on placement, it will cancel instead. * **AllOrNone**: Valid only for hidden orders (`displayQty: 0`). Use to only execute if the entire order would fill. * **MarkPrice, LastPrice, IndexPrice**: Used by stop and if-touched orders to determine the triggering price. Use only one. By default, `'MarkPrice'` is used. Also used for Pegged orders to define the value of `'LastPeg'`. * **ReduceOnly**: A `'ReduceOnly'` order can only reduce your position, not increase it. If you have a `'ReduceOnly'` limit order that rests in the order book while the position is reduced by other orders, then its order quantity will be amended down or canceled. If there are multiple `'ReduceOnly'` orders the least agresssive will be amended first. * **Close**: `'Close'` implies `'ReduceOnly'`. A `'Close'` order will cancel other active limit orders with the same side and symbol if the open quantity exceeds the current position. This is useful for stops: by canceling these orders, a `'Close'` Stop is ensured to have the margin required to execute, and can only execute up to the full size of your position. If not specified, a `'Close'` order has an `orderQty` equal to your current position's size. #### Linked Orders Linked Orders are an advanced capability. It is very powerful, but its use requires careful coding and testing. Please follow this document carefully and use the [Testnet Exchange](https://testnet.bitmex.com) while developing. BitMEX offers four advanced Linked Order types: * **OCO**: *One Cancels the Other*. A very flexible version of the standard Stop / Take Profit technique. Multiple orders may be linked together using a single `clOrdLinkID`. Send a `contingencyType` of `OneCancelsTheOther` on the orders. The first order that fully or partially executes (or activates for `Stop` orders) will cancel all other orders with the same `clOrdLinkID`. * **OTO**: *One Triggers the Other*. Send a `contingencyType` of `'OneTriggersTheOther'` on the primary order and then subsequent orders with the same `clOrdLinkID` will be not be triggered until the primary order fully executes. * **OUOA**: *One Updates the Other Absolute*. Send a `contingencyType` of `'OneUpdatesTheOtherAbsolute'` on the orders. Then as one order has a execution, other orders with the same `clOrdLinkID` will have their order quantity amended down by the execution quantity. * **OUOP**: *One Updates the Other Proportional*. Send a `contingencyType` of `'OneUpdatesTheOtherProportional'` on the orders. Then as one order has a execution, other orders with the same `clOrdLinkID` will have their order quantity reduced proportionally by the fill percentage. #### Trailing Stops You may use `pegPriceType` of `'TrailingStopPeg'` to create Trailing Stops. The pegged `stopPx` will move as the market moves away from the peg, and freeze as the market moves toward it. To use, combine with `pegOffsetValue` to set the `stopPx` of your order. The peg is set to the triggering price specified in the `execInst` (default `'MarkPrice'`). Use a negative offset for stop-sell and buy-if-touched orders. Requires `ordType`: `'Stop', 'StopLimit', 'MarketIfTouched', 'LimitIfTouched'`. #### Simple Quantities Send a `simpleOrderQty` instead of an `orderQty` to create an order denominated in the underlying currency. This is useful for opening up a position with 1 XBT of exposure without having to calculate how many contracts it is. #### Rate Limits See the [Bulk Order Documentation](#!/Order/Order_newBulk) if you need to place multiple orders at the same time. Bulk orders require fewer risk checks in the trading engine and thus are ratelimited at **1/10** the normal rate. You can also improve your reactivity to market movements while staying under your ratelimit by using the [Amend](#!/Order/Order_amend) and [Amend Bulk](#!/Order/Order_amendBulk) endpoints. This allows you to stay in the market and avoids the cancel/replace cycle. #### Tracking Your Orders If you want to keep track of order IDs yourself, set a unique `clOrdID` per order. This `clOrdID` will come back as a property on the order and any related executions (including on the WebSocket), and can be used to get or cancel the order. Max length is 36 characters. + * @param ctx context.Context Authentication Context + @param symbol Instrument symbol. e.g. 'XBTUSD'. + @param optional (nil or map[string]interface{}) with one or more of: + @param "side" (string) Order side. Valid options: Buy, Sell. Defaults to 'Buy' unless `orderQty` or `simpleOrderQty` is negative. + @param "simpleOrderQty" (float64) Order quantity in units of the underlying instrument (i.e. Bitcoin). + @param "quantity" (float32) Deprecated: use `orderQty`. + @param "orderQty" (float32) Order quantity in units of the instrument (i.e. contracts). + @param "price" (float64) Optional limit price for 'Limit', 'StopLimit', and 'LimitIfTouched' orders. + @param "displayQty" (float32) Optional quantity to display in the book. Use 0 for a fully hidden order. + @param "stopPrice" (float64) Deprecated: use `stopPx`. + @param "stopPx" (float64) Optional trigger price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. Use a price below the current price for stop-sell orders and buy-if-touched orders. Use `execInst` of 'MarkPrice' or 'LastPrice' to define the current price used for triggering. + @param "clOrdID" (string) Optional Client Order ID. This clOrdID will come back on the order and any related executions. + @param "clOrdLinkID" (string) Optional Client Order Link ID for contingent orders. + @param "pegOffsetValue" (float64) Optional trailing offset from the current price for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders; use a negative offset for stop-sell orders and buy-if-touched orders. Optional offset from the peg price for 'Pegged' orders. + @param "pegPriceType" (string) Optional peg price type. Valid options: LastPeg, MidPricePeg, MarketPeg, PrimaryPeg, TrailingStopPeg. + @param "type_" (string) Deprecated: use `ordType`. + @param "ordType" (string) Order type. Valid options: Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, MarketWithLeftOverAsLimit, Pegged. Defaults to 'Limit' when `price` is specified. Defaults to 'Stop' when `stopPx` is specified. Defaults to 'StopLimit' when `price` and `stopPx` are specified. + @param "timeInForce" (string) Time in force. Valid options: Day, GoodTillCancel, ImmediateOrCancel, FillOrKill. Defaults to 'GoodTillCancel' for 'Limit', 'StopLimit', 'LimitIfTouched', and 'MarketWithLeftOverAsLimit' orders. + @param "execInst" (string) Optional execution instructions. Valid options: ParticipateDoNotInitiate, AllOrNone, MarkPrice, IndexPrice, LastPrice, Close, ReduceOnly, Fixed. 'AllOrNone' instruction requires `displayQty` to be 0. 'MarkPrice', 'IndexPrice' or 'LastPrice' instruction valid for 'Stop', 'StopLimit', 'MarketIfTouched', and 'LimitIfTouched' orders. + @param "contingencyType" (string) Optional contingency type for use with `clOrdLinkID`. Valid options: OneCancelsTheOther, OneTriggersTheOther, OneUpdatesTheOtherAbsolute, OneUpdatesTheOtherProportional. + @param "text" (string) Optional order annotation. e.g. 'Take profit'. + @return Order*/ +func (a *OrderApiService) OrderNew(ctx context.Context, symbol string, localVarOptionals map[string]interface{}) (Order, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Order + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["side"], "string", "side"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["simpleOrderQty"], "float64", "simpleOrderQty"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["quantity"], "float32", "quantity"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["orderQty"], "float32", "orderQty"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["price"], "float64", "price"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["displayQty"], "float32", "displayQty"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["stopPrice"], "float64", "stopPrice"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["stopPx"], "float64", "stopPx"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["clOrdID"], "string", "clOrdID"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["clOrdLinkID"], "string", "clOrdLinkID"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["pegOffsetValue"], "float64", "pegOffsetValue"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["pegPriceType"], "string", "pegPriceType"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["type_"], "string", "type_"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["ordType"], "string", "ordType"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["timeInForce"], "string", "timeInForce"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["execInst"], "string", "execInst"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["contingencyType"], "string", "contingencyType"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["text"], "string", "text"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("symbol", parameterToString(symbol, "")) + if localVarTempParam, localVarOk := localVarOptionals["side"].(string); localVarOk { + localVarFormParams.Add("side", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["simpleOrderQty"].(float64); localVarOk { + localVarFormParams.Add("simpleOrderQty", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["quantity"].(float32); localVarOk { + localVarFormParams.Add("quantity", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["orderQty"].(float32); localVarOk { + localVarFormParams.Add("orderQty", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["price"].(float64); localVarOk { + localVarFormParams.Add("price", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["displayQty"].(float32); localVarOk { + localVarFormParams.Add("displayQty", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["stopPrice"].(float64); localVarOk { + localVarFormParams.Add("stopPrice", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["stopPx"].(float64); localVarOk { + localVarFormParams.Add("stopPx", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["clOrdID"].(string); localVarOk { + localVarFormParams.Add("clOrdID", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["clOrdLinkID"].(string); localVarOk { + localVarFormParams.Add("clOrdLinkID", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["pegOffsetValue"].(float64); localVarOk { + localVarFormParams.Add("pegOffsetValue", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["pegPriceType"].(string); localVarOk { + localVarFormParams.Add("pegPriceType", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["type_"].(string); localVarOk { + localVarFormParams.Add("type", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["ordType"].(string); localVarOk { + localVarFormParams.Add("ordType", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["timeInForce"].(string); localVarOk { + localVarFormParams.Add("timeInForce", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["execInst"].(string); localVarOk { + localVarFormParams.Add("execInst", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["contingencyType"].(string); localVarOk { + localVarFormParams.Add("contingencyType", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["text"].(string); localVarOk { + localVarFormParams.Add("text", parameterToString(localVarTempParam, "")) + } + + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + DebugHttpRequest(r) + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + bodyBytes, _ := ioutil.ReadAll(localVarHttpResponse.Body) + fmt.Printf("%s\n", string(bodyBytes)) + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderApiService Create multiple new orders for the same symbol. + This endpoint is used for placing bulk orders. Valid order types are Market, Limit, Stop, StopLimit, MarketIfTouched, LimitIfTouched, MarketWithLeftOverAsLimit, and Pegged. Each individual order object in the array should have the same properties as an individual POST /order call. This endpoint is much faster for getting many orders into the book at once. Because it reduces load on BitMEX systems, this endpoint is ratelimited at `ceil(0.1 * orders)`. Submitting 10 orders via a bulk order call will only count as 1 request, 15 as 2, 32 as 4, and so on. For now, only `application/json` is supported on this endpoint. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "orders" (string) An array of orders. + @return []Order*/ +func (a *OrderApiService) OrderNewBulk(ctx context.Context, localVarOptionals map[string]interface{}) ([]Order, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Order + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/order/bulk" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["orders"], "string", "orders"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["orders"].(string); localVarOk { + localVarFormParams.Add("orders", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/order_book.go b/swagger/order_book.go new file mode 100644 index 0000000..100bc30 --- /dev/null +++ b/swagger/order_book.go @@ -0,0 +1,32 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Level 2 Book Data +type OrderBook struct { + Symbol string `json:"symbol"` + + Level float32 `json:"level"` + + BidSize float32 `json:"bidSize,omitempty"` + + BidPrice float64 `json:"bidPrice,omitempty"` + + AskPrice float64 `json:"askPrice,omitempty"` + + AskSize float32 `json:"askSize,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` +} diff --git a/swagger/order_book_api.go b/swagger/order_book_api.go new file mode 100644 index 0000000..1a8deef --- /dev/null +++ b/swagger/order_book_api.go @@ -0,0 +1,174 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type OrderBookApiService service + +/* OrderBookApiService Get current orderbook [deprecated, use /orderBook/L2]. + + @param symbol Instrument symbol. Send a series (e.g. XBT) to get data for the nearest contract in that series. + @param optional (nil or map[string]interface{}) with one or more of: + @param "depth" (float32) Orderbook depth. + @return []OrderBook*/ +func (a *OrderBookApiService) OrderBookGet(symbol string, localVarOptionals map[string]interface{}) ([]OrderBook, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []OrderBook + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/orderBook" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["depth"], "float32", "depth"); err != nil { + return successPayload, nil, err + } + + localVarQueryParams.Add("symbol", parameterToString(symbol, "")) + if localVarTempParam, localVarOk := localVarOptionals["depth"].(float32); localVarOk { + localVarQueryParams.Add("depth", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* OrderBookApiService Get current orderbook in vertical format. + + @param symbol Instrument symbol. Send a series (e.g. XBT) to get data for the nearest contract in that series. + @param optional (nil or map[string]interface{}) with one or more of: + @param "depth" (float32) Orderbook depth per side. Send 0 for full depth. + @return []OrderBookL2*/ +func (a *OrderBookApiService) OrderBookGetL2(symbol string, localVarOptionals map[string]interface{}) ([]OrderBookL2, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []OrderBookL2 + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/orderBook/L2" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["depth"], "float32", "depth"); err != nil { + return successPayload, nil, err + } + + localVarQueryParams.Add("symbol", parameterToString(symbol, "")) + if localVarTempParam, localVarOk := localVarOptionals["depth"].(float32); localVarOk { + localVarQueryParams.Add("depth", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/order_book_l2.go b/swagger/order_book_l2.go new file mode 100644 index 0000000..4318248 --- /dev/null +++ b/swagger/order_book_l2.go @@ -0,0 +1,23 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type OrderBookL2 struct { + Symbol string `json:"symbol"` + + Id float32 `json:"id"` + + Side string `json:"side"` + + Size float32 `json:"size,omitempty"` + + Price float64 `json:"price,omitempty"` +} diff --git a/swagger/position.go b/swagger/position.go new file mode 100644 index 0000000..1a2e889 --- /dev/null +++ b/swagger/position.go @@ -0,0 +1,200 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Summary of Open and Closed Positions +type Position struct { + Account float32 `json:"account"` + + Symbol string `json:"symbol"` + + Currency string `json:"currency"` + + Underlying string `json:"underlying,omitempty"` + + QuoteCurrency string `json:"quoteCurrency,omitempty"` + + Commission float64 `json:"commission,omitempty"` + + InitMarginReq float64 `json:"initMarginReq,omitempty"` + + MaintMarginReq float64 `json:"maintMarginReq,omitempty"` + + RiskLimit float32 `json:"riskLimit,omitempty"` + + Leverage float64 `json:"leverage,omitempty"` + + CrossMargin bool `json:"crossMargin,omitempty"` + + DeleveragePercentile float64 `json:"deleveragePercentile,omitempty"` + + RebalancedPnl float32 `json:"rebalancedPnl,omitempty"` + + PrevRealisedPnl float32 `json:"prevRealisedPnl,omitempty"` + + PrevUnrealisedPnl float32 `json:"prevUnrealisedPnl,omitempty"` + + PrevClosePrice float64 `json:"prevClosePrice,omitempty"` + + OpeningTimestamp time.Time `json:"openingTimestamp,omitempty"` + + OpeningQty float32 `json:"openingQty,omitempty"` + + OpeningCost float32 `json:"openingCost,omitempty"` + + OpeningComm float32 `json:"openingComm,omitempty"` + + OpenOrderBuyQty float32 `json:"openOrderBuyQty,omitempty"` + + OpenOrderBuyCost float32 `json:"openOrderBuyCost,omitempty"` + + OpenOrderBuyPremium float32 `json:"openOrderBuyPremium,omitempty"` + + OpenOrderSellQty float32 `json:"openOrderSellQty,omitempty"` + + OpenOrderSellCost float32 `json:"openOrderSellCost,omitempty"` + + OpenOrderSellPremium float32 `json:"openOrderSellPremium,omitempty"` + + ExecBuyQty float32 `json:"execBuyQty,omitempty"` + + ExecBuyCost float32 `json:"execBuyCost,omitempty"` + + ExecSellQty float32 `json:"execSellQty,omitempty"` + + ExecSellCost float32 `json:"execSellCost,omitempty"` + + ExecQty float32 `json:"execQty,omitempty"` + + ExecCost float32 `json:"execCost,omitempty"` + + ExecComm float32 `json:"execComm,omitempty"` + + CurrentTimestamp time.Time `json:"currentTimestamp,omitempty"` + + CurrentQty float32 `json:"currentQty,omitempty"` + + CurrentCost float32 `json:"currentCost,omitempty"` + + CurrentComm float32 `json:"currentComm,omitempty"` + + RealisedCost float32 `json:"realisedCost,omitempty"` + + UnrealisedCost float32 `json:"unrealisedCost,omitempty"` + + GrossOpenCost float32 `json:"grossOpenCost,omitempty"` + + GrossOpenPremium float32 `json:"grossOpenPremium,omitempty"` + + GrossExecCost float32 `json:"grossExecCost,omitempty"` + + IsOpen bool `json:"isOpen,omitempty"` + + MarkPrice float64 `json:"markPrice,omitempty"` + + MarkValue float32 `json:"markValue,omitempty"` + + RiskValue float32 `json:"riskValue,omitempty"` + + HomeNotional float64 `json:"homeNotional,omitempty"` + + ForeignNotional float64 `json:"foreignNotional,omitempty"` + + PosState string `json:"posState,omitempty"` + + PosCost float32 `json:"posCost,omitempty"` + + PosCost2 float32 `json:"posCost2,omitempty"` + + PosCross float32 `json:"posCross,omitempty"` + + PosInit float32 `json:"posInit,omitempty"` + + PosComm float32 `json:"posComm,omitempty"` + + PosLoss float32 `json:"posLoss,omitempty"` + + PosMargin float32 `json:"posMargin,omitempty"` + + PosMaint float32 `json:"posMaint,omitempty"` + + PosAllowance float32 `json:"posAllowance,omitempty"` + + TaxableMargin float32 `json:"taxableMargin,omitempty"` + + InitMargin float32 `json:"initMargin,omitempty"` + + MaintMargin float32 `json:"maintMargin,omitempty"` + + SessionMargin float32 `json:"sessionMargin,omitempty"` + + TargetExcessMargin float32 `json:"targetExcessMargin,omitempty"` + + VarMargin float32 `json:"varMargin,omitempty"` + + RealisedGrossPnl float32 `json:"realisedGrossPnl,omitempty"` + + RealisedTax float32 `json:"realisedTax,omitempty"` + + RealisedPnl float32 `json:"realisedPnl,omitempty"` + + UnrealisedGrossPnl float32 `json:"unrealisedGrossPnl,omitempty"` + + LongBankrupt float32 `json:"longBankrupt,omitempty"` + + ShortBankrupt float32 `json:"shortBankrupt,omitempty"` + + TaxBase float32 `json:"taxBase,omitempty"` + + IndicativeTaxRate float64 `json:"indicativeTaxRate,omitempty"` + + IndicativeTax float32 `json:"indicativeTax,omitempty"` + + UnrealisedTax float32 `json:"unrealisedTax,omitempty"` + + UnrealisedPnl float32 `json:"unrealisedPnl,omitempty"` + + UnrealisedPnlPcnt float64 `json:"unrealisedPnlPcnt,omitempty"` + + UnrealisedRoePcnt float64 `json:"unrealisedRoePcnt,omitempty"` + + SimpleQty float64 `json:"simpleQty,omitempty"` + + SimpleCost float64 `json:"simpleCost,omitempty"` + + SimpleValue float64 `json:"simpleValue,omitempty"` + + SimplePnl float64 `json:"simplePnl,omitempty"` + + SimplePnlPcnt float64 `json:"simplePnlPcnt,omitempty"` + + AvgCostPrice float64 `json:"avgCostPrice,omitempty"` + + AvgEntryPrice float64 `json:"avgEntryPrice,omitempty"` + + BreakEvenPrice float64 `json:"breakEvenPrice,omitempty"` + + MarginCallPrice float64 `json:"marginCallPrice,omitempty"` + + LiquidationPrice float64 `json:"liquidationPrice,omitempty"` + + BankruptPrice float64 `json:"bankruptPrice,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` + + LastPrice float64 `json:"lastPrice,omitempty"` + + LastValue float32 `json:"lastValue,omitempty"` +} diff --git a/swagger/position_api.go b/swagger/position_api.go new file mode 100644 index 0000000..8dcf6d1 --- /dev/null +++ b/swagger/position_api.go @@ -0,0 +1,572 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type PositionApiService service + +/* PositionApiService Get your positions. + See <a href=\"http://www.onixs.biz/fix-dictionary/5.0.SP2/msgType_AP_6580.html\">the FIX Spec</a> for explanations of these fields. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "filter" (string) Table filter. For example, send {\"symbol\": \"XBTUSD\"}. + @param "columns" (string) Which columns to fetch. For example, send [\"columnName\"]. + @param "count" (float32) Number of rows to fetch. + @return []Position*/ +func (a *PositionApiService) PositionGet(ctx context.Context, localVarOptionals map[string]interface{}) ([]Position, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Position + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/position" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* PositionApiService Enable isolated margin or cross margin per-position. + Users can switch isolate margin per-position. This function allows switching margin isolation (aka fixed margin) on and off. + * @param ctx context.Context Authentication Context + @param symbol Position symbol to isolate. + @param optional (nil or map[string]interface{}) with one or more of: + @param "enabled" (bool) True for isolated margin, false for cross margin. + @return Position*/ +func (a *PositionApiService) PositionIsolateMargin(ctx context.Context, symbol string, localVarOptionals map[string]interface{}) (Position, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Position + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/position/isolate" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["enabled"], "bool", "enabled"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("symbol", parameterToString(symbol, "")) + if localVarTempParam, localVarOk := localVarOptionals["enabled"].(bool); localVarOk { + localVarFormParams.Add("enabled", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* PositionApiService Transfer equity in or out of a position. + When margin is isolated on a position, use this function to add or remove margin from the position. Note that you cannot remove margin below the initial margin threshold. + * @param ctx context.Context Authentication Context + @param symbol Symbol of position to isolate. + @param amount Amount to transfer, in Satoshis. May be negative. + @return Position*/ +func (a *PositionApiService) PositionTransferIsolatedMargin(ctx context.Context, symbol string, amount float32) (Position, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Position + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/position/transferMargin" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("symbol", parameterToString(symbol, "")) + localVarFormParams.Add("amount", parameterToString(amount, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* PositionApiService Choose leverage for a position. + Users can choose an isolated leverage. This will automatically enable isolated margin. + * @param ctx context.Context Authentication Context + @param symbol Symbol of position to adjust. + @param leverage Leverage value. Send a number between 0.01 and 100 to enable isolated margin with a fixed leverage. Send 0 to enable cross margin. + @return Position*/ +func (a *PositionApiService) PositionUpdateLeverage(ctx context.Context, symbol string, leverage float64) (Position, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Position + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/position/leverage" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("symbol", parameterToString(symbol, "")) + localVarFormParams.Add("leverage", parameterToString(leverage, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* PositionApiService Update your risk limit. + Risk Limits limit the size of positions you can trade at various margin levels. Larger positions require more margin. Please see the Risk Limit documentation for more details. + * @param ctx context.Context Authentication Context + @param symbol Symbol of position to isolate. + @param riskLimit New Risk Limit, in Satoshis. + @return Position*/ +func (a *PositionApiService) PositionUpdateRiskLimit(ctx context.Context, symbol string, riskLimit float32) (Position, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Position + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/position/riskLimit" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("symbol", parameterToString(symbol, "")) + localVarFormParams.Add("riskLimit", parameterToString(riskLimit, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/quote.go b/swagger/quote.go new file mode 100644 index 0000000..07fb1d6 --- /dev/null +++ b/swagger/quote.go @@ -0,0 +1,30 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Best Bid/Offer Snapshots & Historical Bins +type Quote struct { + Timestamp time.Time `json:"timestamp"` + + Symbol string `json:"symbol"` + + BidSize float32 `json:"bidSize,omitempty"` + + BidPrice float64 `json:"bidPrice,omitempty"` + + AskPrice float64 `json:"askPrice,omitempty"` + + AskSize float32 `json:"askSize,omitempty"` +} diff --git a/swagger/quote_api.go b/swagger/quote_api.go new file mode 100644 index 0000000..88e19ab --- /dev/null +++ b/swagger/quote_api.go @@ -0,0 +1,283 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type QuoteApiService service + +/* QuoteApiService Get Quotes. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Quote*/ +func (a *QuoteApiService) QuoteGet(localVarOptionals map[string]interface{}) ([]Quote, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Quote + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/quote" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* QuoteApiService Get previous quotes in time buckets. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "binSize" (string) Time interval to bucket by. Available options: [1m,5m,1h,1d]. + @param "partial" (bool) If true, will send in-progress (incomplete) bins for the current time period. + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Quote*/ +func (a *QuoteApiService) QuoteGetBucketed(localVarOptionals map[string]interface{}) ([]Quote, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Quote + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/quote/bucketed" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["binSize"], "string", "binSize"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["partial"], "bool", "partial"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["binSize"].(string); localVarOk { + localVarQueryParams.Add("binSize", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["partial"].(bool); localVarOk { + localVarQueryParams.Add("partial", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/schema_api.go b/swagger/schema_api.go new file mode 100644 index 0000000..22b9860 --- /dev/null +++ b/swagger/schema_api.go @@ -0,0 +1,161 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type SchemaApiService service + +/* SchemaApiService Get model schemata for data objects returned by this API. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "model" (string) Optional model filter. If omitted, will return all models. + @return interface{}*/ +func (a *SchemaApiService) SchemaGet(localVarOptionals map[string]interface{}) (interface{}, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload interface{} + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/schema" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["model"], "string", "model"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["model"].(string); localVarOk { + localVarQueryParams.Add("model", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* SchemaApiService Returns help text & subject list for websocket usage. + + @return interface{}*/ +func (a *SchemaApiService) SchemaWebsocketHelp() (interface{}, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload interface{} + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/schema/websocketHelp" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/settlement.go b/swagger/settlement.go new file mode 100644 index 0000000..ebb9c03 --- /dev/null +++ b/swagger/settlement.go @@ -0,0 +1,32 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Historical Settlement Data +type Settlement struct { + Timestamp time.Time `json:"timestamp"` + + Symbol string `json:"symbol"` + + SettlementType string `json:"settlementType,omitempty"` + + SettledPrice float64 `json:"settledPrice,omitempty"` + + Bankrupt float32 `json:"bankrupt,omitempty"` + + TaxBase float32 `json:"taxBase,omitempty"` + + TaxRate float64 `json:"taxRate,omitempty"` +} diff --git a/swagger/settlement_api.go b/swagger/settlement_api.go new file mode 100644 index 0000000..c50bb59 --- /dev/null +++ b/swagger/settlement_api.go @@ -0,0 +1,148 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type SettlementApiService service + +/* SettlementApiService Get settlement history. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Settlement*/ +func (a *SettlementApiService) SettlementGet(localVarOptionals map[string]interface{}) ([]Settlement, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Settlement + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/settlement" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/stats.go b/swagger/stats.go new file mode 100644 index 0000000..d653e77 --- /dev/null +++ b/swagger/stats.go @@ -0,0 +1,26 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +// Exchange Statistics +type Stats struct { + RootSymbol string `json:"rootSymbol"` + + Currency string `json:"currency,omitempty"` + + Volume24h float32 `json:"volume24h,omitempty"` + + Turnover24h float32 `json:"turnover24h,omitempty"` + + OpenInterest float32 `json:"openInterest,omitempty"` + + OpenValue float32 `json:"openValue,omitempty"` +} diff --git a/swagger/stats_api.go b/swagger/stats_api.go new file mode 100644 index 0000000..2aba658 --- /dev/null +++ b/swagger/stats_api.go @@ -0,0 +1,215 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type StatsApiService service + +/* StatsApiService Get exchange-wide and per-series turnover and volume statistics. + + @return []Stats*/ +func (a *StatsApiService) StatsGet() ([]Stats, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Stats + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/stats" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* StatsApiService Get historical exchange-wide and per-series turnover and volume statistics. + + @return []StatsHistory*/ +func (a *StatsApiService) StatsHistory() ([]StatsHistory, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []StatsHistory + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/stats/history" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* StatsApiService Get a summary of exchange statistics in USD. + + @return []StatsUsd*/ +func (a *StatsApiService) StatsHistoryUSD() ([]StatsUsd, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []StatsUsd + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/stats/historyUSD" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/stats_history.go b/swagger/stats_history.go new file mode 100644 index 0000000..dca146a --- /dev/null +++ b/swagger/stats_history.go @@ -0,0 +1,27 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type StatsHistory struct { + Date time.Time `json:"date"` + + RootSymbol string `json:"rootSymbol"` + + Currency string `json:"currency,omitempty"` + + Volume float32 `json:"volume,omitempty"` + + Turnover float32 `json:"turnover,omitempty"` +} diff --git a/swagger/stats_usd.go b/swagger/stats_usd.go new file mode 100644 index 0000000..daf473c --- /dev/null +++ b/swagger/stats_usd.go @@ -0,0 +1,25 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type StatsUsd struct { + RootSymbol string `json:"rootSymbol"` + + Currency string `json:"currency,omitempty"` + + Turnover24h float32 `json:"turnover24h,omitempty"` + + Turnover30d float32 `json:"turnover30d,omitempty"` + + Turnover365d float32 `json:"turnover365d,omitempty"` + + Turnover float32 `json:"turnover,omitempty"` +} diff --git a/swagger/trade.go b/swagger/trade.go new file mode 100644 index 0000000..decedb3 --- /dev/null +++ b/swagger/trade.go @@ -0,0 +1,38 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Individual & Bucketed Trades +type Trade struct { + Timestamp time.Time `json:"timestamp"` + + Symbol string `json:"symbol"` + + Side string `json:"side,omitempty"` + + Size float32 `json:"size,omitempty"` + + Price float64 `json:"price,omitempty"` + + TickDirection string `json:"tickDirection,omitempty"` + + TrdMatchID string `json:"trdMatchID,omitempty"` + + GrossValue float32 `json:"grossValue,omitempty"` + + HomeNotional float64 `json:"homeNotional,omitempty"` + + ForeignNotional float64 `json:"foreignNotional,omitempty"` +} diff --git a/swagger/trade_api.go b/swagger/trade_api.go new file mode 100644 index 0000000..b8d3806 --- /dev/null +++ b/swagger/trade_api.go @@ -0,0 +1,284 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "time" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type TradeApiService service + +/* TradeApiService Get Trades. + Please note that indices (symbols starting with `.`) post trades at intervals to the trade feed. These have a `size` of 0 and are used only to indicate a changing price. See [the FIX Spec](http://www.onixs.biz/fix-dictionary/5.0.SP2/msgType_AE_6569.html) for explanations of these fields. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []Trade*/ +func (a *TradeApiService) TradeGet(localVarOptionals map[string]interface{}) ([]Trade, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Trade + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/trade" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* TradeApiService Get previous trades in time buckets. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "binSize" (string) Time interval to bucket by. Available options: [1m,5m,1h,1d]. + @param "partial" (bool) If true, will send in-progress (incomplete) bins for the current time period. + @param "symbol" (string) Instrument symbol. Send a bare series (e.g. XBU) to get data for the nearest expiring contract in that series. You can also send a timeframe, e.g. `XBU:monthly`. Timeframes are `daily`, `weekly`, `monthly`, `quarterly`, and `biquarterly`. + @param "filter" (string) Generic table filter. Send JSON key/value pairs, such as `{\"key\": \"value\"}`. You can key on individual fields, and do more advanced querying on timestamps. See the [Timestamp Docs](https://www.bitmex.com/app/restAPI#timestamp-filters) for more details. + @param "columns" (string) Array of column names to fetch. If omitted, will return all columns. Note that this method will always return item keys, even when not specified, so you may receive more columns that you expect. + @param "count" (float32) Number of results to fetch. + @param "start" (float32) Starting point for results. + @param "reverse" (bool) If true, will sort results newest first. + @param "startTime" (time.Time) Starting date filter for results. + @param "endTime" (time.Time) Ending date filter for results. + @return []TradeBin*/ +func (a *TradeApiService) TradeGetBucketed(localVarOptionals map[string]interface{}) ([]TradeBin, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []TradeBin + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/trade/bucketed" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["binSize"], "string", "binSize"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["partial"], "bool", "partial"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["symbol"], "string", "symbol"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["filter"], "string", "filter"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["columns"], "string", "columns"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["count"], "float32", "count"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["start"], "float32", "start"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["reverse"], "bool", "reverse"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["startTime"], "time.Time", "startTime"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["endTime"], "time.Time", "endTime"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["binSize"].(string); localVarOk { + localVarQueryParams.Add("binSize", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["partial"].(bool); localVarOk { + localVarQueryParams.Add("partial", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["symbol"].(string); localVarOk { + localVarQueryParams.Add("symbol", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["filter"].(string); localVarOk { + localVarQueryParams.Add("filter", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["columns"].(string); localVarOk { + localVarQueryParams.Add("columns", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["count"].(float32); localVarOk { + localVarQueryParams.Add("count", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["start"].(float32); localVarOk { + localVarQueryParams.Add("start", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["reverse"].(bool); localVarOk { + localVarQueryParams.Add("reverse", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["startTime"].(time.Time); localVarOk { + localVarQueryParams.Add("startTime", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["endTime"].(time.Time); localVarOk { + localVarQueryParams.Add("endTime", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/trade_bin.go b/swagger/trade_bin.go new file mode 100644 index 0000000..e4c4498 --- /dev/null +++ b/swagger/trade_bin.go @@ -0,0 +1,43 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type TradeBin struct { + Timestamp time.Time `json:"timestamp"` + + Symbol string `json:"symbol"` + + Open float64 `json:"open,omitempty"` + + High float64 `json:"high,omitempty"` + + Low float64 `json:"low,omitempty"` + + Close float64 `json:"close,omitempty"` + + Trades float32 `json:"trades,omitempty"` + + Volume float32 `json:"volume,omitempty"` + + Vwap float64 `json:"vwap,omitempty"` + + LastSize float32 `json:"lastSize,omitempty"` + + Turnover float32 `json:"turnover,omitempty"` + + HomeNotional float64 `json:"homeNotional,omitempty"` + + ForeignNotional float64 `json:"foreignNotional,omitempty"` +} diff --git a/swagger/transaction.go b/swagger/transaction.go new file mode 100644 index 0000000..fc95ada --- /dev/null +++ b/swagger/transaction.go @@ -0,0 +1,41 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type Transaction struct { + TransactID string `json:"transactID"` + + Account float32 `json:"account,omitempty"` + + Currency string `json:"currency,omitempty"` + + TransactType string `json:"transactType,omitempty"` + + Amount float32 `json:"amount,omitempty"` + + Fee float32 `json:"fee,omitempty"` + + TransactStatus string `json:"transactStatus,omitempty"` + + Address string `json:"address,omitempty"` + + Tx string `json:"tx,omitempty"` + + Text string `json:"text,omitempty"` + + TransactTime time.Time `json:"transactTime,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` +} diff --git a/swagger/user.go b/swagger/user.go new file mode 100644 index 0000000..140c6bd --- /dev/null +++ b/swagger/user.go @@ -0,0 +1,46 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +// Account Operations +type User struct { + Id float32 `json:"id,omitempty"` + + OwnerId float32 `json:"ownerId,omitempty"` + + Firstname string `json:"firstname,omitempty"` + + Lastname string `json:"lastname,omitempty"` + + Username string `json:"username"` + + Email string `json:"email"` + + Phone string `json:"phone,omitempty"` + + Created time.Time `json:"created,omitempty"` + + LastUpdated time.Time `json:"lastUpdated,omitempty"` + + Preferences *UserPreferences `json:"preferences,omitempty"` + + TFAEnabled string `json:"TFAEnabled,omitempty"` + + AffiliateID string `json:"affiliateID,omitempty"` + + PgpPubKey string `json:"pgpPubKey,omitempty"` + + Country string `json:"country,omitempty"` +} diff --git a/swagger/user_api.go b/swagger/user_api.go new file mode 100644 index 0000000..1b4fd30 --- /dev/null +++ b/swagger/user_api.go @@ -0,0 +1,2079 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "net/url" + "net/http" + "strings" + "golang.org/x/net/context" + "encoding/json" +) + +// Linger please +var ( + _ context.Context +) + +type UserApiService service + +/* UserApiService Cancel a withdrawal. + + @param token + @return Transaction*/ +func (a *UserApiService) UserCancelWithdrawal(token string) (Transaction, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Transaction + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/cancelWithdrawal" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("token", parameterToString(token, "")) + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Check if a referral code is valid. + If the code is valid, responds with the referral code's discount (e.g. `0.1` for 10%). Otherwise, will return a 404. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "referralCode" (string) + @return float64*/ +func (a *UserApiService) UserCheckReferralCode(localVarOptionals map[string]interface{}) (float64, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload float64 + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/checkReferralCode" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["referralCode"], "string", "referralCode"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["referralCode"].(string); localVarOk { + localVarQueryParams.Add("referralCode", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Confirm your email address with a token. + + @param token + @return AccessToken*/ +func (a *UserApiService) UserConfirm(token string) (AccessToken, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload AccessToken + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/confirmEmail" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("token", parameterToString(token, "")) + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Confirm two-factor auth for this account. If using a Yubikey, simply send a token to this endpoint. + * @param ctx context.Context Authentication Context + @param token Token from your selected TFA type. + @param optional (nil or map[string]interface{}) with one or more of: + @param "type_" (string) Two-factor auth type. Supported types: 'GA' (Google Authenticator), 'Yubikey' + @return bool*/ +func (a *UserApiService) UserConfirmEnableTFA(ctx context.Context, token string, localVarOptionals map[string]interface{}) (bool, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload bool + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/confirmEnableTFA" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["type_"], "string", "type_"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["type_"].(string); localVarOk { + localVarFormParams.Add("type", parameterToString(localVarTempParam, "")) + } + localVarFormParams.Add("token", parameterToString(token, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Confirm a withdrawal. + + @param token + @return Transaction*/ +func (a *UserApiService) UserConfirmWithdrawal(token string) (Transaction, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Transaction + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/confirmWithdrawal" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("token", parameterToString(token, "")) + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Disable two-factor auth for this account. + * @param ctx context.Context Authentication Context + @param token Token from your selected TFA type. + @param optional (nil or map[string]interface{}) with one or more of: + @param "type_" (string) Two-factor auth type. Supported types: 'GA' (Google Authenticator) + @return bool*/ +func (a *UserApiService) UserDisableTFA(ctx context.Context, token string, localVarOptionals map[string]interface{}) (bool, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload bool + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/disableTFA" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["type_"], "string", "type_"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["type_"].(string); localVarOk { + localVarFormParams.Add("type", parameterToString(localVarTempParam, "")) + } + localVarFormParams.Add("token", parameterToString(token, "")) + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get your user model. + * @param ctx context.Context Authentication Context + @return User*/ +func (a *UserApiService) UserGet(ctx context.Context, ) (User, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload User + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get your current affiliate/referral status. + * @param ctx context.Context Authentication Context + @return Affiliate*/ +func (a *UserApiService) UserGetAffiliateStatus(ctx context.Context, ) (Affiliate, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Affiliate + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/affiliateStatus" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get your account's commission status. + * @param ctx context.Context Authentication Context + @return []UserCommission*/ +func (a *UserApiService) UserGetCommission(ctx context.Context, ) ([]UserCommission, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []UserCommission + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/commission" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get a deposit address. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "currency" (string) + @return string*/ +func (a *UserApiService) UserGetDepositAddress(ctx context.Context, localVarOptionals map[string]interface{}) (string, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload string + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/depositAddress" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["currency"], "string", "currency"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["currency"].(string); localVarOk { + localVarQueryParams.Add("currency", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get your account's margin status. Send a currency of \"all\" to receive an array of all supported currencies. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "currency" (string) + @return Margin*/ +func (a *UserApiService) UserGetMargin(ctx context.Context, localVarOptionals map[string]interface{}) (Margin, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Margin + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/margin" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["currency"], "string", "currency"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["currency"].(string); localVarOk { + localVarQueryParams.Add("currency", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get your current wallet information. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "currency" (string) + @return Wallet*/ +func (a *UserApiService) UserGetWallet(ctx context.Context, localVarOptionals map[string]interface{}) (Wallet, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Wallet + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/wallet" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["currency"], "string", "currency"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["currency"].(string); localVarOk { + localVarQueryParams.Add("currency", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get a history of all of your wallet transactions (deposits, withdrawals, PNL). + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "currency" (string) + @return []Transaction*/ +func (a *UserApiService) UserGetWalletHistory(ctx context.Context, localVarOptionals map[string]interface{}) ([]Transaction, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Transaction + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/walletHistory" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["currency"], "string", "currency"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["currency"].(string); localVarOk { + localVarQueryParams.Add("currency", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get a summary of all of your wallet transactions (deposits, withdrawals, PNL). + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "currency" (string) + @return []Transaction*/ +func (a *UserApiService) UserGetWalletSummary(ctx context.Context, localVarOptionals map[string]interface{}) ([]Transaction, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload []Transaction + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/walletSummary" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["currency"], "string", "currency"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["currency"].(string); localVarOk { + localVarQueryParams.Add("currency", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Log out of BitMEX. + + @return */ +func (a *UserApiService) UserLogout() (*http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/logout" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + return localVarHttpResponse, err +} + +/* UserApiService Log all systems out of BitMEX. This will revoke all of your account's access tokens, logging you out on all devices. + * @param ctx context.Context Authentication Context + @return float64*/ +func (a *UserApiService) UserLogoutAll(ctx context.Context, ) (float64, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload float64 + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/logoutAll" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get the minimum withdrawal fee for a currency. + This is changed based on network conditions to ensure timely withdrawals. During network congestion, this may be high. The fee is returned in the same currency. + + @param optional (nil or map[string]interface{}) with one or more of: + @param "currency" (string) + @return interface{}*/ +func (a *UserApiService) UserMinWithdrawalFee(localVarOptionals map[string]interface{}) (interface{}, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Get") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload interface{} + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/minWithdrawalFee" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["currency"], "string", "currency"); err != nil { + return successPayload, nil, err + } + + if localVarTempParam, localVarOk := localVarOptionals["currency"].(string); localVarOk { + localVarQueryParams.Add("currency", parameterToString(localVarTempParam, "")) + } + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + r, err := a.client.prepareRequest(nil, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Get secret key for setting up two-factor auth. + Use /confirmEnableTFA directly for Yubikeys. This fails if TFA is already enabled. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "type_" (string) Two-factor auth type. Supported types: 'GA' (Google Authenticator) + @return bool*/ +func (a *UserApiService) UserRequestEnableTFA(ctx context.Context, localVarOptionals map[string]interface{}) (bool, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload bool + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/requestEnableTFA" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["type_"], "string", "type_"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["type_"].(string); localVarOk { + localVarFormParams.Add("type", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Request a withdrawal to an external wallet. + This will send a confirmation email to the email address on record, unless requested via an API Key with the `withdraw` permission. + * @param ctx context.Context Authentication Context + @param currency Currency you're withdrawing. Options: `XBt` + @param amount Amount of withdrawal currency. + @param address Destination Address. + @param optional (nil or map[string]interface{}) with one or more of: + @param "otpToken" (string) 2FA token. Required if 2FA is enabled on your account. + @param "fee" (float64) Network fee for Bitcoin withdrawals. If not specified, a default value will be calculated based on Bitcoin network conditions. You will have a chance to confirm this via email. + @return Transaction*/ +func (a *UserApiService) UserRequestWithdrawal(ctx context.Context, currency string, amount float32, address string, localVarOptionals map[string]interface{}) (Transaction, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload Transaction + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/requestWithdrawal" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["otpToken"], "string", "otpToken"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["fee"], "float64", "fee"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["otpToken"].(string); localVarOk { + localVarFormParams.Add("otpToken", parameterToString(localVarTempParam, "")) + } + localVarFormParams.Add("currency", parameterToString(currency, "")) + localVarFormParams.Add("amount", parameterToString(amount, "")) + localVarFormParams.Add("address", parameterToString(address, "")) + if localVarTempParam, localVarOk := localVarOptionals["fee"].(float64); localVarOk { + localVarFormParams.Add("fee", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Save user preferences. + * @param ctx context.Context Authentication Context + @param prefs + @param optional (nil or map[string]interface{}) with one or more of: + @param "overwrite" (bool) If true, will overwrite all existing preferences. + @return User*/ +func (a *UserApiService) UserSavePreferences(ctx context.Context, prefs string, localVarOptionals map[string]interface{}) (User, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Post") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload User + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user/preferences" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["overwrite"], "bool", "overwrite"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + localVarFormParams.Add("prefs", parameterToString(prefs, "")) + if localVarTempParam, localVarOk := localVarOptionals["overwrite"].(bool); localVarOk { + localVarFormParams.Add("overwrite", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} + +/* UserApiService Update your password, name, and other attributes. + * @param ctx context.Context Authentication Context + @param optional (nil or map[string]interface{}) with one or more of: + @param "firstname" (string) + @param "lastname" (string) + @param "oldPassword" (string) + @param "newPassword" (string) + @param "newPasswordConfirm" (string) + @param "username" (string) Username can only be set once. To reset, email support. + @param "country" (string) Country of residence. + @param "pgpPubKey" (string) PGP Public Key. If specified, automated emails will be sentwith this key. + @return User*/ +func (a *UserApiService) UserUpdate(ctx context.Context, localVarOptionals map[string]interface{}) (User, *http.Response, error) { + var ( + localVarHttpMethod = strings.ToUpper("Put") + localVarPostBody interface{} + localVarFileName string + localVarFileBytes []byte + successPayload User + ) + + // create path and map variables + localVarPath := a.client.cfg.BasePath + "/user" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if err := typeCheckParameter(localVarOptionals["firstname"], "string", "firstname"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["lastname"], "string", "lastname"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["oldPassword"], "string", "oldPassword"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["newPassword"], "string", "newPassword"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["newPasswordConfirm"], "string", "newPasswordConfirm"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["username"], "string", "username"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["country"], "string", "country"); err != nil { + return successPayload, nil, err + } + if err := typeCheckParameter(localVarOptionals["pgpPubKey"], "string", "pgpPubKey"); err != nil { + return successPayload, nil, err + } + + // to determine the Content-Type header + localVarHttpContentTypes := []string{"application/json", "application/x-www-form-urlencoded",} + + // set Content-Type header + localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) + if localVarHttpContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHttpContentType + } + + // to determine the Accept header + localVarHttpHeaderAccepts := []string{ + "application/json", + "application/xml", + "text/xml", + "application/javascript", + "text/javascript", + } + + // set Accept header + localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) + if localVarHttpHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHttpHeaderAccept + } + if localVarTempParam, localVarOk := localVarOptionals["firstname"].(string); localVarOk { + localVarFormParams.Add("firstname", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["lastname"].(string); localVarOk { + localVarFormParams.Add("lastname", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["oldPassword"].(string); localVarOk { + localVarFormParams.Add("oldPassword", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["newPassword"].(string); localVarOk { + localVarFormParams.Add("newPassword", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["newPasswordConfirm"].(string); localVarOk { + localVarFormParams.Add("newPasswordConfirm", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["username"].(string); localVarOk { + localVarFormParams.Add("username", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["country"].(string); localVarOk { + localVarFormParams.Add("country", parameterToString(localVarTempParam, "")) + } + if localVarTempParam, localVarOk := localVarOptionals["pgpPubKey"].(string); localVarOk { + localVarFormParams.Add("pgpPubKey", parameterToString(localVarTempParam, "")) + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-key"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-nonce"] = key + } + } + if ctx != nil { + // API Key Authentication + if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok { + var key string + if auth.Prefix != "" { + key = auth.Prefix + " " + auth.Key + } else { + key = auth.Key + } + localVarHeaderParams["api-signature"] = key + } + } + r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) + if err != nil { + return successPayload, nil, err + } + + localVarHttpResponse, err := a.client.callAPI(r) + if err != nil || localVarHttpResponse == nil { + return successPayload, localVarHttpResponse, err + } + defer localVarHttpResponse.Body.Close() + if localVarHttpResponse.StatusCode >= 300 { + return successPayload, localVarHttpResponse, reportError(localVarHttpResponse.Status) + } + + if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil { + return successPayload, localVarHttpResponse, err + } + + return successPayload, localVarHttpResponse, err +} diff --git a/swagger/user_commission.go b/swagger/user_commission.go new file mode 100644 index 0000000..d356e68 --- /dev/null +++ b/swagger/user_commission.go @@ -0,0 +1,21 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type UserCommission struct { + MakerFee float64 `json:"makerFee,omitempty"` + + TakerFee float64 `json:"takerFee,omitempty"` + + SettlementFee float64 `json:"settlementFee,omitempty"` + + MaxFee float64 `json:"maxFee,omitempty"` +} diff --git a/swagger/user_preferences.go b/swagger/user_preferences.go new file mode 100644 index 0000000..e7815ef --- /dev/null +++ b/swagger/user_preferences.go @@ -0,0 +1,67 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type UserPreferences struct { + AlertOnLiquidations bool `json:"alertOnLiquidations,omitempty"` + + AnimationsEnabled bool `json:"animationsEnabled,omitempty"` + + AnnouncementsLastSeen time.Time `json:"announcementsLastSeen,omitempty"` + + ChatChannelID float64 `json:"chatChannelID,omitempty"` + + ColorTheme string `json:"colorTheme,omitempty"` + + Currency string `json:"currency,omitempty"` + + Debug bool `json:"debug,omitempty"` + + DisableEmails []string `json:"disableEmails,omitempty"` + + HideConfirmDialogs []string `json:"hideConfirmDialogs,omitempty"` + + HideConnectionModal bool `json:"hideConnectionModal,omitempty"` + + HideFromLeaderboard bool `json:"hideFromLeaderboard,omitempty"` + + HideNameFromLeaderboard bool `json:"hideNameFromLeaderboard,omitempty"` + + HideNotifications []string `json:"hideNotifications,omitempty"` + + Locale string `json:"locale,omitempty"` + + MsgsSeen []string `json:"msgsSeen,omitempty"` + + OrderBookBinning *interface{} `json:"orderBookBinning,omitempty"` + + OrderBookType string `json:"orderBookType,omitempty"` + + OrderClearImmediate bool `json:"orderClearImmediate,omitempty"` + + OrderControlsPlusMinus bool `json:"orderControlsPlusMinus,omitempty"` + + Sounds []string `json:"sounds,omitempty"` + + StrictIPCheck bool `json:"strictIPCheck,omitempty"` + + StrictTimeout bool `json:"strictTimeout,omitempty"` + + TickerGroup string `json:"tickerGroup,omitempty"` + + TickerPinned bool `json:"tickerPinned,omitempty"` + + TradeLayout string `json:"tradeLayout,omitempty"` +} diff --git a/swagger/wallet.go b/swagger/wallet.go new file mode 100644 index 0000000..e6083a2 --- /dev/null +++ b/swagger/wallet.go @@ -0,0 +1,67 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +import ( + "time" +) + +type Wallet struct { + Account float32 `json:"account"` + + Currency string `json:"currency"` + + PrevDeposited float32 `json:"prevDeposited,omitempty"` + + PrevWithdrawn float32 `json:"prevWithdrawn,omitempty"` + + PrevTransferIn float32 `json:"prevTransferIn,omitempty"` + + PrevTransferOut float32 `json:"prevTransferOut,omitempty"` + + PrevAmount float32 `json:"prevAmount,omitempty"` + + PrevTimestamp time.Time `json:"prevTimestamp,omitempty"` + + DeltaDeposited float32 `json:"deltaDeposited,omitempty"` + + DeltaWithdrawn float32 `json:"deltaWithdrawn,omitempty"` + + DeltaTransferIn float32 `json:"deltaTransferIn,omitempty"` + + DeltaTransferOut float32 `json:"deltaTransferOut,omitempty"` + + DeltaAmount float32 `json:"deltaAmount,omitempty"` + + Deposited float32 `json:"deposited,omitempty"` + + Withdrawn float32 `json:"withdrawn,omitempty"` + + TransferIn float32 `json:"transferIn,omitempty"` + + TransferOut float32 `json:"transferOut,omitempty"` + + Amount float32 `json:"amount,omitempty"` + + PendingCredit float32 `json:"pendingCredit,omitempty"` + + PendingDebit float32 `json:"pendingDebit,omitempty"` + + ConfirmedDebit float32 `json:"confirmedDebit,omitempty"` + + Timestamp time.Time `json:"timestamp,omitempty"` + + Addr string `json:"addr,omitempty"` + + Script string `json:"script,omitempty"` + + WithdrawalLock []string `json:"withdrawalLock,omitempty"` +} diff --git a/swagger/x_any.go b/swagger/x_any.go new file mode 100644 index 0000000..b917658 --- /dev/null +++ b/swagger/x_any.go @@ -0,0 +1,14 @@ +/* + * 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. + * + * OpenAPI spec version: 1.2.0 + * Contact: support@bitmex.com + * Generated by: https://github.com/swagger-api/swagger-codegen.git + */ + +package swagger + +type XAny struct { +} diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 0000000..2abcc47 --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,7 @@ +package tools + +func CheckErr(err error) { + if err != nil { + panic(err) + } +} diff --git a/tools/tools_test.go b/tools/tools_test.go new file mode 100644 index 0000000..d335d36 --- /dev/null +++ b/tools/tools_test.go @@ -0,0 +1,16 @@ +package tools + +import ( + "testing" + "strconv" +) + +func TestCheckErr(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Errorf("The code did not panic") + } + }() + _, err := strconv.Atoi("x1") + CheckErr(err) +} diff --git a/websocket/websocket.go b/websocket/websocket.go new file mode 100644 index 0000000..7de853a --- /dev/null +++ b/websocket/websocket.go @@ -0,0 +1,67 @@ +package websocket + +import ( + "crypto/hmac" + "crypto/sha256" + "encoding/hex" + "encoding/json" + "fmt" + "net/url" + "reflect" + "time" + "github.com/gorilla/websocket" + "github.com/vmpartner/bitmex/tools" +) + +type Message struct { + Op string `json:"op,omitempty"` + Args []interface{} `json:"args,omitempty"` +} + +func (m *Message) AddArgument(argument string) { + m.Args = append(m.Args, argument) +} + +func Connect(host string) *websocket.Conn { + u := url.URL{Scheme: "wss", Host: host, Path: "/realtime"} + conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil) + tools.CheckErr(err) + + return conn +} + +func ReadFromWSToChannel(c *websocket.Conn, chRead chan<- []byte) { + for { + _, message, err := c.ReadMessage() + //fmt.Println("Read", string(message)) + tools.CheckErr(err) + chRead <- message + } +} + +func WriteFromChannelToWS(c *websocket.Conn, chWrite <-chan interface{}) { + for { + message := <-chWrite + if reflect.TypeOf(message).String() == "websocket.Message" { + var err error + message, err = json.Marshal(message) + tools.CheckErr(err) + } + err := c.WriteMessage(websocket.TextMessage, message.([]byte)) + tools.CheckErr(err) + } +} + +func GetAuthMessage(key string, secret string) Message { + nonce := time.Now().Unix() + 412 + req := fmt.Sprintf("GET/realtime%d", nonce) + sig := hmac.New(sha256.New, []byte(secret)) + sig.Write([]byte(req)) + signature := hex.EncodeToString(sig.Sum(nil)) + var msgKey []interface{} + msgKey = append(msgKey, key) + msgKey = append(msgKey, nonce) + msgKey = append(msgKey, signature) + + return Message{"authKey", msgKey} +} diff --git a/websocket/websocket_test.go b/websocket/websocket_test.go new file mode 100644 index 0000000..3412cdd --- /dev/null +++ b/websocket/websocket_test.go @@ -0,0 +1,74 @@ +package websocket + +import ( + "testing" + "time" + "fmt" + "strings" +) + +func TestConnectMaster(t *testing.T) { + conn := Connect("www.bitmex.com") + if conn == nil { + t.Error("No connect to ws") + } +} + +func TestConnectDev(t *testing.T) { + conn := Connect("testnet.bitmex.com") + if conn == nil { + t.Error("No connect to testnet ws") + } +} + +func TestConnectFail(t *testing.T) { + defer func() { + if r := recover(); r == nil { + t.Errorf("The code did not panic") + } + }() + Connect("") +} + +func TestWorkerReadMessages(t *testing.T) { + chReaderMessage := make(chan []byte) + conn := Connect("testnet.bitmex.com") + go ReadFromWSToChannel(conn, chReaderMessage) + message := <-chReaderMessage + if message == nil { + t.Error("Empty message") + } + close(chReaderMessage) +} + +func TestWorkerWriteMessages(t *testing.T) { + + conn := Connect("testnet.bitmex.com") + + // Read + chReadFromWS := make(chan []byte, 10) + go ReadFromWSToChannel(conn, chReadFromWS) + + // Write + chWriteToWS := make(chan interface{}, 10) + go WriteFromChannelToWS(conn, chWriteToWS) + + // Send ping + chWriteToWS <- []byte(`ping`) + + // Read first response message + message := <-chReadFromWS + if !strings.Contains(string(message), "Welcome to the BitMEX") { + fmt.Println(string(message)) + t.Error("No welcome message") + } + + // Read second response message + message = <-chReadFromWS + if !strings.Contains(string(message), "pong") { + fmt.Println(string(message)) + t.Error("No pong message") + } + + time.Sleep(1 * time.Second) +}