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:
Adam
2021-02-12 16:19:18 +11:00
committed by GitHub
parent e9bd2ad4d8
commit 504c2fad6d
169 changed files with 227754 additions and 31776 deletions

View File

@@ -122,13 +122,13 @@ func (l *LocalBitcoins) GetAccountInformation(username string, self bool) (Accou
resp := response{}
if self {
err := l.SendAuthenticatedHTTPRequest(http.MethodGet, localbitcoinsAPIMyself, nil, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, localbitcoinsAPIMyself, nil, &resp)
if err != nil {
return resp.Data, err
}
} else {
path := fmt.Sprintf("%s/%s/%s/", l.API.Endpoints.URL, localbitcoinsAPIAccountInfo, username)
err := l.SendHTTPRequest(path, &resp, request.Unset)
path := fmt.Sprintf("/%s/%s/", localbitcoinsAPIAccountInfo, username)
err := l.SendHTTPRequest(exchange.RestSpot, path, &resp, request.Unset)
if err != nil {
return resp.Data, err
}
@@ -152,14 +152,14 @@ func (l *LocalBitcoins) Getads(args ...string) (AdData, error) {
var err error
if len(args) == 0 {
err = l.SendAuthenticatedHTTPRequest(http.MethodGet,
err = l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
localbitcoinsAPIAds,
nil,
&resp)
} else {
params := url.Values{"ads": {strings.Join(args, ",")}}
err = l.SendAuthenticatedHTTPRequest(http.MethodGet,
err = l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet,
localbitcoinsAPIAdGet,
params,
&resp)
@@ -189,7 +189,7 @@ func (l *LocalBitcoins) EditAd(_ *AdEdit, adID string) error {
}
}{}
err := l.SendAuthenticatedHTTPRequest(http.MethodPost,
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
localbitcoinsAPIAdEdit+adID+"/",
nil,
&resp)
@@ -209,7 +209,7 @@ func (l *LocalBitcoins) EditAd(_ *AdEdit, adID string) error {
// params - see localbitcoins_types.go AdCreate for reference
// TODO
func (l *LocalBitcoins) CreateAd(_ *AdCreate) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIAdCreate, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIAdCreate, nil, nil)
}
// UpdatePriceEquation updates price equation of an advertisement. If there are
@@ -220,7 +220,7 @@ func (l *LocalBitcoins) CreateAd(_ *AdCreate) error {
// adID - string of specific ad identification
// TODO
func (l *LocalBitcoins) UpdatePriceEquation(adID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIUpdateEquation+adID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIUpdateEquation+adID, nil, nil)
}
// DeleteAd deletes the advertisement by adID.
@@ -235,7 +235,7 @@ func (l *LocalBitcoins) DeleteAd(adID string) error {
} `json:"error"`
}{}
err := l.SendAuthenticatedHTTPRequest(http.MethodPost,
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost,
localbitcoinsAPIDeleteAd+adID+"/",
nil,
&resp)
@@ -253,7 +253,7 @@ func (l *LocalBitcoins) DeleteAd(adID string) error {
// ReleaseFunds releases Bitcoin trades specified by ID {contact_id}. If the
// release was successful a message is returned on the data key.
func (l *LocalBitcoins) ReleaseFunds(contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIRelease+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIRelease+contactID, nil, nil)
}
// ReleaseFundsByPin releases Bitcoin trades specified by ID {contact_id}. if
@@ -261,12 +261,12 @@ func (l *LocalBitcoins) ReleaseFunds(contactID string) error {
// returned on the data key.
// TODO
func (l *LocalBitcoins) ReleaseFundsByPin(contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIReleaseByPin+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIReleaseByPin+contactID, nil, nil)
}
// MarkAsPaid marks a trade as paid.
func (l *LocalBitcoins) MarkAsPaid(contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIMarkAsPaid+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIMarkAsPaid+contactID, nil, nil)
}
// GetMessages returns all chat messages from the trade. Messages are on the message_list key.
@@ -277,14 +277,14 @@ func (l *LocalBitcoins) GetMessages(contactID string) (Message, error) {
resp := response{}
return resp.MessageList,
l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIMessages+contactID, nil, &resp)
l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIMessages+contactID, nil, &resp)
}
// SendMessage posts a message and/or uploads an image to the trade. Encode
// images with multipart/form-data encoding.
// TODO
func (l *LocalBitcoins) SendMessage(contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPISendMessage+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPISendMessage+contactID, nil, nil)
}
// Dispute starts a dispute on the specified trade ID if the requirements for
@@ -293,56 +293,56 @@ func (l *LocalBitcoins) SendMessage(contactID string) error {
// topic - [optional] String Short description of issue to LocalBitcoins customer support.
// TODO
func (l *LocalBitcoins) Dispute(_, contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIDispute+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIDispute+contactID, nil, nil)
}
// CancelTrade cancels the trade if the token owner is the Bitcoin buyer.
// Bitcoin sellers cannot cancel trades.
func (l *LocalBitcoins) CancelTrade(contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPICancelTrade+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPICancelTrade+contactID, nil, nil)
}
// FundTrade attempts to fund an unfunded local trade from the token owners
// wallet. Works only if the token owner is the Bitcoin seller in the trade.
func (l *LocalBitcoins) FundTrade(contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIFundTrade+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIFundTrade+contactID, nil, nil)
}
// ConfirmRealName creates or updates real name confirmation.
func (l *LocalBitcoins) ConfirmRealName(contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIConfirmRealName+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIConfirmRealName+contactID, nil, nil)
}
// VerifyIdentity marks the identity of trade partner as verified. You must be
// the advertiser in this trade.
func (l *LocalBitcoins) VerifyIdentity(contactID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIVerifyIdentity+contactID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIVerifyIdentity+contactID, nil, nil)
}
// InitiateTrade sttempts to start a Bitcoin trade from the specified
// advertisement ID.
// TODO
func (l *LocalBitcoins) InitiateTrade(adID string) error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIInitiateTrade+adID, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIInitiateTrade+adID, nil, nil)
}
// GetTradeInfo returns information about a single trade that the token owner is
// part in.
func (l *LocalBitcoins) GetTradeInfo(contactID string) (dbi DashBoardInfo, err error) {
err = l.SendAuthenticatedHTTPRequest(http.MethodGet, localbitcoinsAPITradeInfo+contactID+"/", nil, &dbi)
err = l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, localbitcoinsAPITradeInfo+contactID+"/", nil, &dbi)
return
}
// GetCountryCodes returns a list of valid and recognized countrycodes
func (l *LocalBitcoins) GetCountryCodes() error {
return l.SendHTTPRequest(l.API.Endpoints.URL+localbitcoinsAPICountryCodes, nil, request.Unset)
return l.SendHTTPRequest(exchange.RestSpot, localbitcoinsAPICountryCodes, nil, request.Unset)
}
// GetCurrencies returns a list of valid and recognized fiat currencies. Also
// contains human readable name for every currency and boolean that tells if
// currency is an altcoin.
func (l *LocalBitcoins) GetCurrencies() error {
return l.SendHTTPRequest(l.API.Endpoints.URL+localbitcoinsAPICurrencies, nil, request.Unset)
return l.SendHTTPRequest(exchange.RestSpot, localbitcoinsAPICurrencies, nil, request.Unset)
}
// GetDashboardInfo returns a list of trades on the data key contact_list. This
@@ -361,7 +361,7 @@ func (l *LocalBitcoins) GetDashboardInfo() ([]DashBoardInfo, error) {
}
return resp.Data.ContactList,
l.SendAuthenticatedHTTPRequest(http.MethodGet, localbitcoinsAPIDashboard, nil, &resp)
l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, localbitcoinsAPIDashboard, nil, &resp)
}
// GetDashboardReleasedTrades returns a list of all released trades where the
@@ -375,7 +375,7 @@ func (l *LocalBitcoins) GetDashboardReleasedTrades() ([]DashBoardInfo, error) {
}
return resp.Data.ContactList,
l.SendAuthenticatedHTTPRequest(http.MethodGet, localbitcoinsAPIDashboardReleased, nil, &resp)
l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, localbitcoinsAPIDashboardReleased, nil, &resp)
}
// GetDashboardCancelledTrades returns a list of all canceled trades where the
@@ -389,7 +389,7 @@ func (l *LocalBitcoins) GetDashboardCancelledTrades() ([]DashBoardInfo, error) {
}
return resp.Data.ContactList,
l.SendAuthenticatedHTTPRequest(http.MethodGet, localbitcoinsAPIDashboardCancelled, nil, &resp)
l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, localbitcoinsAPIDashboardCancelled, nil, &resp)
}
// GetDashboardClosedTrades returns a list of all closed trades where the token
@@ -403,7 +403,7 @@ func (l *LocalBitcoins) GetDashboardClosedTrades() ([]DashBoardInfo, error) {
}
return resp.Data.ContactList,
l.SendAuthenticatedHTTPRequest(http.MethodGet, localbitcoinsAPIDashboardClosed, nil, &resp)
l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, localbitcoinsAPIDashboardClosed, nil, &resp)
}
// SetFeedback gives feedback to user. Possible feedback values are: trust,
@@ -420,20 +420,20 @@ func (l *LocalBitcoins) GetDashboardClosedTrades() ([]DashBoardInfo, error) {
// username - username of trade contact
// TODO
func (l *LocalBitcoins) SetFeedback() error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIFeedback, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIFeedback, nil, nil)
}
// Logout expires the current access token immediately. To get a new token
// afterwards, public apps will need to re-authenticate, confidential apps can
// turn in a refresh token.
func (l *LocalBitcoins) Logout() error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPILogout, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPILogout, nil, nil)
}
// CreateNewInvoice creates a new invoice.
// TODO
func (l *LocalBitcoins) CreateNewInvoice() error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPICreateInvoice, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPICreateInvoice, nil, nil)
}
// GetInvoice returns information about a specific invoice created by the token
@@ -441,7 +441,7 @@ func (l *LocalBitcoins) CreateNewInvoice() error {
// TODO
func (l *LocalBitcoins) GetInvoice() (Invoice, error) {
resp := Invoice{}
return resp, l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPICreateInvoice, nil, &resp)
return resp, l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPICreateInvoice, nil, &resp)
}
// DeleteInvoice deletes a specific invoice. Deleting invoices is possible when
@@ -451,32 +451,32 @@ func (l *LocalBitcoins) GetInvoice() (Invoice, error) {
// TODO
func (l *LocalBitcoins) DeleteInvoice() (Invoice, error) {
resp := Invoice{}
return resp, l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPICreateInvoice, nil, &resp)
return resp, l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPICreateInvoice, nil, &resp)
}
// GetNotifications returns recent notifications.
func (l *LocalBitcoins) GetNotifications() ([]NotificationInfo, error) {
var resp []NotificationInfo
return resp, l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIGetNotification, nil, &resp)
return resp, l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIGetNotification, nil, &resp)
}
// MarkNotifications marks a specific notification as read.
// TODO
func (l *LocalBitcoins) MarkNotifications() error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIMarkNotification, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIMarkNotification, nil, nil)
}
// GetPaymentMethods returns a list of valid payment methods. Also contains name
// and code for payment methods, and possible limitations in currencies and bank
// name choices.
func (l *LocalBitcoins) GetPaymentMethods() error {
return l.SendHTTPRequest(l.API.Endpoints.URL+localbitcoinsAPIPaymentMethods, nil, request.Unset)
return l.SendHTTPRequest(exchange.RestSpot, localbitcoinsAPIPaymentMethods, nil, request.Unset)
}
// GetPaymentMethodsByCountry returns a list of valid payment methods filtered
// by countrycodes.
func (l *LocalBitcoins) GetPaymentMethodsByCountry(countryCode string) error {
return l.SendHTTPRequest(l.API.Endpoints.URL+localbitcoinsAPIPaymentMethods+countryCode, nil, request.Unset)
return l.SendHTTPRequest(exchange.RestSpot, localbitcoinsAPIPaymentMethods+countryCode, nil, request.Unset)
}
// CheckPincode checks the given PIN code against the token owners currently
@@ -494,7 +494,7 @@ func (l *LocalBitcoins) CheckPincode(pin int) (bool, error) {
resp := response{}
values := url.Values{}
values.Set("pincode", strconv.Itoa(pin))
err := l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIPinCode, values, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIPinCode, values, &resp)
if err != nil {
return false, err
@@ -511,13 +511,13 @@ func (l *LocalBitcoins) CheckPincode(pin int) (bool, error) {
// sell listings for each.
// TODO
func (l *LocalBitcoins) GetPlaces() error {
return l.SendHTTPRequest(l.API.Endpoints.URL+localbitcoinsAPIPlaces, nil, request.Unset)
return l.SendHTTPRequest(exchange.RestSpot, localbitcoinsAPIPlaces, nil, request.Unset)
}
// VerifyUsername returns list of real name verifiers for the user. Returns a
// list only when you have a trade with the user where you are the seller.
func (l *LocalBitcoins) VerifyUsername() error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIVerifyUsername, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIVerifyUsername, nil, nil)
}
// GetRecentMessages returns maximum of 25 newest trade messages. Does not
@@ -525,7 +525,7 @@ func (l *LocalBitcoins) VerifyUsername() error {
// and the newest one is first.
// TODO
func (l *LocalBitcoins) GetRecentMessages() error {
return l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIVerifyUsername, nil, nil)
return l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIVerifyUsername, nil, nil)
}
// GetWalletInfo gets information about the token owner's wallet balance.
@@ -534,7 +534,7 @@ func (l *LocalBitcoins) GetWalletInfo() (WalletInfo, error) {
Data WalletInfo `json:"data"`
}
resp := response{}
err := l.SendAuthenticatedHTTPRequest(http.MethodGet, localbitcoinsAPIWallet, nil, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, localbitcoinsAPIWallet, nil, &resp)
if err != nil {
return WalletInfo{}, err
@@ -555,7 +555,7 @@ func (l *LocalBitcoins) GetWalletBalance() (WalletBalanceInfo, error) {
Data WalletBalanceInfo `json:"data"`
}
resp := response{}
err := l.SendAuthenticatedHTTPRequest(http.MethodGet, localbitcoinsAPIWalletBalance, nil, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodGet, localbitcoinsAPIWalletBalance, nil, &resp)
if err != nil {
return WalletBalanceInfo{}, err
@@ -594,7 +594,7 @@ func (l *LocalBitcoins) WalletSend(address string, amount float64, pin int64) er
} `json:"data"`
}{}
err := l.SendAuthenticatedHTTPRequest(http.MethodPost, path, values, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, path, values, &resp)
if err != nil {
return err
}
@@ -624,7 +624,7 @@ func (l *LocalBitcoins) GetWalletAddress() (string, error) {
}
}
resp := response{}
err := l.SendAuthenticatedHTTPRequest(http.MethodPost, localbitcoinsAPIWalletAddress, nil, &resp)
err := l.SendAuthenticatedHTTPRequest(exchange.RestSpot, http.MethodPost, localbitcoinsAPIWalletAddress, nil, &resp)
if err != nil {
return "", err
}
@@ -639,22 +639,19 @@ func (l *LocalBitcoins) GetWalletAddress() (string, error) {
// GetBitcoinsWithCashAd returns buy or sell as cash local advertisements.
// TODO
func (l *LocalBitcoins) GetBitcoinsWithCashAd() error {
return l.SendHTTPRequest(l.API.Endpoints.URL+localbitcoinsAPICashBuy, nil, request.Unset)
return l.SendHTTPRequest(exchange.RestSpot, localbitcoinsAPICashBuy, nil, request.Unset)
}
// GetBitcoinsOnlineAd this API returns buy or sell Bitcoin online ads.
// TODO
func (l *LocalBitcoins) GetBitcoinsOnlineAd() error {
return l.SendHTTPRequest(l.API.Endpoints.URL+localbitcoinsAPIOnlineBuy, nil, request.Unset)
return l.SendHTTPRequest(exchange.RestSpot, localbitcoinsAPIOnlineBuy, nil, request.Unset)
}
// GetTicker returns list of all completed trades.
func (l *LocalBitcoins) GetTicker() (map[string]Ticker, error) {
result := make(map[string]Ticker)
return result,
l.SendHTTPRequest(l.API.Endpoints.URL+localbitcoinsAPITicker,
&result,
tickerLimiter)
return result, l.SendHTTPRequest(exchange.RestSpot, localbitcoinsAPITicker, &result, tickerLimiter)
}
// GetTradableCurrencies returns a list of tradable fiat currencies
@@ -675,11 +672,9 @@ func (l *LocalBitcoins) GetTradableCurrencies() ([]string, error) {
// GetTrades returns all closed trades in online buy and online sell categories,
// updated every 15 minutes.
func (l *LocalBitcoins) GetTrades(currency string, values url.Values) ([]Trade, error) {
path := common.EncodeURLValues(fmt.Sprintf("%s%s/trades.json",
l.API.Endpoints.URL+localbitcoinsAPIBitcoincharts, currency),
values)
path := common.EncodeURLValues(fmt.Sprintf("%s%s/trades.json", localbitcoinsAPIBitcoincharts, currency), values)
var result []Trade
return result, l.SendHTTPRequest(path, &result, request.Unset)
return result, l.SendHTTPRequest(exchange.RestSpot, path, &result, request.Unset)
}
// GetOrderbook returns buy and sell bitcoin online advertisements. Amount is
@@ -692,9 +687,9 @@ func (l *LocalBitcoins) GetOrderbook(currency string) (Orderbook, error) {
Asks [][]string `json:"asks"`
}
path := l.API.Endpoints.URL + localbitcoinsAPIBitcoincharts + currency + "/orderbook.json"
path := fmt.Sprintf("%s/%s/orderbook.json", localbitcoinsAPIBitcoincharts, currency+"/orderbook.json")
resp := response{}
err := l.SendHTTPRequest(path, &resp, orderBookLimiter)
err := l.SendHTTPRequest(exchange.RestSpot, path, &resp, orderBookLimiter)
if err != nil {
return Orderbook{}, err
@@ -734,10 +729,14 @@ func (l *LocalBitcoins) GetOrderbook(currency string) (Orderbook, error) {
}
// SendHTTPRequest sends an unauthenticated HTTP request
func (l *LocalBitcoins) SendHTTPRequest(path string, result interface{}, ep request.EndpointLimit) error {
func (l *LocalBitcoins) SendHTTPRequest(endpoint exchange.URL, path string, result interface{}, ep request.EndpointLimit) error {
ePoint, err := l.API.Endpoints.GetURL(endpoint)
if err != nil {
return err
}
return l.SendPayload(context.Background(), &request.Item{
Method: http.MethodGet,
Path: path,
Path: ePoint + path,
Result: result,
Verbose: l.Verbose,
HTTPDebugging: l.HTTPDebugging,
@@ -748,11 +747,14 @@ func (l *LocalBitcoins) SendHTTPRequest(path string, result interface{}, ep requ
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request to
// localbitcoins
func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(method, path string, params url.Values, result interface{}) (err error) {
func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(ep exchange.URL, method, path string, params url.Values, result interface{}) (err error) {
if !l.AllowAuthenticatedRequest() {
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, l.Name)
}
endpoint, err := l.API.Endpoints.GetURL(ep)
if err != nil {
return err
}
n := l.Requester.GetNonce(true).String()
path = "/api/" + path
@@ -766,7 +768,7 @@ func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(method, path string, params
headers["Content-Type"] = "application/x-www-form-urlencoded"
if l.Verbose {
log.Debugf(log.ExchangeSys, "Sending POST request to `%s`, path: `%s`, params: `%s`.", l.API.Endpoints.URL, path, encoded)
log.Debugf(log.ExchangeSys, "Sending POST request to `%s`, path: `%s`, params: `%s`.", endpoint, path, encoded)
}
if method == http.MethodGet && len(encoded) > 0 {
@@ -775,7 +777,7 @@ func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(method, path string, params
return l.SendPayload(context.Background(), &request.Item{
Method: method,
Path: l.API.Endpoints.URL + path,
Path: endpoint + path,
Headers: headers,
Body: bytes.NewBufferString(encoded),
Result: result,

View File

@@ -33,6 +33,6 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatal("Localbitcoins setup error", err)
}
log.Printf(sharedtestvalues.LiveTesting, l.Name, l.API.Endpoints.URL)
log.Printf(sharedtestvalues.LiveTesting, l.Name)
os.Exit(m.Run())
}

View File

@@ -44,8 +44,14 @@ func TestMain(m *testing.M) {
}
l.HTTPClient = newClient
l.API.Endpoints.URL = serverDetails
endpoints := l.API.Endpoints.GetURLMap()
for k := range endpoints {
err = l.API.Endpoints.SetRunning(k, serverDetails)
if err != nil {
log.Fatal(err)
}
}
log.Printf(sharedtestvalues.MockTesting, l.Name, l.API.Endpoints.URL)
log.Printf(sharedtestvalues.MockTesting, l.Name)
os.Exit(m.Run())
}

View File

@@ -212,7 +212,8 @@ func TestGetActiveOrders(t *testing.T) {
t.Parallel()
var getOrdersRequest = order.GetOrdersRequest{
Type: order.AnyType,
Type: order.AnyType,
AssetType: asset.Spot,
}
_, err := l.GetActiveOrders(&getOrdersRequest)
@@ -230,7 +231,8 @@ func TestGetOrderHistory(t *testing.T) {
t.Parallel()
var getOrdersRequest = order.GetOrdersRequest{
Type: order.AnyType,
Type: order.AnyType,
AssetType: asset.Spot,
}
_, err := l.GetOrderHistory(&getOrdersRequest)

View File

@@ -92,11 +92,14 @@ func (l *LocalBitcoins) SetDefaults() {
}
l.Requester = request.New(l.Name,
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
request.WithLimiter(SetRateLimit()))
l.API.Endpoints.URLDefault = localbitcoinsAPIURL
l.API.Endpoints.URL = l.API.Endpoints.URLDefault
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
l.API.Endpoints = l.NewEndpoints()
err = l.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
exchange.RestSpot: localbitcoinsAPIURL,
})
if err != nil {
log.Errorln(log.ExchangeSys, err)
}
}
// Setup sets exchange configuration parameters
@@ -250,7 +253,7 @@ func (l *LocalBitcoins) UpdateOrderbook(p currency.Pair, assetType asset.Item) (
// UpdateAccountInfo retrieves balances for all enabled currencies for the
// LocalBitcoins exchange
func (l *LocalBitcoins) UpdateAccountInfo() (account.Holdings, error) {
func (l *LocalBitcoins) UpdateAccountInfo(assetType asset.Item) (account.Holdings, error) {
var response account.Holdings
response.Exchange = l.Name
accountBalance, err := l.GetWalletBalance()
@@ -274,10 +277,10 @@ func (l *LocalBitcoins) UpdateAccountInfo() (account.Holdings, error) {
}
// FetchAccountInfo retrieves balances for all enabled currencies
func (l *LocalBitcoins) FetchAccountInfo() (account.Holdings, error) {
acc, err := account.GetHoldings(l.Name)
func (l *LocalBitcoins) FetchAccountInfo(assetType asset.Item) (account.Holdings, error) {
acc, err := account.GetHoldings(l.Name, assetType)
if err != nil {
return l.UpdateAccountInfo()
return l.UpdateAccountInfo(assetType)
}
return acc, nil
@@ -644,8 +647,8 @@ func (l *LocalBitcoins) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest
// ValidateCredentials validates current credentials used for wrapper
// functionality
func (l *LocalBitcoins) ValidateCredentials() error {
_, err := l.UpdateAccountInfo()
func (l *LocalBitcoins) ValidateCredentials(assetType asset.Item) error {
_, err := l.UpdateAccountInfo(assetType)
return l.CheckTransientError(err)
}