From 35eece1e409952a3356a42cdb2a9794bee78b9f6 Mon Sep 17 00:00:00 2001 From: sanagrishin Date: Mon, 19 Apr 2021 17:04:45 +0500 Subject: [PATCH] added us domain --- .golangci.yml | 1 - README.md | 10 +++++++-- account.go | 6 +++--- client.go | 43 +++++++++++++++++++++++++++----------- client_test.go | 13 +++++++++--- converts.go | 6 +++--- examples/websocket/main.go | 1 + fills.go | 2 +- futures.go | 14 ++++++------- markets.go | 10 ++++----- orders.go | 32 ++++++++++++++-------------- spot_margin.go | 18 ++++++++-------- subaccounts.go | 12 +++++------ websocket.go | 2 +- 14 files changed, 101 insertions(+), 69 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5d90787..08a7e2e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,6 +21,5 @@ linters: - bodyclose - depguard - goimports - - dupl enable-all: false disable-all: true diff --git a/README.md b/README.md index 8d7f179..4e0b2fa 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,7 @@ go get github.com/grishinsana/goftx > See examples directory and test cases for more examples ### TODO -- Futures - Wallet -- Converts - Funding Payments - Leveraged Tokens - Options @@ -96,6 +94,14 @@ func main() { } ``` +### FTX US Mode +If you need to use FTX US than you could set goftx.WithFTXUS option +```go + client := goftx.New( + goftx.WithFTXUS(), + ) +``` + ### Websocket Debug Mode If need, it is possible to set debug mode to look error and system messages in stream methods ```go diff --git a/account.go b/account.go index e089fc5..1e76bba 100644 --- a/account.go +++ b/account.go @@ -25,7 +25,7 @@ func (a *Account) GetAccountInformation() (*models.AccountInformation, error) { request, err := a.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiGetAccountInformation), + URL: fmt.Sprintf("%s%s", a.client.apiURL, apiGetAccountInformation), }) if err != nil { return nil, errors.WithStack(err) @@ -49,7 +49,7 @@ func (a *Account) GetPositions() ([]*models.Position, error) { request, err := a.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiGetPositions), + URL: fmt.Sprintf("%s%s", a.client.apiURL, apiGetPositions), }) if err != nil { return nil, errors.WithStack(err) @@ -80,7 +80,7 @@ func (a *Account) ChangeAccountLeverage(leverage decimal.Decimal) error { request, err := a.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, apiPostLeverage), + URL: fmt.Sprintf("%s%s", a.client.apiURL, apiPostLeverage), Body: body, }) if err != nil { diff --git a/client.go b/client.go index dfa544b..1a59eec 100644 --- a/client.go +++ b/client.go @@ -18,13 +18,13 @@ import ( ) const ( - apiUrl = "https://ftx.com/api" - apiOtcUrl = "https://otc.ftx.com/api" + apiUrlFormat = "https://ftx.%s/api" + apiOtcUrl = "https://otc.ftx.com/api" - keyHeader = "FTX-KEY" - signHeader = "FTX-SIGN" - tsHeader = "FTX-TS" - subAccountHeader = "FTX-SUBACCOUNT" + keyHeaderFormat = "FTX%s-KEY" + signHeaderFormat = "FTX%s-SIGN" + tsHeaderFormat = "FTX%s-TS" + subAccountHeaderFormat = "FTX%s-SUBACCOUNT" ) type Option func(c *Client) @@ -35,6 +35,12 @@ func WithHTTPClient(client *http.Client) Option { } } +func WithFTXUS() Option { + return func(c *Client) { + c.isFtxUS = true + } +} + func WithAuth(key, secret string, subAccount ...string) Option { return func(c *Client) { c.apiKey = key @@ -54,6 +60,8 @@ type Client struct { secret string subAccount string serverTimeDiff time.Duration + isFtxUS bool + apiURL string SubAccounts Markets Account @@ -74,6 +82,12 @@ func New(opts ...Option) *Client { opt(client) } + domain := "com" + if client.isFtxUS { + domain = "us" + } + client.apiURL = fmt.Sprintf(apiUrlFormat, domain) + client.SubAccounts = SubAccounts{client: client} client.Markets = Markets{client: client} client.Account = Account{client: client} @@ -87,7 +101,7 @@ func New(opts ...Option) *Client { secret: client.secret, subAccount: client.subAccount, mu: &sync.Mutex{}, - url: wsUrl, + url: fmt.Sprintf(wsUrlFormat, domain), dialer: websocket.DefaultDialer, wsReconnectionCount: reconnectCount, wsReconnectionInterval: reconnectInterval, @@ -144,13 +158,18 @@ func (c *Client) prepareRequest(request Request) (*http.Request, error) { payload += string(request.Body) } + usPrefix := "" + if c.isFtxUS { + usPrefix = "US" + } + req.Header.Set("Content-Type", "application/json") - req.Header.Set(keyHeader, c.apiKey) - req.Header.Set(signHeader, c.signture(payload)) - req.Header.Set(tsHeader, nonce) + req.Header.Set(fmt.Sprintf(keyHeaderFormat, usPrefix), c.apiKey) + req.Header.Set(fmt.Sprintf(signHeaderFormat, usPrefix), c.signture(payload)) + req.Header.Set(fmt.Sprintf(tsHeaderFormat, usPrefix), nonce) if c.subAccount != "" { - req.Header.Set(subAccountHeader, c.subAccount) + req.Header.Set(fmt.Sprintf(subAccountHeaderFormat, usPrefix), c.subAccount) } } @@ -221,7 +240,7 @@ func (c *Client) GetServerTime() (time.Time, error) { func (c Client) Ping() error { request, err := c.prepareRequest(Request{ Method: http.MethodGet, - URL: apiUrl, + URL: c.apiURL, }) if err != nil { return errors.WithStack(err) diff --git a/client_test.go b/client_test.go index 7de86b6..f0fdbfa 100644 --- a/client_test.go +++ b/client_test.go @@ -17,8 +17,15 @@ func TestClient_GetServerTime(t *testing.T) { } func TestClient_Ping(t *testing.T) { - ftx := New() + t.Run("com", func(t *testing.T) { + ftx := New(WithFTXUS()) + err := ftx.Ping() + require.NoError(t, err) + }) - err := ftx.Ping() - require.NoError(t, err) + t.Run("us", func(t *testing.T) { + ftx := New() + err := ftx.Ping() + require.NoError(t, err) + }) } diff --git a/converts.go b/converts.go index e87127a..1b05f6c 100644 --- a/converts.go +++ b/converts.go @@ -25,7 +25,7 @@ func (c *Converts) CreateQuote(payload *models.CreateQuotePayload) (int64, error request, err := c.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, apiQuotes), + URL: fmt.Sprintf("%s%s", c.client.apiURL, apiQuotes), Body: body, }) if err != nil { @@ -57,7 +57,7 @@ func (c *Converts) GetQuotes(quoteID int64, market *string) ([]*models.QuoteStat request, err := c.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s/%d", apiUrl, apiQuotes, quoteID), + URL: fmt.Sprintf("%s%s/%d", c.client.apiURL, apiQuotes, quoteID), Params: queryParams, }) if err != nil { @@ -82,7 +82,7 @@ func (c *Converts) AcceptQuote(quoteID int64) error { request, err := c.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s/%d/accept", apiUrl, apiQuotes, quoteID), + URL: fmt.Sprintf("%s%s/%d/accept", c.client.apiURL, apiQuotes, quoteID), }) if err != nil { return errors.WithStack(err) diff --git a/examples/websocket/main.go b/examples/websocket/main.go index d208da2..26a3474 100644 --- a/examples/websocket/main.go +++ b/examples/websocket/main.go @@ -19,6 +19,7 @@ func main() { client := goftx.New( goftx.WithAuth(os.Getenv("FTX_KEY"), os.Getenv("FTX_SECRET")), + goftx.WithFTXUS(), ) client.Stream.SetStreamTimeout(60 * time.Second) diff --git a/fills.go b/fills.go index 0d09b8d..72138cd 100644 --- a/fills.go +++ b/fills.go @@ -25,7 +25,7 @@ func (f *Fills) GetFills(params *models.GetFillsParams) ([]*models.Fill, error) request, err := f.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiFills), + URL: fmt.Sprintf("%s%s", f.client.apiURL, apiFills), Params: queryParams, }) if err != nil { diff --git a/futures.go b/futures.go index 888c992..be353c9 100644 --- a/futures.go +++ b/futures.go @@ -26,7 +26,7 @@ type Futures struct { func (f *Futures) GetFutures() ([]*models.Future, error) { request, err := f.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiFutures), + URL: fmt.Sprintf("%s%s", f.client.apiURL, apiFutures), }) if err != nil { return nil, errors.WithStack(err) @@ -49,7 +49,7 @@ func (f *Futures) GetFutures() ([]*models.Future, error) { func (f *Futures) GetFuture(name string) (*models.Future, error) { request, err := f.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s/%s", apiUrl, apiFutures, name), + URL: fmt.Sprintf("%s%s/%s", f.client.apiURL, apiFutures, name), }) if err != nil { return nil, errors.WithStack(err) @@ -72,7 +72,7 @@ func (f *Futures) GetFuture(name string) (*models.Future, error) { func (f *Futures) GetFutureStats(name string) (*models.FutureStats, error) { request, err := f.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s/%s/stats", apiUrl, apiFutures, name), + URL: fmt.Sprintf("%s%s/%s/stats", f.client.apiURL, apiFutures, name), }) if err != nil { return nil, errors.WithStack(err) @@ -100,7 +100,7 @@ func (f *Futures) GetFundingRates(params *models.GetFundingRatesParams) ([]*mode request, err := f.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiFundingRates), + URL: fmt.Sprintf("%s%s", f.client.apiURL, apiFundingRates), Params: queryParams, }) if err != nil { @@ -124,7 +124,7 @@ func (f *Futures) GetFundingRates(params *models.GetFundingRatesParams) ([]*mode func (f *Futures) GetIndexWeights(indexName string) (map[string]decimal.Decimal, error) { request, err := f.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, fmt.Sprintf(apiIndexWeights, indexName)), + URL: fmt.Sprintf("%s%s", f.client.apiURL, fmt.Sprintf(apiIndexWeights, indexName)), }) if err != nil { return nil, errors.WithStack(err) @@ -147,7 +147,7 @@ func (f *Futures) GetIndexWeights(indexName string) (map[string]decimal.Decimal, func (f *Futures) GetExpiredFutures() ([]*models.FutureExpired, error) { request, err := f.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiExpiredFutures), + URL: fmt.Sprintf("%s%s", f.client.apiURL, apiExpiredFutures), }) if err != nil { return nil, errors.WithStack(err) @@ -175,7 +175,7 @@ func (f *Futures) GetHistoricalIndex(market string, params *models.GetHistorical request, err := f.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, fmt.Sprintf(apiIndexCandles, market)), + URL: fmt.Sprintf("%s%s", f.client.apiURL, fmt.Sprintf(apiIndexCandles, market)), Params: queryParams, }) if err != nil { diff --git a/markets.go b/markets.go index 6978c0e..e36b092 100644 --- a/markets.go +++ b/markets.go @@ -24,7 +24,7 @@ type Markets struct { func (m *Markets) GetMarkets() ([]*models.Market, error) { request, err := m.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiGetMarkets), + URL: fmt.Sprintf("%s%s", m.client.apiURL, apiGetMarkets), }) if err != nil { return nil, errors.WithStack(err) @@ -47,7 +47,7 @@ func (m *Markets) GetMarkets() ([]*models.Market, error) { func (m *Markets) GetMarketByName(name string) (*models.Market, error) { request, err := m.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s/%s", apiUrl, apiGetMarkets, name), + URL: fmt.Sprintf("%s%s/%s", m.client.apiURL, apiGetMarkets, name), }) if err != nil { return nil, errors.WithStack(err) @@ -77,7 +77,7 @@ func (m *Markets) GetOrderBook(marketName string, depth *int) (*models.OrderBook request, err := m.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, path), + URL: fmt.Sprintf("%s%s", m.client.apiURL, path), Params: params, }) if err != nil { @@ -107,7 +107,7 @@ func (m *Markets) GetTrades(marketName string, params *models.GetTradesParams) ( path := fmt.Sprintf(apiGetTrades, marketName) request, err := m.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, path), + URL: fmt.Sprintf("%s%s", m.client.apiURL, path), Params: queryParams, }) if err != nil { @@ -137,7 +137,7 @@ func (m *Markets) GetHistoricalPrices(marketName string, params *models.GetHisto path := fmt.Sprintf(apiGetHistoricalPrices, marketName) request, err := m.client.prepareRequest(Request{ Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, path), + URL: fmt.Sprintf("%s%s", m.client.apiURL, path), Params: queryParams, }) if err != nil { diff --git a/orders.go b/orders.go index bd42a92..ac0e805 100644 --- a/orders.go +++ b/orders.go @@ -29,7 +29,7 @@ func (o *Orders) GetOpenOrders(market string) ([]*models.Order, error) { requestParams := Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiOrders), + URL: fmt.Sprintf("%s%s", o.client.apiURL, apiOrders), } if market != "" { requestParams.Params = map[string]string{ @@ -65,7 +65,7 @@ func (o *Orders) GetOrdersHistory(params *models.GetOrdersHistoryParams) ([]*mod request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiGetOrdersHistory), + URL: fmt.Sprintf("%s%s", o.client.apiURL, apiGetOrdersHistory), Params: queryParams, }) if err != nil { @@ -95,7 +95,7 @@ func (o *Orders) GetOpenTriggerOrders(params *models.GetOpenTriggerOrdersParams) request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiTriggerOrders), + URL: fmt.Sprintf("%s%s", o.client.apiURL, apiTriggerOrders), Params: queryParams, }) if err != nil { @@ -120,7 +120,7 @@ func (o *Orders) GetOrderTriggers(orderID int64) ([]*models.Trigger, error) { request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, fmt.Sprintf(apiGetOrderTriggers, orderID)), + URL: fmt.Sprintf("%s%s", o.client.apiURL, fmt.Sprintf(apiGetOrderTriggers, orderID)), }) if err != nil { return nil, errors.WithStack(err) @@ -149,7 +149,7 @@ func (o *Orders) GetTriggerOrdersHistory(params *models.GetTriggerOrdersHistoryP request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiGetTriggerOrdersHistory), + URL: fmt.Sprintf("%s%s", o.client.apiURL, apiGetTriggerOrdersHistory), Params: queryParams, }) if err != nil { @@ -179,7 +179,7 @@ func (o *Orders) PlaceOrder(payload *models.PlaceOrderPayload) (*models.Order, e request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, apiOrders), + URL: fmt.Sprintf("%s%s", o.client.apiURL, apiOrders), Body: body, }) if err != nil { @@ -214,7 +214,7 @@ func (o *Orders) PlaceTriggerOrder(payload *models.PlaceTriggerOrderPayload) (*m request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, apiTriggerOrders), + URL: fmt.Sprintf("%s%s", o.client.apiURL, apiTriggerOrders), Body: body, }) if err != nil { @@ -244,7 +244,7 @@ func (o *Orders) ModifyOrder(payload *models.ModifyOrderPayload, orderID int64) request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, fmt.Sprintf(apiModifyOrder, orderID)), + URL: fmt.Sprintf("%s%s", o.client.apiURL, fmt.Sprintf(apiModifyOrder, orderID)), Body: body, }) if err != nil { @@ -274,7 +274,7 @@ func (o *Orders) ModifyOrderByClientID(payload *models.ModifyOrderPayload, clien request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, fmt.Sprintf(apiModifyOrderByClientID, clientOrderID)), + URL: fmt.Sprintf("%s%s", o.client.apiURL, fmt.Sprintf(apiModifyOrderByClientID, clientOrderID)), Body: body, }) if err != nil { @@ -304,7 +304,7 @@ func (o *Orders) ModifyTriggerOrder(payload *models.ModifyTriggerOrderPayload, o request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, fmt.Sprintf(apiModifyTriggerOrder, orderID)), + URL: fmt.Sprintf("%s%s", o.client.apiURL, fmt.Sprintf(apiModifyTriggerOrder, orderID)), Body: body, }) if err != nil { @@ -329,7 +329,7 @@ func (o *Orders) GetOrder(orderID int64) (*models.Order, error) { request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s/%d", apiUrl, apiOrders, orderID), + URL: fmt.Sprintf("%s%s/%d", o.client.apiURL, apiOrders, orderID), }) if err != nil { return nil, errors.WithStack(err) @@ -353,7 +353,7 @@ func (o *Orders) GetOrderByClientID(clientOrderID int64) (*models.Order, error) request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s/by_client_id/%d", apiUrl, apiOrders, clientOrderID), + URL: fmt.Sprintf("%s%s/by_client_id/%d", o.client.apiURL, apiOrders, clientOrderID), }) if err != nil { return nil, errors.WithStack(err) @@ -377,7 +377,7 @@ func (o *Orders) CancelOrder(orderID int64) error { request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodDelete, - URL: fmt.Sprintf("%s%s/%d", apiUrl, apiOrders, orderID), + URL: fmt.Sprintf("%s%s/%d", o.client.apiURL, apiOrders, orderID), }) if err != nil { return errors.WithStack(err) @@ -395,7 +395,7 @@ func (o *Orders) CancelOrderByClientID(clientOrderID int64) error { request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodDelete, - URL: fmt.Sprintf("%s%s/by_client_id/%d", apiUrl, apiOrders, clientOrderID), + URL: fmt.Sprintf("%s%s/by_client_id/%d", o.client.apiURL, apiOrders, clientOrderID), }) if err != nil { return errors.WithStack(err) @@ -413,7 +413,7 @@ func (o *Orders) CancelOpenTriggerOrder(triggerOrderID int64) error { request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodDelete, - URL: fmt.Sprintf("%s%s/%d", apiUrl, apiTriggerOrders, triggerOrderID), + URL: fmt.Sprintf("%s%s/%d", o.client.apiURL, apiTriggerOrders, triggerOrderID), }) if err != nil { return errors.WithStack(err) @@ -436,7 +436,7 @@ func (o *Orders) CancelAllOrders(payload *models.CancelAllOrdersPayload) error { request, err := o.client.prepareRequest(Request{ Auth: true, Method: http.MethodDelete, - URL: fmt.Sprintf("%s%s", apiUrl, apiOrders), + URL: fmt.Sprintf("%s%s", o.client.apiURL, apiOrders), Body: body, }) if err != nil { diff --git a/spot_margin.go b/spot_margin.go index 64099eb..95c2340 100644 --- a/spot_margin.go +++ b/spot_margin.go @@ -29,7 +29,7 @@ func (s *SpotMargin) GetBorrowRates() ([]*models.BorrowRate, error) { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiBorrowRates), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiBorrowRates), }) if err != nil { return nil, errors.WithStack(err) @@ -53,7 +53,7 @@ func (s *SpotMargin) GetLendingRates() ([]*models.LendingRate, error) { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiLendingRates), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiLendingRates), }) if err != nil { return nil, errors.WithStack(err) @@ -77,7 +77,7 @@ func (s *SpotMargin) GetDailyBorrowedAmounts() ([]*models.BorrowSummary, error) request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiBorrowSummary), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiBorrowSummary), }) if err != nil { return nil, errors.WithStack(err) @@ -105,7 +105,7 @@ func (s *SpotMargin) GetMarketInfo(market string) ([]*models.GetSpotMarginMarket request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiMarketInfo), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiMarketInfo), Params: queryParams, }) if err != nil { @@ -130,7 +130,7 @@ func (s *SpotMargin) GetBorrowHistory() ([]*models.BorrowHistory, error) { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiBorrowHistory), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiBorrowHistory), }) if err != nil { return nil, errors.WithStack(err) @@ -154,7 +154,7 @@ func (s *SpotMargin) GetLendingHistory() ([]*models.LendingHistory, error) { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiLendingHistory), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiLendingHistory), }) if err != nil { return nil, errors.WithStack(err) @@ -178,7 +178,7 @@ func (s *SpotMargin) GetLendingOffers() ([]*models.LendingOffer, error) { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiLendingOffers), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiLendingOffers), }) if err != nil { return nil, errors.WithStack(err) @@ -202,7 +202,7 @@ func (s *SpotMargin) GetLendingInfo() ([]*models.LendingInfo, error) { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiLendingInfo), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiLendingInfo), }) if err != nil { return nil, errors.WithStack(err) @@ -231,7 +231,7 @@ func (s *SpotMargin) SubmitLendingOffer(payload *models.LendingOfferPayload) err request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, apiLendingOffers), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiLendingOffers), Body: body, }) if err != nil { diff --git a/subaccounts.go b/subaccounts.go index 33af075..cdc31cd 100644 --- a/subaccounts.go +++ b/subaccounts.go @@ -25,7 +25,7 @@ func (s *SubAccounts) GetSubaccounts() ([]*models.SubAccount, error) { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, apiSubaccounts), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiSubaccounts), }) if err != nil { return nil, errors.WithStack(err) @@ -56,7 +56,7 @@ func (s *SubAccounts) CreateSubaccount(nickname string) (*models.SubAccount, err request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, apiSubaccounts), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiSubaccounts), Body: body, }) if err != nil { @@ -89,7 +89,7 @@ func (s *SubAccounts) ChangeSubaccount(nickname, newNickname string) error { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, apiChangeSubaccountName), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiChangeSubaccountName), Body: body, }) if err != nil { @@ -115,7 +115,7 @@ func (s *SubAccounts) DeleteSubaccount(nickname string) error { request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodDelete, - URL: fmt.Sprintf("%s%s", apiUrl, apiSubaccounts), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiSubaccounts), Body: body, }) if err != nil { @@ -134,7 +134,7 @@ func (s *SubAccounts) GetSubaccountBalances(nickname string) ([]*models.Balance, request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodGet, - URL: fmt.Sprintf("%s%s", apiUrl, fmt.Sprintf(apiGetSubaccountBalances, nickname)), + URL: fmt.Sprintf("%s%s", s.client.apiURL, fmt.Sprintf(apiGetSubaccountBalances, nickname)), }) if err != nil { return nil, errors.WithStack(err) @@ -163,7 +163,7 @@ func (s *SubAccounts) Transfer(payload *models.TransferPayload) (*models.Transfe request, err := s.client.prepareRequest(Request{ Auth: true, Method: http.MethodPost, - URL: fmt.Sprintf("%s%s", apiUrl, apiTransfer), + URL: fmt.Sprintf("%s%s", s.client.apiURL, apiTransfer), Body: body, }) if err != nil { diff --git a/websocket.go b/websocket.go index d006159..327adf2 100644 --- a/websocket.go +++ b/websocket.go @@ -19,7 +19,7 @@ import ( ) const ( - wsUrl = "wss://ftx.com/ws/" + wsUrlFormat = "wss://ftx.%s/ws/" writeWait = time.Second * 10 reconnectCount = int(10)