mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 23:16:51 +00:00
Feature: Implement funding rates, futures and coin margin (exchange API coverage) (#530)
* ALMOST THERE * more api wips * more api thingz * testing n more api wipz * more apiz * more wips * what is goin on * more wips * whip n testing * testing * testing no keys * remove log * kraken is broken ugh * still broken * fixing auth funcs + usdtm api docs * wip * api stuffs * whip * more wips * whip * more wip * api wip n testing * wip * wip * unsaved * wip n testing * wip * wip * wip * wip * wip * wip * wip * wip * wip * whip * wrapper authenticated functions * adding asset type and fixing dependencies * wip * binance auth wrapper start * wrapper functionality * wip * wip * wip * wrapper cancel functions * order submission for wrappers * wip * more error fixing and nits * websocket beginning n error fix * wip * WOW * glorious n shazzy nits * useless nits * wip * fixing things * merge stuffs * crapveyor * crapveyor rebuild * probably broke more things than he fixed * rm lns n other thangs * hope * please * stop it * done * ofcourse * rm vb * fix lbank * appveyor please * float lev * DONT ASK RYAN FOR HELP EVER * wip * wip * endpoint upgrades continued * path upgrade * NeeeNeeeNeeeNeeeNING * fix stuffs * fixing time issue * fixing broken funcs * glorious nits * shaz changes * fixing errors for fundmon * more error fixing for fundmon * test running past 30s * basic changes * THX AGAIN SHAZBERT * path system upgrade * config upgrade * unsaved stuffs * broken wip config upgrade * path system upgrade contd. * path system upgrade contd * path upgrade ready for review * testing verbose removed * linter stuffs * appveyor stuffs * appveyor stuff * fixed? * bugfix * wip * broken stuff * fix test * wierd hack fix * appveyor pls stop * error found * more useless nits * bitmex err * broken wip * broken wip path upgrade change to uint32 * changed url lookups to uint * WOW * ready4review * config fixed HOPEFULLY * config fix and glorious changes * efficient way of getting orders and open orders * binance wrapper logic fixing * testing, adding tests and fixing lot of errrrrs * merge master * appveyor stuffs * appveyor stuffs * fmt * test * octalLiteral issue fix? * octalLiteral fix? * rm vb * prnt ln to restart * adding testz * test fixzzz * READY FOR REVIEW * Actually ready now * FORMATTING * addressing shazzy n glorious nits * crapveyor * rm vb * small change * fixing err * shazbert nits * review changes * requested changes * more requested changes * noo * last nit fixes * restart appveyor * improving test cov * Update .golangci.yml * shazbert changes * moving pair formatting * format pair update wip * path upgrade complete * error fix * appveyor linters * more linters * remove testexch * more formatting changes * changes * shazbert changes * checking older requested changes to ensure completion * wip * fixing broken code * error fix * all fixed * additional changes * more changes * remove commented code * ftx margin api * appveyor fixes * more appveyor issues + test addition * more appveyor issues + test addition * remove unnecessary * testing * testing, fixing okex api, error fix * git merge fix * go sum * glorious changes and error fix * rm vb * more glorious changes and go mod tidy * fixed now * okex testing upgrade * old config migration and batch fetching fix * added test * glorious requested changes WIP * tested and fixed * go fmted * go fmt and test fix * additional funcs and tests for fundingRates * OKEX tested and fixed * appveyor fixes * ineff assign * 1 glorious change * error fix * typo * shazbert changes * glorious code changes and path fixing huobi WIP * adding assetType to accountinfo functions * fixing panic * panic fix and updating account info wrappers WIP * updateaccountinfo updated * testing WIP binance USDT n Coin Margined and Kraken Futures * auth functions tested and fixed * added test * config reverted * shazbert and glorious changes * shazbert and glorious changes * latest changes and portfolio update * go fmt change: * remove commented codes * improved error checking * index out of range fix * rm ln * critical nit * glorious latest changes * appveyor changes * shazbert change * easier readability * latest glorious changes * shadow dec * assetstore updated * last change * another last change * merge changes * go mod tidy * thrasher requested changes wip * improving struct layouts * appveyor go fmt * remove unnecessary code * shazbert changes * small change * oopsie * tidy * configtest reverted * error fix * oopsie * for what * test patch fix * insecurities * fixing tests * fix config
This commit is contained in:
@@ -4,8 +4,10 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -33,7 +35,7 @@ const (
|
||||
bitmexEndpointTrollbox = "/chat"
|
||||
bitmexEndpointTrollboxChannels = "/chat/channels"
|
||||
bitmexEndpointTrollboxConnected = "/chat/connected"
|
||||
bitmexEndpointFundingHistory = "/funding"
|
||||
bitmexEndpointFundingHistory = "/funding?"
|
||||
bitmexEndpointInstruments = "/instrument"
|
||||
bitmexEndpointActiveInstruments = "/instrument/active"
|
||||
bitmexEndpointActiveAndIndexInstruments = "/instrument/activeAndIndices"
|
||||
@@ -106,7 +108,7 @@ const (
|
||||
func (b *Bitmex) GetAnnouncement() ([]Announcement, error) {
|
||||
var announcement []Announcement
|
||||
|
||||
return announcement, b.SendHTTPRequest(bitmexEndpointAnnouncement,
|
||||
return announcement, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointAnnouncement,
|
||||
nil,
|
||||
&announcement)
|
||||
}
|
||||
@@ -115,7 +117,7 @@ func (b *Bitmex) GetAnnouncement() ([]Announcement, error) {
|
||||
func (b *Bitmex) GetUrgentAnnouncement() ([]Announcement, error) {
|
||||
var announcement []Announcement
|
||||
|
||||
return announcement, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return announcement, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointAnnouncementUrgent,
|
||||
nil,
|
||||
&announcement)
|
||||
@@ -125,7 +127,7 @@ func (b *Bitmex) GetUrgentAnnouncement() ([]Announcement, error) {
|
||||
func (b *Bitmex) GetAPIKeys() ([]APIKey, error) {
|
||||
var keys []APIKey
|
||||
|
||||
return keys, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return keys, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointAPIkeys,
|
||||
nil,
|
||||
&keys)
|
||||
@@ -135,7 +137,7 @@ func (b *Bitmex) GetAPIKeys() ([]APIKey, error) {
|
||||
func (b *Bitmex) RemoveAPIKey(params APIKeyParams) (bool, error) {
|
||||
var keyDeleted bool
|
||||
|
||||
return keyDeleted, b.SendAuthenticatedHTTPRequest(http.MethodDelete,
|
||||
return keyDeleted, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodDelete,
|
||||
bitmexEndpointAPIkeys,
|
||||
¶ms,
|
||||
&keyDeleted)
|
||||
@@ -145,7 +147,7 @@ func (b *Bitmex) RemoveAPIKey(params APIKeyParams) (bool, error) {
|
||||
func (b *Bitmex) DisableAPIKey(params APIKeyParams) (APIKey, error) {
|
||||
var keyInfo APIKey
|
||||
|
||||
return keyInfo, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return keyInfo, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointDisableAPIkey,
|
||||
¶ms,
|
||||
&keyInfo)
|
||||
@@ -155,7 +157,7 @@ func (b *Bitmex) DisableAPIKey(params APIKeyParams) (APIKey, error) {
|
||||
func (b *Bitmex) EnableAPIKey(params APIKeyParams) (APIKey, error) {
|
||||
var keyInfo APIKey
|
||||
|
||||
return keyInfo, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return keyInfo, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointEnableAPIkey,
|
||||
¶ms,
|
||||
&keyInfo)
|
||||
@@ -165,14 +167,14 @@ func (b *Bitmex) EnableAPIKey(params APIKeyParams) (APIKey, error) {
|
||||
func (b *Bitmex) GetTrollboxMessages(params ChatGetParams) ([]Chat, error) {
|
||||
var messages []Chat
|
||||
|
||||
return messages, b.SendHTTPRequest(bitmexEndpointTrollbox, ¶ms, &messages)
|
||||
return messages, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointTrollbox, ¶ms, &messages)
|
||||
}
|
||||
|
||||
// SendTrollboxMessage sends a message to the bitmex trollbox
|
||||
func (b *Bitmex) SendTrollboxMessage(params ChatSendParams) ([]Chat, error) {
|
||||
var messages []Chat
|
||||
|
||||
return messages, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return messages, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointTrollboxSend,
|
||||
¶ms,
|
||||
&messages)
|
||||
@@ -182,7 +184,7 @@ func (b *Bitmex) SendTrollboxMessage(params ChatSendParams) ([]Chat, error) {
|
||||
func (b *Bitmex) GetTrollboxChannels() ([]ChatChannel, error) {
|
||||
var channels []ChatChannel
|
||||
|
||||
return channels, b.SendHTTPRequest(bitmexEndpointTrollboxChannels,
|
||||
return channels, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointTrollboxChannels,
|
||||
nil,
|
||||
&channels)
|
||||
}
|
||||
@@ -191,7 +193,7 @@ func (b *Bitmex) GetTrollboxChannels() ([]ChatChannel, error) {
|
||||
func (b *Bitmex) GetTrollboxConnectedUsers() (ConnectedUsers, error) {
|
||||
var users ConnectedUsers
|
||||
|
||||
return users, b.SendHTTPRequest(bitmexEndpointTrollboxConnected, nil, &users)
|
||||
return users, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointTrollboxConnected, nil, &users)
|
||||
}
|
||||
|
||||
// GetAccountExecutions returns all raw transactions, which includes order
|
||||
@@ -200,7 +202,7 @@ func (b *Bitmex) GetTrollboxConnectedUsers() (ConnectedUsers, error) {
|
||||
func (b *Bitmex) GetAccountExecutions(params *GenericRequestParams) ([]Execution, error) {
|
||||
var executionList []Execution
|
||||
|
||||
return executionList, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return executionList, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointExecution,
|
||||
params,
|
||||
&executionList)
|
||||
@@ -211,17 +213,33 @@ func (b *Bitmex) GetAccountExecutions(params *GenericRequestParams) ([]Execution
|
||||
func (b *Bitmex) GetAccountExecutionTradeHistory(params *GenericRequestParams) ([]Execution, error) {
|
||||
var tradeHistory []Execution
|
||||
|
||||
return tradeHistory, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return tradeHistory, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointExecutionTradeHistory,
|
||||
params,
|
||||
&tradeHistory)
|
||||
}
|
||||
|
||||
// GetFullFundingHistory returns funding history
|
||||
func (b *Bitmex) GetFullFundingHistory() ([]Funding, error) {
|
||||
func (b *Bitmex) GetFullFundingHistory(symbol, count, filter, columns, start string, reverse bool, startTime, endTime time.Time) ([]Funding, error) {
|
||||
var fundingHistory []Funding
|
||||
|
||||
return fundingHistory, b.SendHTTPRequest(bitmexEndpointFundingHistory,
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
params.Set("count", count)
|
||||
params.Set("filter", filter)
|
||||
params.Set("columns", columns)
|
||||
params.Set("start", start)
|
||||
params.Set("reverse", "true")
|
||||
if !reverse {
|
||||
params.Set("reverse", "false")
|
||||
}
|
||||
if !startTime.IsZero() && !endTime.IsZero() {
|
||||
if startTime.After(endTime) {
|
||||
return nil, errors.New("startTime cannot be after endTime")
|
||||
}
|
||||
params.Set("startTime", startTime.Format(time.RFC3339))
|
||||
params.Set("endTime", endTime.Format(time.RFC3339))
|
||||
}
|
||||
return fundingHistory, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointFundingHistory+params.Encode(),
|
||||
nil,
|
||||
&fundingHistory)
|
||||
}
|
||||
@@ -230,7 +248,7 @@ func (b *Bitmex) GetFullFundingHistory() ([]Funding, error) {
|
||||
func (b *Bitmex) GetInstruments(params *GenericRequestParams) ([]Instrument, error) {
|
||||
var instruments []Instrument
|
||||
|
||||
return instruments, b.SendHTTPRequest(bitmexEndpointInstruments,
|
||||
return instruments, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointInstruments,
|
||||
params,
|
||||
&instruments)
|
||||
}
|
||||
@@ -239,7 +257,7 @@ func (b *Bitmex) GetInstruments(params *GenericRequestParams) ([]Instrument, err
|
||||
func (b *Bitmex) GetActiveInstruments(params *GenericRequestParams) ([]Instrument, error) {
|
||||
var activeInstruments []Instrument
|
||||
|
||||
return activeInstruments, b.SendHTTPRequest(bitmexEndpointActiveInstruments,
|
||||
return activeInstruments, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointActiveInstruments,
|
||||
params,
|
||||
&activeInstruments)
|
||||
}
|
||||
@@ -249,7 +267,7 @@ func (b *Bitmex) GetActiveAndIndexInstruments() ([]Instrument, error) {
|
||||
var activeAndIndices []Instrument
|
||||
|
||||
return activeAndIndices,
|
||||
b.SendHTTPRequest(bitmexEndpointActiveAndIndexInstruments,
|
||||
b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointActiveAndIndexInstruments,
|
||||
nil,
|
||||
&activeAndIndices)
|
||||
}
|
||||
@@ -258,17 +276,40 @@ func (b *Bitmex) GetActiveAndIndexInstruments() ([]Instrument, error) {
|
||||
func (b *Bitmex) GetActiveIntervals() (InstrumentInterval, error) {
|
||||
var interval InstrumentInterval
|
||||
|
||||
return interval, b.SendHTTPRequest(bitmexEndpointActiveIntervals,
|
||||
return interval, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointActiveIntervals,
|
||||
nil,
|
||||
&interval)
|
||||
}
|
||||
|
||||
// GetCompositeIndex returns composite index
|
||||
func (b *Bitmex) GetCompositeIndex(params *GenericRequestParams) ([]IndexComposite, error) {
|
||||
func (b *Bitmex) GetCompositeIndex(symbol, count, filter, columns, start, reverse string, startTime, endTime time.Time) ([]IndexComposite, error) {
|
||||
var compositeIndices []IndexComposite
|
||||
|
||||
return compositeIndices, b.SendHTTPRequest(bitmexEndpointCompositeIndex,
|
||||
params,
|
||||
params := url.Values{}
|
||||
params.Set("symbol", symbol)
|
||||
if count != "" {
|
||||
params.Set("count", count)
|
||||
}
|
||||
if filter != "" {
|
||||
params.Set("filter", filter)
|
||||
}
|
||||
if columns != "" {
|
||||
params.Set("columns", columns)
|
||||
}
|
||||
if start != "" {
|
||||
params.Set("start", start)
|
||||
}
|
||||
if reverse != "" {
|
||||
params.Set("reverse", "true")
|
||||
}
|
||||
if !startTime.IsZero() && !endTime.IsZero() {
|
||||
if startTime.After(endTime) {
|
||||
return nil, errors.New("startTime cannot be after endTime")
|
||||
}
|
||||
params.Set("startTime", startTime.Format(time.RFC3339))
|
||||
params.Set("endTime", endTime.Format(time.RFC3339))
|
||||
}
|
||||
return compositeIndices, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointCompositeIndex+"?"+params.Encode(),
|
||||
nil,
|
||||
&compositeIndices)
|
||||
}
|
||||
|
||||
@@ -276,35 +317,35 @@ func (b *Bitmex) GetCompositeIndex(params *GenericRequestParams) ([]IndexComposi
|
||||
func (b *Bitmex) GetIndices() ([]Instrument, error) {
|
||||
var indices []Instrument
|
||||
|
||||
return indices, b.SendHTTPRequest(bitmexEndpointIndices, nil, &indices)
|
||||
return indices, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointIndices, nil, &indices)
|
||||
}
|
||||
|
||||
// GetInsuranceFundHistory returns insurance fund history
|
||||
func (b *Bitmex) GetInsuranceFundHistory(params *GenericRequestParams) ([]Insurance, error) {
|
||||
var history []Insurance
|
||||
|
||||
return history, b.SendHTTPRequest(bitmexEndpointIndices, params, &history)
|
||||
return history, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointIndices, params, &history)
|
||||
}
|
||||
|
||||
// GetLeaderboard returns leaderboard information
|
||||
func (b *Bitmex) GetLeaderboard(params LeaderboardGetParams) ([]Leaderboard, error) {
|
||||
var leader []Leaderboard
|
||||
|
||||
return leader, b.SendHTTPRequest(bitmexEndpointLeader, params, &leader)
|
||||
return leader, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointLeader, params, &leader)
|
||||
}
|
||||
|
||||
// GetAliasOnLeaderboard returns your alias on the leaderboard
|
||||
func (b *Bitmex) GetAliasOnLeaderboard() (Alias, error) {
|
||||
var alias Alias
|
||||
|
||||
return alias, b.SendHTTPRequest(bitmexEndpointAlias, nil, &alias)
|
||||
return alias, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointAlias, nil, &alias)
|
||||
}
|
||||
|
||||
// GetLiquidationOrders returns liquidation orders
|
||||
func (b *Bitmex) GetLiquidationOrders(params *GenericRequestParams) ([]Liquidation, error) {
|
||||
var orders []Liquidation
|
||||
|
||||
return orders, b.SendHTTPRequest(bitmexEndpointLiquidation,
|
||||
return orders, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointLiquidation,
|
||||
params,
|
||||
&orders)
|
||||
}
|
||||
@@ -313,7 +354,7 @@ func (b *Bitmex) GetLiquidationOrders(params *GenericRequestParams) ([]Liquidati
|
||||
func (b *Bitmex) GetCurrentNotifications() ([]Notification, error) {
|
||||
var notifications []Notification
|
||||
|
||||
return notifications, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return notifications, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointNotifications,
|
||||
nil,
|
||||
¬ifications)
|
||||
@@ -322,7 +363,7 @@ func (b *Bitmex) GetCurrentNotifications() ([]Notification, error) {
|
||||
// GetOrders returns all the orders, open and closed
|
||||
func (b *Bitmex) GetOrders(params *OrdersRequest) ([]Order, error) {
|
||||
var orders []Order
|
||||
return orders, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return orders, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointOrder,
|
||||
params,
|
||||
&orders)
|
||||
@@ -332,7 +373,7 @@ func (b *Bitmex) GetOrders(params *OrdersRequest) ([]Order, error) {
|
||||
func (b *Bitmex) AmendOrder(params *OrderAmendParams) (Order, error) {
|
||||
var order Order
|
||||
|
||||
return order, b.SendAuthenticatedHTTPRequest(http.MethodPut,
|
||||
return order, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPut,
|
||||
bitmexEndpointOrder,
|
||||
params,
|
||||
&order)
|
||||
@@ -342,7 +383,7 @@ func (b *Bitmex) AmendOrder(params *OrderAmendParams) (Order, error) {
|
||||
func (b *Bitmex) CreateOrder(params *OrderNewParams) (Order, error) {
|
||||
var orderInfo Order
|
||||
|
||||
return orderInfo, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return orderInfo, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointOrder,
|
||||
params,
|
||||
&orderInfo)
|
||||
@@ -353,7 +394,7 @@ func (b *Bitmex) CreateOrder(params *OrderNewParams) (Order, error) {
|
||||
func (b *Bitmex) CancelOrders(params *OrderCancelParams) ([]Order, error) {
|
||||
var cancelledOrders []Order
|
||||
|
||||
return cancelledOrders, b.SendAuthenticatedHTTPRequest(http.MethodDelete,
|
||||
return cancelledOrders, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodDelete,
|
||||
bitmexEndpointOrder,
|
||||
params,
|
||||
&cancelledOrders)
|
||||
@@ -363,7 +404,7 @@ func (b *Bitmex) CancelOrders(params *OrderCancelParams) ([]Order, error) {
|
||||
func (b *Bitmex) CancelAllExistingOrders(params OrderCancelAllParams) ([]Order, error) {
|
||||
var cancelledOrders []Order
|
||||
|
||||
return cancelledOrders, b.SendAuthenticatedHTTPRequest(http.MethodDelete,
|
||||
return cancelledOrders, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodDelete,
|
||||
bitmexEndpointCancelAllOrders,
|
||||
params,
|
||||
&cancelledOrders)
|
||||
@@ -373,7 +414,7 @@ func (b *Bitmex) CancelAllExistingOrders(params OrderCancelAllParams) ([]Order,
|
||||
func (b *Bitmex) AmendBulkOrders(params OrderAmendBulkParams) ([]Order, error) {
|
||||
var amendedOrders []Order
|
||||
|
||||
return amendedOrders, b.SendAuthenticatedHTTPRequest(http.MethodPut,
|
||||
return amendedOrders, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPut,
|
||||
bitmexEndpointBulk,
|
||||
params,
|
||||
&amendedOrders)
|
||||
@@ -383,7 +424,7 @@ func (b *Bitmex) AmendBulkOrders(params OrderAmendBulkParams) ([]Order, error) {
|
||||
func (b *Bitmex) CreateBulkOrders(params OrderNewBulkParams) ([]Order, error) {
|
||||
var orders []Order
|
||||
|
||||
return orders, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return orders, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointBulk,
|
||||
params,
|
||||
&orders)
|
||||
@@ -393,7 +434,7 @@ func (b *Bitmex) CreateBulkOrders(params OrderNewBulkParams) ([]Order, error) {
|
||||
func (b *Bitmex) CancelAllOrdersAfterTime(params OrderCancelAllAfterParams) ([]Order, error) {
|
||||
var cancelledOrder []Order
|
||||
|
||||
return cancelledOrder, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return cancelledOrder, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointCancelOrderAfter,
|
||||
params,
|
||||
&cancelledOrder)
|
||||
@@ -403,7 +444,7 @@ func (b *Bitmex) CancelAllOrdersAfterTime(params OrderCancelAllAfterParams) ([]O
|
||||
func (b *Bitmex) ClosePosition(params OrderClosePositionParams) ([]Order, error) {
|
||||
var closedPositions []Order
|
||||
|
||||
return closedPositions, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return closedPositions, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointOrder,
|
||||
params,
|
||||
&closedPositions)
|
||||
@@ -413,7 +454,7 @@ func (b *Bitmex) ClosePosition(params OrderClosePositionParams) ([]Order, error)
|
||||
func (b *Bitmex) GetOrderbook(params OrderBookGetL2Params) ([]OrderBookL2, error) {
|
||||
var orderBooks []OrderBookL2
|
||||
|
||||
return orderBooks, b.SendHTTPRequest(bitmexEndpointOrderbookL2,
|
||||
return orderBooks, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointOrderbookL2,
|
||||
params,
|
||||
&orderBooks)
|
||||
}
|
||||
@@ -422,7 +463,7 @@ func (b *Bitmex) GetOrderbook(params OrderBookGetL2Params) ([]OrderBookL2, error
|
||||
func (b *Bitmex) GetPositions(params PositionGetParams) ([]Position, error) {
|
||||
var positions []Position
|
||||
|
||||
return positions, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return positions, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointPosition,
|
||||
params,
|
||||
&positions)
|
||||
@@ -432,7 +473,7 @@ func (b *Bitmex) GetPositions(params PositionGetParams) ([]Position, error) {
|
||||
func (b *Bitmex) IsolatePosition(params PositionIsolateMarginParams) (Position, error) {
|
||||
var position Position
|
||||
|
||||
return position, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return position, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointIsolatePosition,
|
||||
params,
|
||||
&position)
|
||||
@@ -442,7 +483,7 @@ func (b *Bitmex) IsolatePosition(params PositionIsolateMarginParams) (Position,
|
||||
func (b *Bitmex) LeveragePosition(params PositionUpdateLeverageParams) (Position, error) {
|
||||
var position Position
|
||||
|
||||
return position, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return position, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointLeveragePosition,
|
||||
params,
|
||||
&position)
|
||||
@@ -452,7 +493,7 @@ func (b *Bitmex) LeveragePosition(params PositionUpdateLeverageParams) (Position
|
||||
func (b *Bitmex) UpdateRiskLimit(params PositionUpdateRiskLimitParams) (Position, error) {
|
||||
var position Position
|
||||
|
||||
return position, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return position, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointAdjustRiskLimit,
|
||||
params,
|
||||
&position)
|
||||
@@ -462,7 +503,7 @@ func (b *Bitmex) UpdateRiskLimit(params PositionUpdateRiskLimitParams) (Position
|
||||
func (b *Bitmex) TransferMargin(params PositionTransferIsolatedMarginParams) (Position, error) {
|
||||
var position Position
|
||||
|
||||
return position, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return position, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointTransferMargin,
|
||||
params,
|
||||
&position)
|
||||
@@ -472,7 +513,7 @@ func (b *Bitmex) TransferMargin(params PositionTransferIsolatedMarginParams) (Po
|
||||
func (b *Bitmex) GetQuotes(params *GenericRequestParams) ([]Quote, error) {
|
||||
var quotations []Quote
|
||||
|
||||
return quotations, b.SendHTTPRequest(bitmexEndpointQuote,
|
||||
return quotations, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointQuote,
|
||||
params,
|
||||
"ations)
|
||||
}
|
||||
@@ -481,7 +522,7 @@ func (b *Bitmex) GetQuotes(params *GenericRequestParams) ([]Quote, error) {
|
||||
func (b *Bitmex) GetQuotesByBuckets(params *QuoteGetBucketedParams) ([]Quote, error) {
|
||||
var quotations []Quote
|
||||
|
||||
return quotations, b.SendHTTPRequest(bitmexEndpointQuoteBucketed,
|
||||
return quotations, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointQuoteBucketed,
|
||||
params,
|
||||
"ations)
|
||||
}
|
||||
@@ -490,7 +531,7 @@ func (b *Bitmex) GetQuotesByBuckets(params *QuoteGetBucketedParams) ([]Quote, er
|
||||
func (b *Bitmex) GetSettlementHistory(params *GenericRequestParams) ([]Settlement, error) {
|
||||
var history []Settlement
|
||||
|
||||
return history, b.SendHTTPRequest(bitmexEndpointSettlement,
|
||||
return history, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointSettlement,
|
||||
params,
|
||||
&history)
|
||||
}
|
||||
@@ -499,35 +540,35 @@ func (b *Bitmex) GetSettlementHistory(params *GenericRequestParams) ([]Settlemen
|
||||
func (b *Bitmex) GetStats() ([]Stats, error) {
|
||||
var stats []Stats
|
||||
|
||||
return stats, b.SendHTTPRequest(bitmexEndpointStats, nil, &stats)
|
||||
return stats, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointStats, nil, &stats)
|
||||
}
|
||||
|
||||
// GetStatsHistorical historic stats
|
||||
func (b *Bitmex) GetStatsHistorical() ([]StatsHistory, error) {
|
||||
var history []StatsHistory
|
||||
|
||||
return history, b.SendHTTPRequest(bitmexEndpointStatsHistory, nil, &history)
|
||||
return history, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointStatsHistory, nil, &history)
|
||||
}
|
||||
|
||||
// GetStatSummary returns the stats summary in USD terms
|
||||
func (b *Bitmex) GetStatSummary() ([]StatsUSD, error) {
|
||||
var summary []StatsUSD
|
||||
|
||||
return summary, b.SendHTTPRequest(bitmexEndpointStatsSummary, nil, &summary)
|
||||
return summary, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointStatsSummary, nil, &summary)
|
||||
}
|
||||
|
||||
// GetTrade returns executed trades on the desk
|
||||
func (b *Bitmex) GetTrade(params *GenericRequestParams) ([]Trade, error) {
|
||||
var trade []Trade
|
||||
|
||||
return trade, b.SendHTTPRequest(bitmexEndpointTrade, params, &trade)
|
||||
return trade, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointTrade, params, &trade)
|
||||
}
|
||||
|
||||
// GetPreviousTrades previous trade history in time buckets
|
||||
func (b *Bitmex) GetPreviousTrades(params *TradeGetBucketedParams) ([]Trade, error) {
|
||||
var trade []Trade
|
||||
|
||||
return trade, b.SendHTTPRequest(bitmexEndpointTradeBucketed,
|
||||
return trade, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointTradeBucketed,
|
||||
params,
|
||||
&trade)
|
||||
}
|
||||
@@ -536,7 +577,7 @@ func (b *Bitmex) GetPreviousTrades(params *TradeGetBucketedParams) ([]Trade, err
|
||||
func (b *Bitmex) GetUserInfo() (User, error) {
|
||||
var userInfo User
|
||||
|
||||
return userInfo, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return userInfo, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUser,
|
||||
nil,
|
||||
&userInfo)
|
||||
@@ -546,7 +587,7 @@ func (b *Bitmex) GetUserInfo() (User, error) {
|
||||
func (b *Bitmex) UpdateUserInfo(params *UserUpdateParams) (User, error) {
|
||||
var userInfo User
|
||||
|
||||
return userInfo, b.SendAuthenticatedHTTPRequest(http.MethodPut,
|
||||
return userInfo, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPut,
|
||||
bitmexEndpointUser,
|
||||
params,
|
||||
&userInfo)
|
||||
@@ -556,7 +597,7 @@ func (b *Bitmex) UpdateUserInfo(params *UserUpdateParams) (User, error) {
|
||||
func (b *Bitmex) GetAffiliateStatus() (AffiliateStatus, error) {
|
||||
var status AffiliateStatus
|
||||
|
||||
return status, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return status, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserAffiliate,
|
||||
nil,
|
||||
&status)
|
||||
@@ -566,7 +607,7 @@ func (b *Bitmex) GetAffiliateStatus() (AffiliateStatus, error) {
|
||||
func (b *Bitmex) CancelWithdraw(token string) (TransactionInfo, error) {
|
||||
var info TransactionInfo
|
||||
|
||||
return info, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return info, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserCancelWithdraw,
|
||||
UserTokenParams{Token: token},
|
||||
&info)
|
||||
@@ -577,7 +618,7 @@ func (b *Bitmex) CancelWithdraw(token string) (TransactionInfo, error) {
|
||||
func (b *Bitmex) CheckReferalCode(referralCode string) (float64, error) {
|
||||
var percentage float64
|
||||
|
||||
return percentage, b.SendHTTPRequest(bitmexEndpointUserCheckReferralCode,
|
||||
return percentage, b.SendHTTPRequest(exchange.RestSpot, bitmexEndpointUserCheckReferralCode,
|
||||
UserCheckReferralCodeParams{ReferralCode: referralCode},
|
||||
&percentage)
|
||||
}
|
||||
@@ -586,7 +627,7 @@ func (b *Bitmex) CheckReferalCode(referralCode string) (float64, error) {
|
||||
func (b *Bitmex) GetUserCommision() (UserCommission, error) {
|
||||
var commissionInfo UserCommission
|
||||
|
||||
return commissionInfo, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return commissionInfo, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserCommision,
|
||||
nil,
|
||||
&commissionInfo)
|
||||
@@ -596,7 +637,7 @@ func (b *Bitmex) GetUserCommision() (UserCommission, error) {
|
||||
func (b *Bitmex) ConfirmEmail(token string) (ConfirmEmail, error) {
|
||||
var confirmation ConfirmEmail
|
||||
|
||||
return confirmation, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return confirmation, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserConfirmEmail,
|
||||
UserTokenParams{Token: token},
|
||||
&confirmation)
|
||||
@@ -606,7 +647,7 @@ func (b *Bitmex) ConfirmEmail(token string) (ConfirmEmail, error) {
|
||||
func (b *Bitmex) ConfirmTwoFactorAuth(token, typ string) (bool, error) {
|
||||
var working bool
|
||||
|
||||
return working, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return working, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserConfirmTFA,
|
||||
UserConfirmTFAParams{Token: token, Type: typ},
|
||||
&working)
|
||||
@@ -616,7 +657,7 @@ func (b *Bitmex) ConfirmTwoFactorAuth(token, typ string) (bool, error) {
|
||||
func (b *Bitmex) ConfirmWithdrawal(token string) (TransactionInfo, error) {
|
||||
var info TransactionInfo
|
||||
|
||||
return info, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return info, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserCancelWithdraw,
|
||||
UserTokenParams{Token: token},
|
||||
&info)
|
||||
@@ -632,7 +673,7 @@ func (b *Bitmex) GetCryptoDepositAddress(cryptoCurrency string) (string, error)
|
||||
cryptoCurrency)
|
||||
}
|
||||
|
||||
return address, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return address, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserDepositAddress,
|
||||
UserCurrencyParams{Currency: "XBt"},
|
||||
&address)
|
||||
@@ -642,7 +683,7 @@ func (b *Bitmex) GetCryptoDepositAddress(cryptoCurrency string) (string, error)
|
||||
func (b *Bitmex) DisableTFA(token, typ string) (bool, error) {
|
||||
var disabled bool
|
||||
|
||||
return disabled, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return disabled, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserDisableTFA,
|
||||
UserConfirmTFAParams{Token: token, Type: typ},
|
||||
&disabled)
|
||||
@@ -650,7 +691,7 @@ func (b *Bitmex) DisableTFA(token, typ string) (bool, error) {
|
||||
|
||||
// UserLogOut logs you out of BitMEX
|
||||
func (b *Bitmex) UserLogOut() error {
|
||||
return b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserLogout,
|
||||
nil,
|
||||
nil)
|
||||
@@ -660,7 +701,7 @@ func (b *Bitmex) UserLogOut() error {
|
||||
func (b *Bitmex) UserLogOutAll() (int64, error) {
|
||||
var status int64
|
||||
|
||||
return status, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return status, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserLogoutAll,
|
||||
nil,
|
||||
&status)
|
||||
@@ -670,7 +711,7 @@ func (b *Bitmex) UserLogOutAll() (int64, error) {
|
||||
func (b *Bitmex) GetUserMargin(currency string) (UserMargin, error) {
|
||||
var info UserMargin
|
||||
|
||||
return info, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return info, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserMargin,
|
||||
UserCurrencyParams{Currency: currency},
|
||||
&info)
|
||||
@@ -680,7 +721,7 @@ func (b *Bitmex) GetUserMargin(currency string) (UserMargin, error) {
|
||||
func (b *Bitmex) GetAllUserMargin() ([]UserMargin, error) {
|
||||
var info []UserMargin
|
||||
|
||||
return info, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return info, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserMargin,
|
||||
UserCurrencyParams{Currency: "all"},
|
||||
&info)
|
||||
@@ -690,7 +731,7 @@ func (b *Bitmex) GetAllUserMargin() ([]UserMargin, error) {
|
||||
func (b *Bitmex) GetMinimumWithdrawalFee(currency string) (MinWithdrawalFee, error) {
|
||||
var fee MinWithdrawalFee
|
||||
|
||||
return fee, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return fee, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserMinWithdrawalFee,
|
||||
UserCurrencyParams{Currency: currency},
|
||||
&fee)
|
||||
@@ -700,7 +741,7 @@ func (b *Bitmex) GetMinimumWithdrawalFee(currency string) (MinWithdrawalFee, err
|
||||
func (b *Bitmex) GetUserPreferences(params UserPreferencesParams) (User, error) {
|
||||
var userInfo User
|
||||
|
||||
return userInfo, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return userInfo, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserPreferences,
|
||||
params,
|
||||
&userInfo)
|
||||
@@ -710,7 +751,7 @@ func (b *Bitmex) GetUserPreferences(params UserPreferencesParams) (User, error)
|
||||
func (b *Bitmex) EnableTFA(typ string) (bool, error) {
|
||||
var enabled bool
|
||||
|
||||
return enabled, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return enabled, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserRequestTFA,
|
||||
UserConfirmTFAParams{Type: typ},
|
||||
&enabled)
|
||||
@@ -722,7 +763,7 @@ func (b *Bitmex) EnableTFA(typ string) (bool, error) {
|
||||
func (b *Bitmex) UserRequestWithdrawal(params UserRequestWithdrawalParams) (TransactionInfo, error) {
|
||||
var info TransactionInfo
|
||||
|
||||
return info, b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
return info, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
|
||||
bitmexEndpointUserRequestWithdraw,
|
||||
params,
|
||||
&info)
|
||||
@@ -732,7 +773,7 @@ func (b *Bitmex) UserRequestWithdrawal(params UserRequestWithdrawalParams) (Tran
|
||||
func (b *Bitmex) GetWalletInfo(currency string) (WalletInfo, error) {
|
||||
var info WalletInfo
|
||||
|
||||
return info, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return info, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserWallet,
|
||||
UserCurrencyParams{Currency: currency},
|
||||
&info)
|
||||
@@ -742,7 +783,7 @@ func (b *Bitmex) GetWalletInfo(currency string) (WalletInfo, error) {
|
||||
func (b *Bitmex) GetWalletHistory(currency string) ([]TransactionInfo, error) {
|
||||
var info []TransactionInfo
|
||||
|
||||
return info, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return info, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserWalletHistory,
|
||||
UserCurrencyParams{Currency: currency},
|
||||
&info)
|
||||
@@ -752,19 +793,24 @@ func (b *Bitmex) GetWalletHistory(currency string) ([]TransactionInfo, error) {
|
||||
func (b *Bitmex) GetWalletSummary(currency string) ([]TransactionInfo, error) {
|
||||
var info []TransactionInfo
|
||||
|
||||
return info, b.SendAuthenticatedHTTPRequest(http.MethodGet,
|
||||
return info, b.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
|
||||
bitmexEndpointUserWalletSummary,
|
||||
UserCurrencyParams{Currency: currency},
|
||||
&info)
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (b *Bitmex) SendHTTPRequest(path string, params Parameter, result interface{}) error {
|
||||
func (b *Bitmex) SendHTTPRequest(ep exchange.URL, path string, params Parameter, result interface{}) error {
|
||||
var respCheck interface{}
|
||||
path = b.API.Endpoints.URL + path
|
||||
endpoint, err := b.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path = endpoint + path
|
||||
if params != nil {
|
||||
var encodedPath string
|
||||
if !params.IsNil() {
|
||||
encodedPath, err := params.ToURLVals(path)
|
||||
encodedPath, err = params.ToURLVals(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -782,7 +828,8 @@ func (b *Bitmex) SendHTTPRequest(path string, params Parameter, result interface
|
||||
return b.CaptureError(respCheck, result)
|
||||
}
|
||||
}
|
||||
err := b.SendPayload(context.Background(), &request.Item{
|
||||
|
||||
err = b.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
Result: &respCheck,
|
||||
@@ -793,16 +840,20 @@ func (b *Bitmex) SendHTTPRequest(path string, params Parameter, result interface
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.CaptureError(respCheck, result)
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request to bitmex
|
||||
func (b *Bitmex) SendAuthenticatedHTTPRequest(verb, path string, params Parameter, result interface{}) error {
|
||||
func (b *Bitmex) SendAuthenticatedHTTPRequest(ep exchange.URL, verb, path string, params Parameter, result interface{}) error {
|
||||
if !b.AllowAuthenticatedRequest() {
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet,
|
||||
b.Name)
|
||||
}
|
||||
|
||||
endpoint, err := b.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
expires := time.Now().Add(time.Second * 10)
|
||||
timestamp := expires.UnixNano()
|
||||
timestampStr := strconv.FormatInt(timestamp, 10)
|
||||
@@ -815,11 +866,12 @@ func (b *Bitmex) SendAuthenticatedHTTPRequest(verb, path string, params Paramete
|
||||
|
||||
var payload string
|
||||
if params != nil {
|
||||
err := params.VerifyData()
|
||||
err = params.VerifyData()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := json.Marshal(params)
|
||||
var data []byte
|
||||
data, err = json.Marshal(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -836,9 +888,9 @@ func (b *Bitmex) SendAuthenticatedHTTPRequest(verb, path string, params Paramete
|
||||
|
||||
ctx, cancel := context.WithDeadline(context.Background(), expires)
|
||||
defer cancel()
|
||||
err := b.SendPayload(ctx, &request.Item{
|
||||
err = b.SendPayload(ctx, &request.Item{
|
||||
Method: verb,
|
||||
Path: b.API.Endpoints.URL + path,
|
||||
Path: endpoint + path,
|
||||
Headers: headers,
|
||||
Body: bytes.NewBuffer([]byte(payload)),
|
||||
Result: &respCheck,
|
||||
|
||||
@@ -56,12 +56,32 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
t.Parallel()
|
||||
var testWg sync.WaitGroup
|
||||
b.Start(&testWg)
|
||||
testWg.Wait()
|
||||
}
|
||||
|
||||
func TestGetFullFundingHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetFullFundingHistory("", "", "", "", "", true, time.Time{}, time.Time{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = b.GetFullFundingHistory("", "", "", "", "", true, time.Now().Add(-time.Hour*8), time.Now())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = b.GetFullFundingHistory("LTCUSD", "1", "", "", "", true, time.Now().Add(time.Hour*-24), time.Now())
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetUrgentAnnouncement(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetUrgentAnnouncement()
|
||||
if err == nil {
|
||||
t.Error("GetUrgentAnnouncement() Expected error")
|
||||
@@ -69,6 +89,7 @@ func TestGetUrgentAnnouncement(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAPIKeys(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetAPIKeys()
|
||||
if err == nil {
|
||||
t.Error("GetAPIKeys() Expected error")
|
||||
@@ -76,6 +97,7 @@ func TestGetAPIKeys(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemoveAPIKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.RemoveAPIKey(APIKeyParams{APIKeyID: "1337"})
|
||||
if err == nil {
|
||||
t.Error("RemoveAPIKey() Expected error")
|
||||
@@ -83,6 +105,7 @@ func TestRemoveAPIKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDisableAPIKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.DisableAPIKey(APIKeyParams{APIKeyID: "1337"})
|
||||
if err == nil {
|
||||
t.Error("DisableAPIKey() Expected error")
|
||||
@@ -90,6 +113,7 @@ func TestDisableAPIKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnableAPIKey(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.EnableAPIKey(APIKeyParams{APIKeyID: "1337"})
|
||||
if err == nil {
|
||||
t.Error("EnableAPIKey() Expected error")
|
||||
@@ -97,6 +121,7 @@ func TestEnableAPIKey(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTrollboxMessages(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTrollboxMessages(ChatGetParams{Count: 5})
|
||||
if err != nil {
|
||||
t.Error("GetTrollboxMessages() error", err)
|
||||
@@ -104,6 +129,7 @@ func TestGetTrollboxMessages(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSendTrollboxMessage(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.SendTrollboxMessage(ChatSendParams{
|
||||
ChannelID: 1337,
|
||||
Message: "Hello,World!"})
|
||||
@@ -113,6 +139,7 @@ func TestSendTrollboxMessage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTrollboxChannels(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTrollboxChannels()
|
||||
if err != nil {
|
||||
t.Error("GetTrollboxChannels() error", err)
|
||||
@@ -120,6 +147,7 @@ func TestGetTrollboxChannels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTrollboxConnectedUsers(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTrollboxConnectedUsers()
|
||||
if err == nil {
|
||||
t.Error("GetTrollboxConnectedUsers() Expected error")
|
||||
@@ -127,6 +155,7 @@ func TestGetTrollboxConnectedUsers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAccountExecutions(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetAccountExecutions(&GenericRequestParams{})
|
||||
if err == nil {
|
||||
t.Error("GetAccountExecutions() Expected error")
|
||||
@@ -134,6 +163,7 @@ func TestGetAccountExecutions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAccountExecutionTradeHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetAccountExecutionTradeHistory(&GenericRequestParams{})
|
||||
if err == nil {
|
||||
t.Error("GetAccountExecutionTradeHistory() Expected error")
|
||||
@@ -141,6 +171,7 @@ func TestGetAccountExecutionTradeHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFundingHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetFundingHistory()
|
||||
if err == nil {
|
||||
t.Error("GetFundingHistory() Expected error")
|
||||
@@ -148,6 +179,7 @@ func TestGetFundingHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetInstruments(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetInstruments(&GenericRequestParams{})
|
||||
if err != nil {
|
||||
t.Error("GetInstruments() error", err)
|
||||
@@ -155,6 +187,7 @@ func TestGetInstruments(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetActiveInstruments(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetActiveInstruments(&GenericRequestParams{})
|
||||
if err != nil {
|
||||
t.Error("GetActiveInstruments() error", err)
|
||||
@@ -162,6 +195,7 @@ func TestGetActiveInstruments(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetActiveAndIndexInstruments(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetActiveAndIndexInstruments()
|
||||
if err != nil {
|
||||
t.Error("GetActiveAndIndexInstruments() error", err)
|
||||
@@ -169,6 +203,7 @@ func TestGetActiveAndIndexInstruments(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetActiveIntervals(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetActiveIntervals()
|
||||
if err == nil {
|
||||
t.Error("GetActiveIntervals() Expected error")
|
||||
@@ -176,13 +211,15 @@ func TestGetActiveIntervals(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCompositeIndex(t *testing.T) {
|
||||
_, err := b.GetCompositeIndex(&GenericRequestParams{})
|
||||
if err == nil {
|
||||
t.Error("GetCompositeIndex() Expected error")
|
||||
t.Parallel()
|
||||
_, err := b.GetCompositeIndex(".XBT", "", "", "", "", "", time.Time{}, time.Time{})
|
||||
if err != nil {
|
||||
t.Error("GetCompositeIndex() Expected error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIndices(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetIndices()
|
||||
if err != nil {
|
||||
t.Error("GetIndices() error", err)
|
||||
@@ -190,6 +227,7 @@ func TestGetIndices(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetInsuranceFundHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetInsuranceFundHistory(&GenericRequestParams{})
|
||||
if err != nil {
|
||||
t.Error("GetInsuranceFundHistory() error", err)
|
||||
@@ -197,6 +235,7 @@ func TestGetInsuranceFundHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLeaderboard(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetLeaderboard(LeaderboardGetParams{})
|
||||
if err != nil {
|
||||
t.Error("GetLeaderboard() error", err)
|
||||
@@ -204,6 +243,7 @@ func TestGetLeaderboard(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAliasOnLeaderboard(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetAliasOnLeaderboard()
|
||||
if err == nil {
|
||||
t.Error("GetAliasOnLeaderboard() Expected error")
|
||||
@@ -211,6 +251,7 @@ func TestGetAliasOnLeaderboard(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLiquidationOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetLiquidationOrders(&GenericRequestParams{})
|
||||
if err != nil {
|
||||
t.Error("GetLiquidationOrders() error", err)
|
||||
@@ -218,6 +259,7 @@ func TestGetLiquidationOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetCurrentNotifications(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetCurrentNotifications()
|
||||
if err == nil {
|
||||
t.Error("GetCurrentNotifications() Expected error")
|
||||
@@ -225,6 +267,7 @@ func TestGetCurrentNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAmendOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.AmendOrder(&OrderAmendParams{})
|
||||
if err == nil {
|
||||
t.Error("AmendOrder() Expected error")
|
||||
@@ -232,6 +275,7 @@ func TestAmendOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.CreateOrder(&OrderNewParams{Symbol: "XBTM15",
|
||||
Price: 219.0,
|
||||
ClientOrderID: "mm_bitmex_1a/oemUeQ4CAJZgP3fjHsA",
|
||||
@@ -242,6 +286,7 @@ func TestCreateOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.CancelOrders(&OrderCancelParams{})
|
||||
if err == nil {
|
||||
t.Error("CancelOrders() Expected error")
|
||||
@@ -249,6 +294,7 @@ func TestCancelOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelAllOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.CancelAllExistingOrders(OrderCancelAllParams{})
|
||||
if err == nil {
|
||||
t.Error("CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error)", err)
|
||||
@@ -256,6 +302,7 @@ func TestCancelAllOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAmendBulkOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.AmendBulkOrders(OrderAmendBulkParams{})
|
||||
if err == nil {
|
||||
t.Error("AmendBulkOrders() Expected error")
|
||||
@@ -263,6 +310,7 @@ func TestAmendBulkOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateBulkOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.CreateBulkOrders(OrderNewBulkParams{})
|
||||
if err == nil {
|
||||
t.Error("CreateBulkOrders() Expected error")
|
||||
@@ -270,6 +318,7 @@ func TestCreateBulkOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelAllOrdersAfterTime(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.CancelAllOrdersAfterTime(OrderCancelAllAfterParams{})
|
||||
if err == nil {
|
||||
t.Error("CancelAllOrdersAfterTime() Expected error")
|
||||
@@ -277,6 +326,7 @@ func TestCancelAllOrdersAfterTime(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestClosePosition(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.ClosePosition(OrderClosePositionParams{})
|
||||
if err == nil {
|
||||
t.Error("ClosePosition() Expected error")
|
||||
@@ -284,6 +334,7 @@ func TestClosePosition(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetOrderbook(OrderBookGetL2Params{Symbol: "XBT"})
|
||||
if err != nil {
|
||||
t.Error("GetOrderbook() error", err)
|
||||
@@ -291,6 +342,7 @@ func TestGetOrderbook(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetPositions(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetPositions(PositionGetParams{})
|
||||
if err == nil {
|
||||
t.Error("GetPositions() Expected error")
|
||||
@@ -298,6 +350,7 @@ func TestGetPositions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIsolatePosition(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.IsolatePosition(PositionIsolateMarginParams{Symbol: "XBT"})
|
||||
if err == nil {
|
||||
t.Error("IsolatePosition() Expected error")
|
||||
@@ -305,6 +358,7 @@ func TestIsolatePosition(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLeveragePosition(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.LeveragePosition(PositionUpdateLeverageParams{})
|
||||
if err == nil {
|
||||
t.Error("LeveragePosition() Expected error")
|
||||
@@ -312,6 +366,7 @@ func TestLeveragePosition(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateRiskLimit(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.UpdateRiskLimit(PositionUpdateRiskLimitParams{})
|
||||
if err == nil {
|
||||
t.Error("UpdateRiskLimit() Expected error")
|
||||
@@ -319,6 +374,7 @@ func TestUpdateRiskLimit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTransferMargin(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.TransferMargin(PositionTransferIsolatedMarginParams{})
|
||||
if err == nil {
|
||||
t.Error("TransferMargin() Expected error")
|
||||
@@ -326,6 +382,7 @@ func TestTransferMargin(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetQuotesByBuckets(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetQuotesByBuckets(&QuoteGetBucketedParams{})
|
||||
if err == nil {
|
||||
t.Error("GetQuotesByBuckets() Expected error")
|
||||
@@ -333,6 +390,7 @@ func TestGetQuotesByBuckets(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetSettlementHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetSettlementHistory(&GenericRequestParams{})
|
||||
if err != nil {
|
||||
t.Error("GetSettlementHistory() error", err)
|
||||
@@ -340,6 +398,7 @@ func TestGetSettlementHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStats(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetStats()
|
||||
if err != nil {
|
||||
t.Error("GetStats() error", err)
|
||||
@@ -347,6 +406,7 @@ func TestGetStats(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStatsHistorical(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetStatsHistorical()
|
||||
if err != nil {
|
||||
t.Error("GetStatsHistorical() error", err)
|
||||
@@ -354,6 +414,7 @@ func TestGetStatsHistorical(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStatSummary(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetStatSummary()
|
||||
if err != nil {
|
||||
t.Error("GetStatSummary() error", err)
|
||||
@@ -361,6 +422,7 @@ func TestGetStatSummary(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTrade(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetTrade(&GenericRequestParams{
|
||||
Symbol: "XBT",
|
||||
Reverse: false,
|
||||
@@ -372,6 +434,7 @@ func TestGetTrade(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetPreviousTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := b.GetPreviousTrades(&TradeGetBucketedParams{
|
||||
Symbol: "XBTBTC",
|
||||
Start: int32(time.Now().Add(-time.Hour * 24).Unix()),
|
||||
@@ -393,6 +456,7 @@ func setFeeBuilder() *exchange.FeeBuilder {
|
||||
|
||||
// TestGetFeeByTypeOfflineTradeFee logic test
|
||||
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
t.Parallel()
|
||||
var feeBuilder = setFeeBuilder()
|
||||
b.GetFeeByType(feeBuilder)
|
||||
if !areTestAPIKeysSet() {
|
||||
@@ -407,6 +471,7 @@ func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
t.Parallel()
|
||||
var feeBuilder = setFeeBuilder()
|
||||
// CryptocurrencyTradeFee Basic
|
||||
if resp, err := b.GetFee(feeBuilder); resp != float64(0.00075) || err != nil {
|
||||
@@ -475,6 +540,7 @@ func TestGetFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
t.Parallel()
|
||||
expectedResult := exchange.AutoWithdrawCryptoWithAPIPermissionText + " & " + exchange.WithdrawCryptoWith2FAText +
|
||||
" & " + exchange.WithdrawCryptoWithEmailText + " & " + exchange.NoFiatWithdrawalsText
|
||||
withdrawPermissions := b.FormatWithdrawPermissions()
|
||||
@@ -484,8 +550,10 @@ func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetActiveOrders(&getOrdersRequest)
|
||||
@@ -497,10 +565,12 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
Type: order.AnyType,
|
||||
Pairs: []currency.Pair{currency.NewPair(currency.LTC,
|
||||
currency.BTC)},
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
_, err := b.GetOrderHistory(&getOrdersRequest)
|
||||
@@ -518,6 +588,7 @@ func areTestAPIKeysSet() bool {
|
||||
}
|
||||
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -543,6 +614,7 @@ func TestSubmitOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -566,6 +638,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -594,13 +667,14 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := b.UpdateAccountInfo()
|
||||
_, err := b.UpdateAccountInfo(asset.Spot)
|
||||
if err != nil {
|
||||
t.Error("GetAccountInfo() error", err)
|
||||
}
|
||||
} else {
|
||||
_, err := b.UpdateAccountInfo()
|
||||
_, err := b.UpdateAccountInfo(asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetAccountInfo() error")
|
||||
}
|
||||
@@ -608,6 +682,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -618,6 +693,7 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Crypto: withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
@@ -642,6 +718,7 @@ func TestWithdraw(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -654,6 +731,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -666,6 +744,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() {
|
||||
_, err := b.GetDepositAddress(currency.BTC, "")
|
||||
if err != nil {
|
||||
@@ -681,6 +760,7 @@ func TestGetDepositAddress(t *testing.T) {
|
||||
|
||||
// TestWsAuth dials websocket, sends login request.
|
||||
func TestWsAuth(t *testing.T) {
|
||||
t.Parallel()
|
||||
if !b.Websocket.IsEnabled() && !b.API.AuthenticatedWebsocketSupport || !areTestAPIKeysSet() {
|
||||
t.Skip(stream.WebsocketNotEnabled)
|
||||
}
|
||||
@@ -708,6 +788,7 @@ func TestWsAuth(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateTradablePairs(t *testing.T) {
|
||||
t.Parallel()
|
||||
err := b.UpdateTradablePairs(true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -715,6 +796,7 @@ func TestUpdateTradablePairs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWsPositionUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"table":"position",
|
||||
"action":"update",
|
||||
"data":[{
|
||||
@@ -731,6 +813,7 @@ func TestWsPositionUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWsInsertExectuionUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"table":"execution",
|
||||
"action":"insert",
|
||||
"data":[{
|
||||
@@ -754,6 +837,7 @@ func TestWsInsertExectuionUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWSConnectionHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"info":"Welcome to the BitMEX Realtime API.","version":"1.1.0",
|
||||
"timestamp":"2015-01-18T10:14:06.802Z","docs":"https://www.bitmex.com/app/wsAPI","heartbeatEnabled":false}`)
|
||||
err := b.wsHandleData(pressXToJSON)
|
||||
@@ -763,6 +847,7 @@ func TestWSConnectionHandling(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWSSubscriptionHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"success":true,"subscribe":"trade:ETHUSD",
|
||||
"request":{"op":"subscribe","args":["trade:ETHUSD","instrument:ETHUSD"]}}`)
|
||||
err := b.wsHandleData(pressXToJSON)
|
||||
@@ -772,6 +857,7 @@ func TestWSSubscriptionHandling(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWSPositionUpdateHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"table":"position",
|
||||
"action":"update",
|
||||
"data":[{
|
||||
@@ -804,6 +890,7 @@ func TestWSPositionUpdateHandling(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWSOrderbookHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{
|
||||
"table":"orderBookL2_25",
|
||||
"keys":["symbol","id","side"],
|
||||
@@ -877,6 +964,7 @@ func TestWSOrderbookHandling(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWSDeleveragePositionUpdateHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"table":"position",
|
||||
"action":"update",
|
||||
"data":[{
|
||||
@@ -911,6 +999,7 @@ func TestWSDeleveragePositionUpdateHandling(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWSDeleverageExecutionInsertHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"table":"execution",
|
||||
"action":"insert",
|
||||
"data":[{
|
||||
@@ -934,6 +1023,7 @@ func TestWSDeleverageExecutionInsertHandling(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWsTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
pressXToJSON := []byte(`{"table":"trade","action":"insert","data":[{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.3,"tickDirection":"MinusTick","trdMatchID":"c427f7a0-6b26-1e10-5c4e-1bd74daf2a73","grossValue":2583000,"homeNotional":0.9904912836767037,"foreignNotional":255.84389857369254},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.3,"tickDirection":"ZeroMinusTick","trdMatchID":"95eb9155-b58c-70e9-44b7-34efe50302e0","grossValue":2583000,"homeNotional":0.9904912836767037,"foreignNotional":255.84389857369254},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.3,"tickDirection":"ZeroMinusTick","trdMatchID":"e607c187-f25c-86bc-cb39-8afff7aaf2d9","grossValue":2583000,"homeNotional":0.9904912836767037,"foreignNotional":255.84389857369254},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":17,"price":258.3,"tickDirection":"ZeroMinusTick","trdMatchID":"0f076814-a57d-9a59-8063-ad6b823a80ac","grossValue":439110,"homeNotional":0.1683835182250396,"foreignNotional":43.49346275752773},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.25,"tickDirection":"MinusTick","trdMatchID":"f4ef3dfd-51c4-538f-37c1-e5071ba1c75d","grossValue":2582500,"homeNotional":0.9904912836767037,"foreignNotional":255.79437400950872},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.25,"tickDirection":"ZeroMinusTick","trdMatchID":"81ef136b-8f4a-b1cf-78a8-fffbfa89bf40","grossValue":2582500,"homeNotional":0.9904912836767037,"foreignNotional":255.79437400950872},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.25,"tickDirection":"ZeroMinusTick","trdMatchID":"65a87e8c-7563-34a4-d040-94e8513c5401","grossValue":2582500,"homeNotional":0.9904912836767037,"foreignNotional":255.79437400950872},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":15,"price":258.25,"tickDirection":"ZeroMinusTick","trdMatchID":"1d11a74e-a157-3f33-036d-35a101fba50b","grossValue":387375,"homeNotional":0.14857369255150554,"foreignNotional":38.369156101426306},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":1,"price":258.25,"tickDirection":"ZeroMinusTick","trdMatchID":"40d49df1-f018-f66f-4ca5-31d4997641d7","grossValue":25825,"homeNotional":0.009904912836767036,"foreignNotional":2.5579437400950873},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.2,"tickDirection":"MinusTick","trdMatchID":"36135b51-73e5-c007-362b-a55be5830c6b","grossValue":2582000,"homeNotional":0.9904912836767037,"foreignNotional":255.7448494453249},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.2,"tickDirection":"ZeroMinusTick","trdMatchID":"6ee19edb-99aa-3030-ba63-933ffb347ade","grossValue":2582000,"homeNotional":0.9904912836767037,"foreignNotional":255.7448494453249},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":100,"price":258.2,"tickDirection":"ZeroMinusTick","trdMatchID":"d44be603-cdb8-d676-e3e2-f91fb12b2a70","grossValue":2582000,"homeNotional":0.9904912836767037,"foreignNotional":255.7448494453249},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":5,"price":258.2,"tickDirection":"ZeroMinusTick","trdMatchID":"a14b43b3-50b4-c075-c54d-dfb0165de33d","grossValue":129100,"homeNotional":0.04952456418383518,"foreignNotional":12.787242472266245},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":8,"price":258.2,"tickDirection":"ZeroMinusTick","trdMatchID":"3c30e175-5194-320c-8f8c-01636c2f4a32","grossValue":206560,"homeNotional":0.07923930269413629,"foreignNotional":20.45958795562599},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":50,"price":258.2,"tickDirection":"ZeroMinusTick","trdMatchID":"5b803378-760b-4919-21fc-bfb275d39ace","grossValue":1291000,"homeNotional":0.49524564183835185,"foreignNotional":127.87242472266244},{"timestamp":"2020-02-17T01:35:36.442Z","symbol":"ETHUSD","side":"Sell","size":244,"price":258.2,"tickDirection":"ZeroMinusTick","trdMatchID":"cf57fec1-c444-b9e5-5e2d-4fb643f4fdb7","grossValue":6300080,"homeNotional":2.416798732171157,"foreignNotional":624.0174326465927}]}`)
|
||||
err := b.wsHandleData(pressXToJSON)
|
||||
if err != nil {
|
||||
|
||||
@@ -119,10 +119,14 @@ func (b *Bitmex) SetDefaults() {
|
||||
b.Requester = request.New(b.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
|
||||
request.WithLimiter(SetRateLimit()))
|
||||
|
||||
b.API.Endpoints.URLDefault = bitmexAPIURL
|
||||
b.API.Endpoints.URL = b.API.Endpoints.URLDefault
|
||||
b.API.Endpoints.WebsocketURL = bitmexWSURL
|
||||
b.API.Endpoints = b.NewEndpoints()
|
||||
err = b.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: bitmexAPIURL,
|
||||
exchange.WebsocketSpot: bitmexWSURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
b.Websocket = stream.New()
|
||||
b.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||
b.WebsocketResponseCheckTimeout = exchange.DefaultWebsocketResponseCheckTimeout
|
||||
@@ -141,6 +145,11 @@ func (b *Bitmex) Setup(exch *config.ExchangeConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
wsEndpoint, err := b.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.Websocket.Setup(&stream.WebsocketSetup{
|
||||
Enabled: exch.Features.Enabled.Websocket,
|
||||
Verbose: exch.Verbose,
|
||||
@@ -148,7 +157,7 @@ func (b *Bitmex) Setup(exch *config.ExchangeConfig) error {
|
||||
WebsocketTimeout: exch.WebsocketTrafficTimeout,
|
||||
DefaultURL: bitmexWSURL,
|
||||
ExchangeName: exch.Name,
|
||||
RunningURL: exch.API.Endpoints.WebsocketURL,
|
||||
RunningURL: wsEndpoint,
|
||||
Connector: b.WsConnect,
|
||||
Subscriber: b.Subscribe,
|
||||
UnSubscriber: b.Unsubscribe,
|
||||
@@ -161,7 +170,6 @@ func (b *Bitmex) Setup(exch *config.ExchangeConfig) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.Websocket.SetupNewConnection(stream.ConnectionSetup{
|
||||
ResponseCheckTimeout: exch.WebsocketResponseCheckTimeout,
|
||||
ResponseMaxLimit: exch.WebsocketResponseMaxLimit,
|
||||
@@ -180,11 +188,15 @@ func (b *Bitmex) Start(wg *sync.WaitGroup) {
|
||||
// Run implements the Bitmex wrapper
|
||||
func (b *Bitmex) Run() {
|
||||
if b.Verbose {
|
||||
wsEndpoint, err := b.API.Endpoints.GetURL(exchange.WebsocketSpot)
|
||||
if err != nil {
|
||||
log.Error(log.ExchangeSys, err)
|
||||
}
|
||||
log.Debugf(log.ExchangeSys,
|
||||
"%s Websocket: %s. (url: %s).\n",
|
||||
b.Name,
|
||||
common.IsEnabled(b.Websocket.IsEnabled()),
|
||||
b.API.Endpoints.WebsocketURL)
|
||||
wsEndpoint)
|
||||
b.PrintEnabledPairs()
|
||||
}
|
||||
|
||||
@@ -383,7 +395,7 @@ func (b *Bitmex) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderb
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
// Bitmex exchange
|
||||
func (b *Bitmex) UpdateAccountInfo() (account.Holdings, error) {
|
||||
func (b *Bitmex) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
|
||||
bal, err := b.GetAllUserMargin()
|
||||
@@ -414,10 +426,10 @@ func (b *Bitmex) UpdateAccountInfo() (account.Holdings, error) {
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (b *Bitmex) FetchAccountInfo() (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(b.Name)
|
||||
func (b *Bitmex) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
|
||||
acc, err := account.GetHoldings(b.Name, assetType)
|
||||
if err != nil {
|
||||
return b.UpdateAccountInfo()
|
||||
return b.UpdateAccountInfo(assetType)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@@ -786,8 +798,8 @@ func (b *Bitmex) AuthenticateWebsocket() error {
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (b *Bitmex) ValidateCredentials() error {
|
||||
_, err := b.UpdateAccountInfo()
|
||||
func (b *Bitmex) ValidateCredentials(assetType asset.Item) error {
|
||||
_, err := b.UpdateAccountInfo(assetType)
|
||||
return b.CheckTransientError(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user