mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
ItBit: Remove exchange implementation (#1463)
This commit is contained in:
@@ -36,7 +36,6 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
|
||||
| Gemini | Yes | Yes | No |
|
||||
| HitBTC | Yes | Yes | No |
|
||||
| Huobi.Pro | Yes | Yes | NA |
|
||||
| ItBit | Yes | NA | No |
|
||||
| Kraken | Yes | Yes | NA |
|
||||
| Kucoin | Yes | Yes | NA |
|
||||
| Lbank | Yes | No | NA |
|
||||
|
||||
@@ -38,7 +38,6 @@ const (
|
||||
pathBitmex = "https://www.bitmex.com/static/md/en-US/apiChangelog"
|
||||
pathANX = "https://anxv3.docs.apiary.io/"
|
||||
pathPoloniex = "https://docs.poloniex.com/#changelog"
|
||||
pathIbBit = "https://api.itbit.com/docs"
|
||||
pathBTCMarkets = "https://api.btcmarkets.net/openapi/info/index.yaml"
|
||||
pathEXMO = "https://exmo.com/en/api/"
|
||||
pathBitstamp = "https://www.bitstamp.net/api/"
|
||||
@@ -468,8 +467,6 @@ func checkChangeLog(htmlData *HTMLScrapingData) (string, error) {
|
||||
dataStrings, err = htmlScrapeANX(htmlData)
|
||||
case pathPoloniex:
|
||||
dataStrings, err = htmlScrapePoloniex(htmlData)
|
||||
case pathIbBit:
|
||||
dataStrings, err = htmlScrapeItBit(htmlData)
|
||||
case pathBTCMarkets:
|
||||
dataStrings, err = htmlScrapeBTCMarkets(htmlData)
|
||||
case pathEXMO:
|
||||
@@ -963,41 +960,6 @@ loop:
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// htmlScrapeItBit gets the check string for ItBit Exchange
|
||||
func htmlScrapeItBit(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
var resp []string
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer temp.Body.Close()
|
||||
tokenizer := html.NewTokenizer(temp.Body)
|
||||
loop:
|
||||
for {
|
||||
next := tokenizer.Next()
|
||||
switch next {
|
||||
case html.ErrorToken:
|
||||
break loop
|
||||
case html.StartTagToken:
|
||||
token := tokenizer.Token()
|
||||
if token.Data == htmlData.TokenData {
|
||||
for _, z := range token.Attr {
|
||||
if z.Key == htmlData.Key {
|
||||
r, err := regexp.Compile(htmlData.RegExp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if r.MatchString(z.Val) {
|
||||
resp = append(resp, z.Val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// htmlScrapeBitstamp gets the check string for Bitstamp Exchange
|
||||
func htmlScrapeBitstamp(htmlData *HTMLScrapingData) ([]string, error) {
|
||||
temp, err := sendHTTPGetRequest(htmlData.Path, nil)
|
||||
|
||||
@@ -317,21 +317,6 @@ func TestHTMLPoloniex(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTMLItBit(t *testing.T) {
|
||||
t.Parallel()
|
||||
data := HTMLScrapingData{TokenData: "a",
|
||||
Key: "href",
|
||||
Val: "changelog",
|
||||
TokenDataEnd: "div",
|
||||
TextTokenData: "h2",
|
||||
DateFormat: "2006-01-02",
|
||||
RegExp: `^https://api.itbit.com/v\d{1}/$`,
|
||||
Path: "https://api.itbit.com/docs"}
|
||||
if _, err := htmlScrapeItBit(&data); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTMLScrapeExmo(t *testing.T) {
|
||||
t.Parallel()
|
||||
data := HTMLScrapingData{RegExp: `Last updated on [\s\S]*, 20\d{2}`,
|
||||
|
||||
@@ -169,20 +169,6 @@
|
||||
},
|
||||
"Disabled": false
|
||||
},
|
||||
{
|
||||
"Name": "ItBit",
|
||||
"CheckType": "HTML String Check",
|
||||
"Data": {
|
||||
"HTMLData": {
|
||||
"TokenData": "a",
|
||||
"Key": "href",
|
||||
"RegExp": "^https://api.itbit.com/v\\d{1}/$",
|
||||
"CheckString": "https://api.itbit.com/v1/",
|
||||
"Path": "https://api.itbit.com/docs"
|
||||
}
|
||||
},
|
||||
"Disabled": false
|
||||
},
|
||||
{
|
||||
"Name": "Bitmex",
|
||||
"CheckType": "HTML String Check",
|
||||
|
||||
@@ -169,20 +169,6 @@
|
||||
},
|
||||
"Disabled": false
|
||||
},
|
||||
{
|
||||
"Name": "ItBit",
|
||||
"CheckType": "HTML String Check",
|
||||
"Data": {
|
||||
"HTMLData": {
|
||||
"TokenData": "a",
|
||||
"Key": "href",
|
||||
"RegExp": "^https://api.itbit.com/v\\d{1}/$",
|
||||
"CheckString": "https://api.itbit.com/v1/",
|
||||
"Path": "https://api.itbit.com/docs"
|
||||
}
|
||||
},
|
||||
"Disabled": false
|
||||
},
|
||||
{
|
||||
"Name": "Bitmex",
|
||||
"CheckType": "HTML String Check",
|
||||
|
||||
@@ -59,7 +59,6 @@ _b in this context is an `IBotExchange` implemented struct_
|
||||
| Gemini | Yes | Yes | Yes |
|
||||
| HitBTC | Yes | Yes | Yes |
|
||||
| Huobi.Pro | Yes | Yes | No |
|
||||
| ItBit | Yes | NA | No |
|
||||
| Kraken | Yes | Yes | No |
|
||||
| Kucoin | Yes | No | Yes |
|
||||
| Lbank | Yes | No | Yes |
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
{{define "exchanges itbit" -}}
|
||||
{{template "header" .}}
|
||||
## Itbit Exchange
|
||||
|
||||
### Current Features
|
||||
|
||||
+ REST Support
|
||||
|
||||
### How to enable
|
||||
|
||||
+ [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example)
|
||||
|
||||
+ Individual package example below:
|
||||
|
||||
```go
|
||||
// Exchanges will be abstracted out in further updates and examples will be
|
||||
// supplied then
|
||||
```
|
||||
|
||||
### How to do REST public/private calls
|
||||
|
||||
+ If enabled via "configuration".json file the exchange will be added to the
|
||||
IBotExchange array in the ```go var bot Bot``` and you will only be able to use
|
||||
the wrapper interface functions for accessing exchange data. View routines.go
|
||||
for an example of integration usage with GoCryptoTrader. Rudimentary example
|
||||
below:
|
||||
|
||||
main.go
|
||||
```go
|
||||
var i exchange.IBotExchange
|
||||
|
||||
for x := range bot.Exchanges {
|
||||
if bot.Exchanges[x].GetName() == "Itbit" {
|
||||
i = bot.Exchanges[x]
|
||||
}
|
||||
}
|
||||
|
||||
// Public calls - wrapper functions
|
||||
|
||||
// Fetches current ticker information
|
||||
tick, err := i.FetchTicker()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Fetches current orderbook information
|
||||
ob, err := i.FetchOrderbook()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
|
||||
// set and AuthenticatedAPISupport is set to true
|
||||
|
||||
// Fetches current account information
|
||||
accountInfo, err := i.GetAccountInfo()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
```
|
||||
|
||||
+ If enabled via individually importing package, rudimentary example below:
|
||||
|
||||
```go
|
||||
// Public calls
|
||||
|
||||
// Fetches current ticker information
|
||||
ticker, err := i.GetTicker()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Fetches current orderbook information
|
||||
ob, err := i.GetOrderBook()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Private calls - make sure your APIKEY and APISECRET are set and
|
||||
// AuthenticatedAPISupport is set to true
|
||||
|
||||
// GetUserInfo returns account info
|
||||
accountInfo, err := i.GetUserInfo(...)
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Submits an order and the exchange and returns its tradeID
|
||||
tradeID, err := i.Trade(...)
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
```
|
||||
|
||||
### Please click GoDocs chevron above to view current GoDoc information for this package
|
||||
{{template "contributions"}}
|
||||
{{template "donations" .}}
|
||||
{{end}}
|
||||
@@ -37,7 +37,6 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
|
||||
| Gemini | Yes | Yes | No |
|
||||
| HitBTC | Yes | Yes | No |
|
||||
| Huobi.Pro | Yes | Yes | NA |
|
||||
| ItBit | Yes | NA | No |
|
||||
| Kraken | Yes | Yes | NA |
|
||||
| Kucoin | Yes | Yes | NA |
|
||||
| Lbank | Yes | No | NA |
|
||||
|
||||
@@ -34,10 +34,6 @@ func main() {
|
||||
var wg sync.WaitGroup
|
||||
for i := range exchange.Exchanges {
|
||||
name := exchange.Exchanges[i]
|
||||
if name == "ftx" {
|
||||
log.Println("Skipping exchange FTX...")
|
||||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
@@ -602,7 +602,6 @@ var unsupportedExchangeNames = []string{
|
||||
"testexch",
|
||||
"alphapoint",
|
||||
"bitflyer", // Bitflyer has many "ErrNotYetImplemented, which is true, but not what we care to test for here
|
||||
"itbit", // itbit has no way of retrieving pair data
|
||||
"btse", // TODO rm once timeout issues resolved
|
||||
"poloniex", // outdated API // TODO rm once updated
|
||||
}
|
||||
|
||||
@@ -1919,81 +1919,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ITBIT",
|
||||
"enabled": true,
|
||||
"verbose": false,
|
||||
"httpTimeout": 15000000000,
|
||||
"websocketResponseCheckTimeout": 30000000,
|
||||
"websocketResponseMaxLimit": 7000000000,
|
||||
"websocketTrafficTimeout": 30000000000,
|
||||
"websocketOrderbookBufferLimit": 5,
|
||||
"baseCurrencies": "USD,SGD",
|
||||
"currencyPairs": {
|
||||
"requestFormat": {
|
||||
"uppercase": true
|
||||
},
|
||||
"configFormat": {
|
||||
"uppercase": true
|
||||
},
|
||||
"useGlobalFormat": true,
|
||||
"lastUpdated": 1591062026,
|
||||
"assetTypes": [
|
||||
"spot"
|
||||
],
|
||||
"pairs": {
|
||||
"spot": {
|
||||
"enabled": "XBTUSD,XBTSGD",
|
||||
"available": "XBTUSD,XBTSGD"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api": {
|
||||
"authenticatedSupport": false,
|
||||
"authenticatedWebsocketApiSupport": false,
|
||||
"endpoints": {
|
||||
"url": "NON_DEFAULT_HTTP_LINK_TO_EXCHANGE_API",
|
||||
"urlSecondary": "NON_DEFAULT_HTTP_LINK_TO_EXCHANGE_API",
|
||||
"websocketURL": "NON_DEFAULT_HTTP_LINK_TO_WEBSOCKET_EXCHANGE_API"
|
||||
},
|
||||
"credentials": {
|
||||
"key": "Key",
|
||||
"secret": "Secret",
|
||||
"clientID": "ClientID"
|
||||
},
|
||||
"credentialsValidator": {
|
||||
"requiresSecret": true,
|
||||
"requiresClientID": true
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"supports": {
|
||||
"restAPI": true,
|
||||
"restCapabilities": {},
|
||||
"websocketAPI": false,
|
||||
"websocketCapabilities": {}
|
||||
},
|
||||
"enabled": {
|
||||
"autoPairUpdates": false,
|
||||
"websocketAPI": false
|
||||
}
|
||||
},
|
||||
"bankAccounts": [
|
||||
{
|
||||
"enabled": false,
|
||||
"bankName": "",
|
||||
"bankAddress": "",
|
||||
"bankPostalCode": "",
|
||||
"bankPostalCity": "",
|
||||
"bankCountry": "",
|
||||
"accountName": "",
|
||||
"accountNumber": "",
|
||||
"swiftCode": "",
|
||||
"iban": "",
|
||||
"supportedCurrencies": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Kraken",
|
||||
"enabled": true,
|
||||
|
||||
@@ -213,7 +213,6 @@ Yes means supported, No means not yet implemented and NA means protocol unsuppor
|
||||
| Gemini | Yes | Yes | No |
|
||||
| HitBTC | Yes | Yes | No |
|
||||
| Huobi.Pro | Yes | Yes | NA |
|
||||
| ItBit | Yes | NA | No |
|
||||
| Kraken | Yes | Yes | NA |
|
||||
| Kucoin | Yes | Yes | No |
|
||||
| Lbank | Yes | No | NA |
|
||||
@@ -243,7 +242,6 @@ var Exchanges = []string{
|
||||
"gemini",
|
||||
"hitbtc",
|
||||
"huobi",
|
||||
"itbit",
|
||||
"kraken",
|
||||
"kucoin",
|
||||
"lbank",
|
||||
|
||||
@@ -60,7 +60,6 @@ $ ./gctcli withdrawcryptofunds --exchange=binance --currency=USDT --address=TJU9
|
||||
| Gemini | No | No | |
|
||||
| HitBTC | No | No | |
|
||||
| Huobi.Pro | Yes | Yes | |
|
||||
| ItBit | No | No | |
|
||||
| Kraken | Yes | Yes | Front-end and API don't match total available transfer chains |
|
||||
| Kucoin | Yes | Yes | |
|
||||
| Lbank | No | No | |
|
||||
|
||||
@@ -81,8 +81,7 @@ A helper tool [cmd/dbseed](../cmd/dbseed/README.md) has been created for assisti
|
||||
| GateIO | Y |
|
||||
| Gemini | |
|
||||
| HitBTC | Y |
|
||||
| Huobi | Y |
|
||||
| itBIT | |
|
||||
| Huobi | Y |
|
||||
| Kraken | Y |
|
||||
| Kucoin | Y |
|
||||
| lBank | Y |
|
||||
|
||||
@@ -355,7 +355,6 @@ func TestSettingsPrint(t *testing.T) {
|
||||
}
|
||||
|
||||
var unsupportedDefaultConfigExchanges = []string{
|
||||
"itbit", // due to unsupported API
|
||||
"poloniex", // poloniex has dropped support for the API GCT has implemented //TODO: drop this when supported
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/gemini"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/hitbtc"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/huobi"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/itbit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kraken"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kucoin"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/lbank"
|
||||
@@ -1028,8 +1027,6 @@ func NewSupportedExchangeByName(name string) (exchange.IBotExchange, error) {
|
||||
return new(hitbtc.HitBTC), nil
|
||||
case "huobi":
|
||||
return new(huobi.HUOBI), nil
|
||||
case "itbit":
|
||||
return new(itbit.ItBit), nil
|
||||
case "kraken":
|
||||
return new(kraken.Kraken), nil
|
||||
case "kucoin":
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
# GoCryptoTrader package Itbit
|
||||
|
||||
<img src="/common/gctlogo.png?raw=true" width="350px" height="350px" hspace="70">
|
||||
|
||||
|
||||
[](https://github.com/thrasher-corp/gocryptotrader/actions/workflows/tests.yml)
|
||||
[](https://github.com/thrasher-corp/gocryptotrader/blob/master/LICENSE)
|
||||
[](https://godoc.org/github.com/thrasher-corp/gocryptotrader/exchanges/itbit)
|
||||
[](http://codecov.io/github/thrasher-corp/gocryptotrader?branch=master)
|
||||
[](https://goreportcard.com/report/github.com/thrasher-corp/gocryptotrader)
|
||||
|
||||
|
||||
This itbit package is part of the GoCryptoTrader codebase.
|
||||
|
||||
## This is still in active development
|
||||
|
||||
You can track ideas, planned features and what's in progress on this Trello board: [https://trello.com/b/ZAhMhpOy/gocryptotrader](https://trello.com/b/ZAhMhpOy/gocryptotrader).
|
||||
|
||||
Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader Slack](https://join.slack.com/t/gocryptotrader/shared_invite/enQtNTQ5NDAxMjA2Mjc5LTc5ZDE1ZTNiOGM3ZGMyMmY1NTAxYWZhODE0MWM5N2JlZDk1NDU0YTViYzk4NTk3OTRiMDQzNGQ1YTc4YmRlMTk)
|
||||
|
||||
## Itbit Exchange
|
||||
|
||||
### Current Features
|
||||
|
||||
+ REST Support
|
||||
|
||||
### How to enable
|
||||
|
||||
+ [Enable via configuration](https://github.com/thrasher-corp/gocryptotrader/tree/master/config#enable-exchange-via-config-example)
|
||||
|
||||
+ Individual package example below:
|
||||
|
||||
```go
|
||||
// Exchanges will be abstracted out in further updates and examples will be
|
||||
// supplied then
|
||||
```
|
||||
|
||||
### How to do REST public/private calls
|
||||
|
||||
+ If enabled via "configuration".json file the exchange will be added to the
|
||||
IBotExchange array in the ```go var bot Bot``` and you will only be able to use
|
||||
the wrapper interface functions for accessing exchange data. View routines.go
|
||||
for an example of integration usage with GoCryptoTrader. Rudimentary example
|
||||
below:
|
||||
|
||||
main.go
|
||||
```go
|
||||
var i exchange.IBotExchange
|
||||
|
||||
for x := range bot.Exchanges {
|
||||
if bot.Exchanges[x].GetName() == "Itbit" {
|
||||
i = bot.Exchanges[x]
|
||||
}
|
||||
}
|
||||
|
||||
// Public calls - wrapper functions
|
||||
|
||||
// Fetches current ticker information
|
||||
tick, err := i.FetchTicker()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Fetches current orderbook information
|
||||
ob, err := i.FetchOrderbook()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
|
||||
// set and AuthenticatedAPISupport is set to true
|
||||
|
||||
// Fetches current account information
|
||||
accountInfo, err := i.GetAccountInfo()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
```
|
||||
|
||||
+ If enabled via individually importing package, rudimentary example below:
|
||||
|
||||
```go
|
||||
// Public calls
|
||||
|
||||
// Fetches current ticker information
|
||||
ticker, err := i.GetTicker()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Fetches current orderbook information
|
||||
ob, err := i.GetOrderBook()
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Private calls - make sure your APIKEY and APISECRET are set and
|
||||
// AuthenticatedAPISupport is set to true
|
||||
|
||||
// GetUserInfo returns account info
|
||||
accountInfo, err := i.GetUserInfo(...)
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
|
||||
// Submits an order and the exchange and returns its tradeID
|
||||
tradeID, err := i.Trade(...)
|
||||
if err != nil {
|
||||
// Handle error
|
||||
}
|
||||
```
|
||||
|
||||
### Please click GoDocs chevron above to view current GoDoc information for this package
|
||||
|
||||
## Contribution
|
||||
|
||||
Please feel free to submit any pull requests or suggest any desired features to be added.
|
||||
|
||||
When submitting a PR, please abide by our coding guidelines:
|
||||
|
||||
+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
|
||||
+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
|
||||
+ Code must adhere to our [coding style](https://github.com/thrasher-corp/gocryptotrader/blob/master/doc/coding_style.md).
|
||||
+ Pull requests need to be based on and opened against the `master` branch.
|
||||
|
||||
## Donations
|
||||
|
||||
<img src="https://github.com/thrasher-corp/gocryptotrader/blob/master/web/src/assets/donate.png?raw=true" hspace="70">
|
||||
|
||||
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
|
||||
|
||||
***bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc***
|
||||
@@ -1,443 +0,0 @@
|
||||
package itbit
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/crypto"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
)
|
||||
|
||||
const (
|
||||
itbitAPIURL = "https://api.itbit.com/v1"
|
||||
itbitAPIVersion = "1"
|
||||
itbitMarkets = "markets"
|
||||
itbitOrderbook = "order_book"
|
||||
itbitTicker = "ticker"
|
||||
itbitWallets = "wallets"
|
||||
itbitBalances = "balances"
|
||||
itbitTrades = "trades"
|
||||
itbitFundingHistory = "funding_history"
|
||||
itbitOrders = "orders"
|
||||
itbitCryptoDeposits = "cryptocurrency_deposits"
|
||||
itbitWalletTransfer = "wallet_transfers"
|
||||
)
|
||||
|
||||
// ItBit is the overarching type across the ItBit package
|
||||
type ItBit struct {
|
||||
exchange.Base
|
||||
}
|
||||
|
||||
// GetTicker returns ticker info for a specified market.
|
||||
// currencyPair - example "XBTUSD" "XBTSGD" "XBTEUR"
|
||||
func (i *ItBit) GetTicker(ctx context.Context, currencyPair string) (Ticker, error) {
|
||||
var response Ticker
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitMarkets, currencyPair, itbitTicker)
|
||||
|
||||
return response, i.SendHTTPRequest(ctx, exchange.RestSpot, path, &response)
|
||||
}
|
||||
|
||||
// GetOrderbook returns full order book for the specified market.
|
||||
// currencyPair - example "XBTUSD" "XBTSGD" "XBTEUR"
|
||||
func (i *ItBit) GetOrderbook(ctx context.Context, currencyPair string) (*OrderbookResponse, error) {
|
||||
response := OrderbookResponse{}
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitMarkets, currencyPair, itbitOrderbook)
|
||||
|
||||
return &response, i.SendHTTPRequest(ctx, exchange.RestSpot, path, &response)
|
||||
}
|
||||
|
||||
// GetTradeHistory returns recent trades for a specified market.
|
||||
//
|
||||
// currencyPair - example "XBTUSD" "XBTSGD" "XBTEUR"
|
||||
// timestamp - matchNumber, only executions after this will be returned
|
||||
func (i *ItBit) GetTradeHistory(ctx context.Context, currencyPair, tradeID string) (Trades, error) {
|
||||
response := Trades{}
|
||||
|
||||
var req = itbitTrades
|
||||
if tradeID != "" {
|
||||
req += "?since=" + tradeID
|
||||
}
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitMarkets, currencyPair, req)
|
||||
|
||||
return response, i.SendHTTPRequest(ctx, exchange.RestSpot, path, &response)
|
||||
}
|
||||
|
||||
// GetWallets returns information about all wallets associated with the account.
|
||||
//
|
||||
// params --
|
||||
//
|
||||
// page - [optional] page to return example 1. default 1
|
||||
// perPage - [optional] items per page example 50, default 50 max 50
|
||||
func (i *ItBit) GetWallets(ctx context.Context, params url.Values) ([]Wallet, error) {
|
||||
creds, err := i.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resp []Wallet
|
||||
params.Set("userId", creds.ClientID)
|
||||
path := fmt.Sprintf("/%s?%s", itbitWallets, params.Encode())
|
||||
return resp, i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
}
|
||||
|
||||
// CreateWallet creates a new wallet with a specified name.
|
||||
func (i *ItBit) CreateWallet(ctx context.Context, walletName string) (Wallet, error) {
|
||||
creds, err := i.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return Wallet{}, err
|
||||
}
|
||||
resp := Wallet{}
|
||||
params := make(map[string]interface{})
|
||||
params["userId"] = creds.ClientID
|
||||
params["name"] = walletName
|
||||
|
||||
err = i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, "/"+itbitWallets, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetWallet returns wallet information by walletID
|
||||
func (i *ItBit) GetWallet(ctx context.Context, walletID string) (Wallet, error) {
|
||||
resp := Wallet{}
|
||||
path := fmt.Sprintf("/%s/%s", itbitWallets, walletID)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetWalletBalance returns balance information for a specific currency in a
|
||||
// wallet.
|
||||
func (i *ItBit) GetWalletBalance(ctx context.Context, walletID, currency string) (Balance, error) {
|
||||
resp := Balance{}
|
||||
path := fmt.Sprintf("/%s/%s/%s/%s", itbitWallets, walletID, itbitBalances, currency)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetOrders returns active orders for itBit
|
||||
// perPage defaults to & has a limit of 50
|
||||
func (i *ItBit) GetOrders(ctx context.Context, walletID, symbol, status string, page, perPage int64) ([]Order, error) {
|
||||
var resp []Order
|
||||
params := make(map[string]interface{})
|
||||
params["walletID"] = walletID
|
||||
|
||||
if symbol != "" {
|
||||
params["instrument"] = symbol
|
||||
}
|
||||
if status != "" {
|
||||
params["status"] = status
|
||||
}
|
||||
if page > 0 {
|
||||
params["page"] = strconv.FormatInt(page, 10)
|
||||
}
|
||||
if perPage > 0 {
|
||||
params["perPage"] = strconv.FormatInt(perPage, 10)
|
||||
}
|
||||
|
||||
return resp, i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, itbitOrders, params, &resp)
|
||||
}
|
||||
|
||||
// GetWalletTrades returns all trades for a specified wallet.
|
||||
func (i *ItBit) GetWalletTrades(ctx context.Context, walletID string, params url.Values) (Records, error) {
|
||||
resp := Records{}
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitTrades)
|
||||
path := common.EncodeURLValues(urlPath, params)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetFundingHistoryForWallet returns all funding history for a specified wallet.
|
||||
func (i *ItBit) GetFundingHistoryForWallet(ctx context.Context, walletID string, params url.Values) (FundingRecords, error) {
|
||||
resp := FundingRecords{}
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitFundingHistory)
|
||||
path := common.EncodeURLValues(urlPath, params)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// PlaceOrder places a new order
|
||||
func (i *ItBit) PlaceOrder(ctx context.Context, walletID, side, orderType, currency string, amount, price float64, instrument, clientRef string) (Order, error) {
|
||||
resp := Order{}
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitOrders)
|
||||
|
||||
params := make(map[string]interface{})
|
||||
params["side"] = side
|
||||
params["type"] = orderType
|
||||
params["currency"] = currency
|
||||
params["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
|
||||
params["price"] = strconv.FormatFloat(price, 'f', -1, 64)
|
||||
params["instrument"] = instrument
|
||||
|
||||
if clientRef != "" {
|
||||
params["clientOrderIdentifier"] = clientRef
|
||||
}
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, path, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetOrder returns an order by id.
|
||||
func (i *ItBit) GetOrder(ctx context.Context, walletID string, params url.Values) (Order, error) {
|
||||
resp := Order{}
|
||||
urlPath := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitOrders)
|
||||
path := common.EncodeURLValues(urlPath, params)
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodGet, path, nil, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// CancelExistingOrder cancels and open order. *This is not a guarantee that the
|
||||
// order has been cancelled!*
|
||||
func (i *ItBit) CancelExistingOrder(ctx context.Context, walletID, orderID string) error {
|
||||
path := fmt.Sprintf("/%s/%s/%s/%s", itbitWallets, walletID, itbitOrders, orderID)
|
||||
|
||||
return i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodDelete, path, nil, nil)
|
||||
}
|
||||
|
||||
// GetCryptoDepositAddress returns a deposit address to send cryptocurrency to.
|
||||
func (i *ItBit) GetCryptoDepositAddress(ctx context.Context, walletID, currency string) (CryptoCurrencyDeposit, error) {
|
||||
resp := CryptoCurrencyDeposit{}
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitCryptoDeposits)
|
||||
params := make(map[string]interface{})
|
||||
params["currency"] = currency
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, path, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// WalletTransfer transfers funds between wallets.
|
||||
func (i *ItBit) WalletTransfer(ctx context.Context, walletID, sourceWallet, destWallet string, amount float64, currency string) (WalletTransfer, error) {
|
||||
resp := WalletTransfer{}
|
||||
path := fmt.Sprintf("/%s/%s/%s", itbitWallets, walletID, itbitWalletTransfer)
|
||||
|
||||
params := make(map[string]interface{})
|
||||
params["sourceWalletId"] = sourceWallet
|
||||
params["destinationWalletId"] = destWallet
|
||||
params["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
|
||||
params["currencyCode"] = currency
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest(ctx, exchange.RestSpot, http.MethodPost, path, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
if resp.Description != "" {
|
||||
return resp, errors.New(resp.Description)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (i *ItBit) SendHTTPRequest(ctx context.Context, ep exchange.URL, path string, result interface{}) error {
|
||||
endpoint, err := i.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
item := &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: endpoint + path,
|
||||
Result: result,
|
||||
Verbose: i.Verbose,
|
||||
HTTPDebugging: i.HTTPDebugging,
|
||||
HTTPRecording: i.HTTPRecording,
|
||||
}
|
||||
|
||||
return i.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
}, request.UnauthenticatedRequest)
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated request to itBit
|
||||
func (i *ItBit) SendAuthenticatedHTTPRequest(ctx context.Context, ep exchange.URL, method, path string, params map[string]interface{}, result interface{}) error {
|
||||
creds, err := i.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
endpoint, err := i.API.Endpoints.GetURL(ep)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req := make(map[string]interface{})
|
||||
urlPath := endpoint + path
|
||||
|
||||
for key, value := range params {
|
||||
req[key] = value
|
||||
}
|
||||
|
||||
PayloadJSON := []byte("")
|
||||
if params != nil {
|
||||
PayloadJSON, err = json.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
var intermediary json.RawMessage
|
||||
err = i.SendPayload(ctx, request.Unset, func() (*request.Item, error) {
|
||||
n := i.Requester.GetNonce(true).String()
|
||||
timestamp := strconv.FormatInt(time.Now().UnixMilli(), 10)
|
||||
|
||||
var message []byte
|
||||
message, err = json.Marshal([]string{method, urlPath, string(PayloadJSON), n, timestamp})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var hash []byte
|
||||
hash, err = crypto.GetSHA256([]byte(n + string(message)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var hmac []byte
|
||||
hmac, err = crypto.GetHMAC(crypto.HashSHA512,
|
||||
[]byte(urlPath+string(hash)),
|
||||
[]byte(creds.Secret))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
signature := crypto.Base64Encode(hmac)
|
||||
|
||||
headers := make(map[string]string)
|
||||
headers["Authorization"] = creds.ClientID + ":" + signature
|
||||
headers["X-Auth-Timestamp"] = timestamp
|
||||
headers["X-Auth-Nonce"] = n
|
||||
headers["Content-Type"] = "application/json"
|
||||
|
||||
return &request.Item{
|
||||
Method: method,
|
||||
Path: urlPath,
|
||||
Headers: headers,
|
||||
Body: bytes.NewBuffer(PayloadJSON),
|
||||
Result: &intermediary,
|
||||
NonceEnabled: true,
|
||||
Verbose: i.Verbose,
|
||||
HTTPDebugging: i.HTTPDebugging,
|
||||
HTTPRecording: i.HTTPRecording,
|
||||
}, nil
|
||||
}, request.AuthenticatedRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
errCheck := struct {
|
||||
Code int `json:"code"`
|
||||
Description string `json:"description"`
|
||||
RequestID string `json:"requestId"`
|
||||
}{}
|
||||
err = json.Unmarshal(intermediary, &errCheck)
|
||||
if err == nil {
|
||||
if errCheck.Code != 0 || errCheck.Description != "" {
|
||||
return fmt.Errorf("sendAuthRequest error code: %d description: %s",
|
||||
errCheck.Code,
|
||||
errCheck.Description)
|
||||
}
|
||||
}
|
||||
return json.Unmarshal(intermediary, result)
|
||||
}
|
||||
|
||||
// GetFee returns an estimate of fee based on type of transaction
|
||||
func (i *ItBit) GetFee(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
var fee float64
|
||||
switch feeBuilder.FeeType {
|
||||
case exchange.CryptocurrencyTradeFee:
|
||||
fee = calculateTradingFee(feeBuilder.PurchasePrice, feeBuilder.Amount, feeBuilder.IsMaker)
|
||||
case exchange.InternationalBankWithdrawalFee:
|
||||
fee = getInternationalBankWithdrawalFee(feeBuilder.FiatCurrency, feeBuilder.BankTransactionType)
|
||||
case exchange.OfflineTradeFee:
|
||||
fee = getOfflineTradeFee(feeBuilder.PurchasePrice, feeBuilder.Amount)
|
||||
}
|
||||
|
||||
if fee < 0 {
|
||||
fee = 0
|
||||
}
|
||||
|
||||
return fee, nil
|
||||
}
|
||||
|
||||
// getOfflineTradeFee calculates the worst case-scenario trading fee
|
||||
func getOfflineTradeFee(price, amount float64) float64 {
|
||||
return 0.0035 * price * amount
|
||||
}
|
||||
|
||||
func calculateTradingFee(purchasePrice, amount float64, isMaker bool) float64 {
|
||||
// TODO: Itbit has volume discounts, but not API endpoint to get the exact volume numbers
|
||||
// When support is added, this needs to be updated to calculate the accurate volume fee
|
||||
feePercent := 0.0035
|
||||
if isMaker {
|
||||
feePercent = -0.0003
|
||||
}
|
||||
return feePercent * purchasePrice * amount
|
||||
}
|
||||
|
||||
func getInternationalBankWithdrawalFee(c currency.Code, bankTransactionType exchange.InternationalBankTransactionType) float64 {
|
||||
var fee float64
|
||||
if (bankTransactionType == exchange.Swift ||
|
||||
bankTransactionType == exchange.WireTransfer) &&
|
||||
c.Equal(currency.USD) {
|
||||
fee = 40
|
||||
} else if (bankTransactionType == exchange.SEPA ||
|
||||
bankTransactionType == exchange.WireTransfer) &&
|
||||
c.Equal(currency.EUR) {
|
||||
fee = 1
|
||||
}
|
||||
return fee
|
||||
}
|
||||
@@ -1,457 +0,0 @@
|
||||
package itbit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var i = &ItBit{}
|
||||
|
||||
// Please provide your own keys to do proper testing
|
||||
const (
|
||||
apiKey = ""
|
||||
apiSecret = ""
|
||||
clientID = ""
|
||||
canManipulateRealOrders = false
|
||||
)
|
||||
|
||||
func TestMain(_ *testing.M) {
|
||||
fmt.Println("ItBit API deprecated, skipping tests")
|
||||
}
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := i.GetTicker(context.Background(), "XBTUSD")
|
||||
if err != nil {
|
||||
t.Error("GetTicker() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderbook(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := i.GetOrderbook(context.Background(), "XBTUSD")
|
||||
if err != nil {
|
||||
t.Error("GetOrderbook() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTradeHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := i.GetTradeHistory(context.Background(), "XBTUSD", "0")
|
||||
if err != nil {
|
||||
t.Error("GetTradeHistory() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWallets(t *testing.T) {
|
||||
_, err := i.GetWallets(context.Background(), url.Values{})
|
||||
if err == nil {
|
||||
t.Error("GetWallets() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateWallet(t *testing.T) {
|
||||
_, err := i.CreateWallet(context.Background(), "test")
|
||||
if err == nil {
|
||||
t.Error("CreateWallet() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWallet(t *testing.T) {
|
||||
_, err := i.GetWallet(context.Background(), "1337")
|
||||
if err == nil {
|
||||
t.Error("GetWallet() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWalletBalance(t *testing.T) {
|
||||
_, err := i.GetWalletBalance(context.Background(), "1337", "XRT")
|
||||
if err == nil {
|
||||
t.Error("GetWalletBalance() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWalletTrades(t *testing.T) {
|
||||
_, err := i.GetWalletTrades(context.Background(), "1337", url.Values{})
|
||||
if err == nil {
|
||||
t.Error("GetWalletTrades() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFundingHistory(t *testing.T) {
|
||||
_, err := i.GetFundingHistoryForWallet(context.Background(), "1337", url.Values{})
|
||||
if err == nil {
|
||||
t.Error("GetAccountFundingHistory() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaceOrder(t *testing.T) {
|
||||
_, err := i.PlaceOrder(context.Background(),
|
||||
"1337", order.Buy.Lower(),
|
||||
order.Limit.Lower(), "USD", 1, 0.2, "banjo",
|
||||
"sauce")
|
||||
if err == nil {
|
||||
t.Error("PlaceOrder() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrder(t *testing.T) {
|
||||
_, err := i.GetOrder(context.Background(), "1337", url.Values{})
|
||||
if err == nil {
|
||||
t.Error("GetOrder() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelExistingOrder(t *testing.T) {
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, i, canManipulateRealOrders)
|
||||
|
||||
err := i.CancelExistingOrder(context.Background(), "1337", "1337order")
|
||||
if err == nil {
|
||||
t.Error("CancelOrder() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCryptoDepositAddress(t *testing.T) {
|
||||
_, err := i.GetCryptoDepositAddress(context.Background(), "1337", "AUD")
|
||||
if err == nil {
|
||||
t.Error("GetCryptoDepositAddress() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWalletTransfer(t *testing.T) {
|
||||
_, err := i.WalletTransfer(context.Background(),
|
||||
"1337", "mywallet", "anotherwallet", 200, "USD")
|
||||
if err == nil {
|
||||
t.Error("WalletTransfer() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func setFeeBuilder() *exchange.FeeBuilder {
|
||||
return &exchange.FeeBuilder{
|
||||
Amount: 1,
|
||||
FeeType: exchange.CryptocurrencyTradeFee,
|
||||
Pair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
||||
currency.LTC.String(),
|
||||
"_"),
|
||||
PurchasePrice: 1,
|
||||
FiatCurrency: currency.USD,
|
||||
BankTransactionType: exchange.WireTransfer,
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetFeeByTypeOfflineTradeFee logic test
|
||||
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
var feeBuilder = setFeeBuilder()
|
||||
_, err := i.GetFeeByType(context.Background(), feeBuilder)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !sharedtestvalues.AreAPICredentialsSet(i) {
|
||||
if feeBuilder.FeeType != exchange.OfflineTradeFee {
|
||||
t.Errorf("Expected %v, received %v", exchange.OfflineTradeFee, feeBuilder.FeeType)
|
||||
}
|
||||
} else {
|
||||
if feeBuilder.FeeType != exchange.CryptocurrencyTradeFee {
|
||||
t.Errorf("Expected %v, received %v", exchange.CryptocurrencyTradeFee, feeBuilder.FeeType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
t.Parallel()
|
||||
var feeBuilder = setFeeBuilder()
|
||||
// CryptocurrencyTradeFee Basic
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyTradeFee High quantity
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.Amount = 1000
|
||||
feeBuilder.PurchasePrice = 1000
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyTradeFee IsMaker
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.IsMaker = true
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyTradeFee Negative purchase price
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.PurchasePrice = -1000
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
// CryptocurrencyWithdrawalFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyWithdrawalFee Invalid currency
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.Pair.Base = currency.NewCode("hello")
|
||||
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// CryptocurrencyDepositFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.CryptocurrencyDepositFee
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// InternationalBankDepositFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.InternationalBankDepositFee
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
// InternationalBankWithdrawalFee Basic
|
||||
feeBuilder = setFeeBuilder()
|
||||
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
|
||||
feeBuilder.FiatCurrency = currency.USD
|
||||
if _, err := i.GetFee(feeBuilder); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
expectedResult := exchange.WithdrawCryptoViaWebsiteOnlyText + " & " + exchange.WithdrawFiatViaWebsiteOnlyText
|
||||
withdrawPermissions := i.FormatWithdrawPermissions()
|
||||
if withdrawPermissions != expectedResult {
|
||||
t.Errorf("Expected: %s, Received: %s", expectedResult, withdrawPermissions)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = order.MultiOrderRequest{
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
Side: order.AnySide,
|
||||
}
|
||||
|
||||
_, err := i.GetActiveOrders(context.Background(), &getOrdersRequest)
|
||||
if sharedtestvalues.AreAPICredentialsSet(i) && err != nil {
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(i) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var getOrdersRequest = order.MultiOrderRequest{
|
||||
Type: order.AnyType,
|
||||
AssetType: asset.Spot,
|
||||
Side: order.AnySide,
|
||||
}
|
||||
|
||||
_, err := i.GetOrderHistory(context.Background(), &getOrdersRequest)
|
||||
if sharedtestvalues.AreAPICredentialsSet(i) && err != nil {
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(i) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
|
||||
// ----------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, i, canManipulateRealOrders)
|
||||
|
||||
var orderSubmission = &order.Submit{
|
||||
Exchange: i.Name,
|
||||
Pair: currency.Pair{
|
||||
Base: currency.BTC,
|
||||
Quote: currency.USD,
|
||||
},
|
||||
Side: order.Buy,
|
||||
Type: order.Limit,
|
||||
Price: 1,
|
||||
Amount: 1,
|
||||
ClientID: "meowOrder",
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
response, err := i.SubmitOrder(context.Background(), orderSubmission)
|
||||
if sharedtestvalues.AreAPICredentialsSet(i) && (err != nil || response.Status != order.New) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !sharedtestvalues.AreAPICredentialsSet(i) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, i, canManipulateRealOrders)
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: core.BitcoinDonationAddress,
|
||||
AccountID: "1",
|
||||
Pair: currencyPair,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
err := i.CancelOrder(context.Background(), orderCancellation)
|
||||
|
||||
if !sharedtestvalues.AreAPICredentialsSet(i) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if sharedtestvalues.AreAPICredentialsSet(i) && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, i, canManipulateRealOrders)
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: core.BitcoinDonationAddress,
|
||||
AccountID: "1",
|
||||
Pair: currencyPair,
|
||||
AssetType: asset.Spot,
|
||||
}
|
||||
|
||||
resp, err := i.CancelAllOrders(context.Background(), orderCancellation)
|
||||
|
||||
if !sharedtestvalues.AreAPICredentialsSet(i) && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if sharedtestvalues.AreAPICredentialsSet(i) && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
|
||||
if len(resp.Status) > 0 {
|
||||
t.Errorf("%v orders failed to cancel", len(resp.Status))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAccountInfo(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, i)
|
||||
|
||||
_, err := i.UpdateAccountInfo(context.Background(), asset.Spot)
|
||||
if err == nil {
|
||||
t.Error("GetAccountInfo() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, i, canManipulateRealOrders)
|
||||
|
||||
_, err := i.ModifyOrder(context.Background(), &order.Modify{AssetType: asset.Spot})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, i, canManipulateRealOrders)
|
||||
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Exchange: i.Name,
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := i.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&withdrawCryptoRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected 'Not supported', received %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, i, canManipulateRealOrders)
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := i.WithdrawFiatFunds(context.Background(),
|
||||
&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCannotManipulateOrders(t, i, canManipulateRealOrders)
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := i.WithdrawFiatFundsToInternationalBank(context.Background(),
|
||||
&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
_, err := i.GetDepositAddress(context.Background(), currency.BTC, "", "")
|
||||
if err == nil {
|
||||
t.Error("GetDepositAddress() error cannot be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRecentTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
currencyPair, err := currency.NewPairFromString("XBTUSD")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = i.GetRecentTrades(context.Background(), currencyPair, asset.Spot)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHistoricTrades(t *testing.T) {
|
||||
t.Parallel()
|
||||
currencyPair, err := currency.NewPairFromString("XBTUSD")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = i.GetHistoricTrades(context.Background(),
|
||||
currencyPair, asset.Spot, time.Now().Add(-time.Minute*15), time.Now())
|
||||
if err != nil && err != common.ErrFunctionNotSupported {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
package itbit
|
||||
|
||||
import "time"
|
||||
|
||||
// GeneralReturn is a generalized return type to capture any errors
|
||||
type GeneralReturn struct {
|
||||
Code int `json:"code"`
|
||||
Description string `json:"description"`
|
||||
RequestID string `json:"requestId"`
|
||||
}
|
||||
|
||||
// Ticker holds returned ticker information
|
||||
type Ticker struct {
|
||||
Pair string `json:"pair"`
|
||||
Bid float64 `json:"bid,string"`
|
||||
BidAmt float64 `json:"bidAmt,string"`
|
||||
Ask float64 `json:"ask,string"`
|
||||
AskAmt float64 `json:"askAmt,string"`
|
||||
LastPrice float64 `json:"lastPrice,string"`
|
||||
LastAmt float64 `json:"lastAmt,string"`
|
||||
Volume24h float64 `json:"volume24h,string"`
|
||||
VolumeToday float64 `json:"volumeToday,string"`
|
||||
High24h float64 `json:"high24h,string"`
|
||||
Low24h float64 `json:"low24h,string"`
|
||||
HighToday float64 `json:"highToday,string"`
|
||||
LowToday float64 `json:"lowToday,string"`
|
||||
OpenToday float64 `json:"openToday,string"`
|
||||
VwapToday float64 `json:"vwapToday,string"`
|
||||
Vwap24h float64 `json:"vwap24h,string"`
|
||||
ServertimeUTC time.Time `json:"serverTimeUTC"`
|
||||
}
|
||||
|
||||
// OrderbookResponse contains multi-arrayed strings of bid and ask side
|
||||
// information
|
||||
type OrderbookResponse struct {
|
||||
Bids [][]string `json:"bids"`
|
||||
Asks [][]string `json:"asks"`
|
||||
}
|
||||
|
||||
// Trades holds recent trades with associated information
|
||||
type Trades struct {
|
||||
RecentTrades []struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
MatchNumber string `json:"matchNumber"`
|
||||
Price float64 `json:"price,string"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
} `json:"recentTrades"`
|
||||
}
|
||||
|
||||
// Wallet contains specific wallet information
|
||||
type Wallet struct {
|
||||
ID string `json:"id"`
|
||||
UserID string `json:"userId"`
|
||||
Name string `json:"name"`
|
||||
Balances []Balance `json:"balances"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Balance is a sub type holding balance information
|
||||
type Balance struct {
|
||||
Currency string `json:"currency"`
|
||||
AvailableBalance float64 `json:"availableBalance,string"`
|
||||
TotalBalance float64 `json:"totalBalance,string"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// Records embodies records of trade history information
|
||||
type Records struct {
|
||||
TotalNumberOfRecords int `json:"totalNumberOfRecords,string"`
|
||||
CurrentPageNumber int `json:"currentPageNumber,string"`
|
||||
LatestExecutedID int64 `json:"latestExecutionId,string"`
|
||||
RecordsPerPage int `json:"recordsPerPage,string"`
|
||||
TradingHistory []TradeHistory `json:"tradingHistory"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// TradeHistory stores historic trade values
|
||||
type TradeHistory struct {
|
||||
OrderID string `json:"orderId"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
Instrument string `json:"instrument"`
|
||||
Direction string `json:"direction"`
|
||||
CurrencyOne string `json:"currency1"`
|
||||
CurrencyOneAmount float64 `json:"currency1Amount,string"`
|
||||
CurrencyTwo string `json:"currency2"`
|
||||
CurrencyTwoAmount float64 `json:"currency2Amount"`
|
||||
Rate float64 `json:"rate,string"`
|
||||
CommissionPaid float64 `json:"commissionPaid,string"`
|
||||
CommissionCurrency string `json:"commissionCurrency"`
|
||||
RebatesApplied float64 `json:"rebatesApplied,string"`
|
||||
RebateCurrency string `json:"rebateCurrency"`
|
||||
}
|
||||
|
||||
// FundingRecords embodies records of fund history information
|
||||
type FundingRecords struct {
|
||||
TotalNumberOfRecords int `json:"totalNumberOfRecords,string"`
|
||||
CurrentPageNumber int `json:"currentPageNumber,string"`
|
||||
LatestExecutedID int64 `json:"latestExecutionId,string"`
|
||||
RecordsPerPage int `json:"recordsPerPage,string"`
|
||||
FundingHistory []FundHistory `json:"fundingHistory"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// FundHistory stores historic funding transactions
|
||||
type FundHistory struct {
|
||||
BankName string `json:"bankName"`
|
||||
WithdrawalID int64 `json:"withdrawalId"`
|
||||
HoldingPeriodCompletionDate string `json:"holdingPeriodCompletionDate"`
|
||||
DestinationAddress string `json:"destinationAddress"`
|
||||
TxnHash string `json:"txnHash"`
|
||||
Time string `json:"time"`
|
||||
Currency string `json:"currency"`
|
||||
TransactionType string `json:"transactionType"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
WalletName string `json:"walletName"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// Order holds order information
|
||||
type Order struct {
|
||||
ID string `json:"id"`
|
||||
WalletID string `json:"walletId"`
|
||||
Side string `json:"side"`
|
||||
Instrument string `json:"instrument"`
|
||||
Type string `json:"type"`
|
||||
Currency string `json:"currency"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Price float64 `json:"price,string"`
|
||||
AmountFilled float64 `json:"amountFilled,string"`
|
||||
VolumeWeightedAveragePrice float64 `json:"volumeWeightedAveragePrice,string"`
|
||||
CreatedTime string `json:"createdTime"`
|
||||
Status string `json:"Status"`
|
||||
Metadata interface{} `json:"metadata"`
|
||||
ClientOrderIdentifier string `json:"clientOrderIdentifier"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// CryptoCurrencyDeposit holds information about a new wallet
|
||||
type CryptoCurrencyDeposit struct {
|
||||
ID int `json:"id"`
|
||||
WalletID string `json:"walletID"`
|
||||
DepositAddress string `json:"depositAddress"`
|
||||
Metadata interface{} `json:"metadata"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// WalletTransfer holds wallet transfer information
|
||||
type WalletTransfer struct {
|
||||
SourceWalletID string `json:"sourceWalletId"`
|
||||
DestinationWalletID string `json:"destinationWalletId"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
CurrencyCode string `json:"currencyCode"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
@@ -1,690 +0,0 @@
|
||||
package itbit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/deposit"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/fundingrate"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/futures"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
func (i *ItBit) GetDefaultConfig(ctx context.Context) (*config.Exchange, error) {
|
||||
i.SetDefaults()
|
||||
exchCfg, err := i.GetStandardConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = i.SetupDefaults(exchCfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if i.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
||||
err = i.UpdateTradablePairs(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return exchCfg, nil
|
||||
}
|
||||
|
||||
// SetDefaults sets the defaults for the exchange
|
||||
func (i *ItBit) SetDefaults() {
|
||||
i.Name = "ITBIT"
|
||||
i.Enabled = true
|
||||
i.Verbose = true
|
||||
i.API.CredentialsValidator.RequiresClientID = true
|
||||
i.API.CredentialsValidator.RequiresSecret = true
|
||||
|
||||
requestFmt := ¤cy.PairFormat{Uppercase: true}
|
||||
configFmt := ¤cy.PairFormat{Uppercase: true}
|
||||
err := i.SetGlobalPairsManager(requestFmt, configFmt, asset.Spot)
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
|
||||
i.Features = exchange.Features{
|
||||
Supports: exchange.FeaturesSupported{
|
||||
REST: true,
|
||||
RESTCapabilities: protocol.Features{
|
||||
TickerFetching: true,
|
||||
TradeFetching: true,
|
||||
OrderbookFetching: true,
|
||||
AccountInfo: true,
|
||||
GetOrder: true,
|
||||
GetOrders: true,
|
||||
CancelOrder: true,
|
||||
SubmitOrder: true,
|
||||
DepositHistory: true,
|
||||
WithdrawalHistory: true,
|
||||
UserTradeHistory: true,
|
||||
CryptoDeposit: true,
|
||||
TradeFee: true,
|
||||
FiatWithdrawalFee: true,
|
||||
},
|
||||
WithdrawPermissions: exchange.WithdrawCryptoViaWebsiteOnly |
|
||||
exchange.WithdrawFiatViaWebsiteOnly,
|
||||
},
|
||||
}
|
||||
|
||||
i.Requester, err = request.New(i.Name,
|
||||
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
i.API.Endpoints = i.NewEndpoints()
|
||||
err = i.API.Endpoints.SetDefaultEndpoints(map[exchange.URL]string{
|
||||
exchange.RestSpot: itbitAPIURL,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorln(log.ExchangeSys, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Setup sets the exchange parameters from exchange config
|
||||
func (i *ItBit) Setup(exch *config.Exchange) error {
|
||||
if err := exch.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if !exch.Enabled {
|
||||
i.SetEnabled(false)
|
||||
return nil
|
||||
}
|
||||
return i.SetupDefaults(exch)
|
||||
}
|
||||
|
||||
// GetServerTime returns the current exchange server time.
|
||||
func (i *ItBit) GetServerTime(_ context.Context, _ asset.Item) (time.Time, error) {
|
||||
return time.Time{}, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
||||
func (i *ItBit) FetchTradablePairs(_ context.Context, _ asset.Item) (currency.Pairs, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// UpdateTradablePairs updates the exchanges available pairs and stores
|
||||
// them in the exchanges config
|
||||
func (i *ItBit) UpdateTradablePairs(_ context.Context, _ bool) error {
|
||||
return common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// UpdateTickers updates the ticker for all currency pairs of a given asset type
|
||||
func (i *ItBit) UpdateTickers(_ context.Context, _ asset.Item) error {
|
||||
return common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
func (i *ItBit) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error) {
|
||||
fPair, err := i.FormatExchangeCurrency(p, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tick, err := i.GetTicker(ctx, fPair.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = ticker.ProcessTicker(&ticker.Price{
|
||||
Last: tick.LastPrice,
|
||||
High: tick.High24h,
|
||||
Low: tick.Low24h,
|
||||
Bid: tick.Bid,
|
||||
Ask: tick.Ask,
|
||||
Volume: tick.Volume24h,
|
||||
Open: tick.OpenToday,
|
||||
Pair: p,
|
||||
LastUpdated: tick.ServertimeUTC,
|
||||
ExchangeName: i.Name,
|
||||
AssetType: a})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ticker.GetTicker(i.Name, p, a)
|
||||
}
|
||||
|
||||
// FetchTicker returns the ticker for a currency pair
|
||||
func (i *ItBit) FetchTicker(ctx context.Context, p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
||||
tickerNew, err := ticker.GetTicker(i.Name, p, assetType)
|
||||
if err != nil {
|
||||
return i.UpdateTicker(ctx, p, assetType)
|
||||
}
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
// FetchOrderbook returns orderbook base on the currency pair
|
||||
func (i *ItBit) FetchOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
ob, err := orderbook.Get(i.Name, p, assetType)
|
||||
if err != nil {
|
||||
return i.UpdateOrderbook(ctx, p, assetType)
|
||||
}
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (i *ItBit) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
if p.IsEmpty() {
|
||||
return nil, currency.ErrCurrencyPairEmpty
|
||||
}
|
||||
if err := i.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
book := &orderbook.Base{
|
||||
Exchange: i.Name,
|
||||
Pair: p,
|
||||
Asset: assetType,
|
||||
PriceDuplication: true,
|
||||
VerifyOrderbook: i.CanVerifyOrderbook,
|
||||
}
|
||||
fPair, err := i.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
|
||||
orderbookNew, err := i.GetOrderbook(ctx, fPair.String())
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
|
||||
book.Bids = make(orderbook.Items, len(orderbookNew.Bids))
|
||||
for x := range orderbookNew.Bids {
|
||||
var price, amount float64
|
||||
price, err = strconv.ParseFloat(orderbookNew.Bids[x][0], 64)
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
amount, err = strconv.ParseFloat(orderbookNew.Bids[x][1], 64)
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
book.Bids[x] = orderbook.Item{
|
||||
Amount: amount,
|
||||
Price: price,
|
||||
}
|
||||
}
|
||||
|
||||
book.Asks = make(orderbook.Items, len(orderbookNew.Asks))
|
||||
for x := range orderbookNew.Asks {
|
||||
var price, amount float64
|
||||
price, err = strconv.ParseFloat(orderbookNew.Asks[x][0], 64)
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
amount, err = strconv.ParseFloat(orderbookNew.Asks[x][1], 64)
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
book.Asks[x] = orderbook.Item{
|
||||
Amount: amount,
|
||||
Price: price,
|
||||
}
|
||||
}
|
||||
err = book.Process()
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
return orderbook.Get(i.Name, p, assetType)
|
||||
}
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies
|
||||
func (i *ItBit) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
var info account.Holdings
|
||||
info.Exchange = i.Name
|
||||
|
||||
wallets, err := i.GetWallets(ctx, url.Values{})
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
var amounts = make(map[string]*account.Balance)
|
||||
|
||||
for x := range wallets {
|
||||
for _, cb := range wallets[x].Balances {
|
||||
if _, ok := amounts[cb.Currency]; !ok {
|
||||
amounts[cb.Currency] = &account.Balance{}
|
||||
}
|
||||
|
||||
amounts[cb.Currency].Total += cb.TotalBalance
|
||||
amounts[cb.Currency].Hold += cb.TotalBalance - cb.AvailableBalance
|
||||
amounts[cb.Currency].Free += cb.AvailableBalance
|
||||
}
|
||||
}
|
||||
|
||||
fullBalance := make([]account.Balance, 0, len(amounts))
|
||||
for key := range amounts {
|
||||
fullBalance = append(fullBalance, account.Balance{
|
||||
Currency: currency.NewCode(key),
|
||||
Total: amounts[key].Total,
|
||||
Hold: amounts[key].Hold,
|
||||
Free: amounts[key].Free,
|
||||
})
|
||||
}
|
||||
|
||||
info.Accounts = append(info.Accounts, account.SubAccount{
|
||||
AssetType: assetType,
|
||||
Currencies: fullBalance,
|
||||
})
|
||||
|
||||
creds, err := i.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
}
|
||||
err = account.Process(&info, creds)
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
// FetchAccountInfo retrieves balances for all enabled currencies
|
||||
func (i *ItBit) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error) {
|
||||
creds, err := i.GetCredentials(ctx)
|
||||
if err != nil {
|
||||
return account.Holdings{}, err
|
||||
}
|
||||
acc, err := account.GetHoldings(i.Name, creds, assetType)
|
||||
if err != nil {
|
||||
return i.UpdateAccountInfo(ctx, assetType)
|
||||
}
|
||||
return acc, nil
|
||||
}
|
||||
|
||||
// GetAccountFundingHistory returns funding history, deposits and
|
||||
// withdrawals
|
||||
func (i *ItBit) GetAccountFundingHistory(_ context.Context) ([]exchange.FundingHistory, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWithdrawalsHistory returns previous withdrawals data
|
||||
func (i *ItBit) GetWithdrawalsHistory(_ context.Context, _ currency.Code, _ asset.Item) ([]exchange.WithdrawalHistory, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetRecentTrades returns the most recent trades for a currency and asset
|
||||
func (i *ItBit) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
||||
var err error
|
||||
p, err = i.FormatExchangeCurrency(p, assetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var tradeData Trades
|
||||
tradeData, err = i.GetTradeHistory(ctx, p.String(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := make([]trade.Data, len(tradeData.RecentTrades))
|
||||
for x := range tradeData.RecentTrades {
|
||||
resp[x] = trade.Data{
|
||||
Exchange: i.Name,
|
||||
TID: tradeData.RecentTrades[x].MatchNumber,
|
||||
CurrencyPair: p,
|
||||
AssetType: assetType,
|
||||
Price: tradeData.RecentTrades[x].Price,
|
||||
Amount: tradeData.RecentTrades[x].Amount,
|
||||
Timestamp: tradeData.RecentTrades[x].Timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
err = i.AddTradesToBuffer(resp...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Sort(trade.ByDate(resp))
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetHistoricTrades returns historic trade data within the timeframe provided
|
||||
func (i *ItBit) GetHistoricTrades(_ context.Context, _ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
||||
// cannot do time based retrieval of trade data
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// SubmitOrder submits a new order
|
||||
func (i *ItBit) SubmitOrder(ctx context.Context, s *order.Submit) (*order.SubmitResponse, error) {
|
||||
if err := s.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var wallet string
|
||||
wallets, err := i.GetWallets(ctx, url.Values{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Determine what wallet ID to use if there is any actual available currency to make the trade!
|
||||
for i := range wallets {
|
||||
for j := range wallets[i].Balances {
|
||||
if wallets[i].Balances[j].Currency == s.Pair.Base.String() &&
|
||||
wallets[i].Balances[j].AvailableBalance >= s.Amount {
|
||||
wallet = wallets[i].ID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if wallet == "" {
|
||||
return nil,
|
||||
fmt.Errorf("no wallet found with currency: %s with amount >= %v",
|
||||
s.Pair.Base,
|
||||
s.Amount)
|
||||
}
|
||||
|
||||
fPair, err := i.FormatExchangeCurrency(s.Pair, s.AssetType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response, err := i.PlaceOrder(ctx,
|
||||
wallet,
|
||||
s.Side.String(),
|
||||
s.Type.String(),
|
||||
fPair.Base.String(),
|
||||
s.Amount,
|
||||
s.Price,
|
||||
fPair.String(),
|
||||
"")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subResp, err := s.DeriveSubmitResponse(response.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if response.AmountFilled == s.Amount {
|
||||
subResp.Status = order.Filled
|
||||
}
|
||||
return subResp, nil
|
||||
}
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
// market conversion
|
||||
func (i *ItBit) ModifyOrder(_ context.Context, _ *order.Modify) (*order.ModifyResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// CancelOrder cancels an order by its corresponding ID number
|
||||
func (i *ItBit) CancelOrder(ctx context.Context, o *order.Cancel) error {
|
||||
if err := o.Validate(o.StandardCancel()); err != nil {
|
||||
return err
|
||||
}
|
||||
return i.CancelExistingOrder(ctx, o.WalletAddress, o.OrderID)
|
||||
}
|
||||
|
||||
// CancelBatchOrders cancels an orders by their corresponding ID numbers
|
||||
func (i *ItBit) CancelBatchOrders(_ context.Context, _ []order.Cancel) (*order.CancelBatchResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (i *ItBit) CancelAllOrders(ctx context.Context, orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
||||
if err := orderCancellation.Validate(); err != nil {
|
||||
return order.CancelAllResponse{}, err
|
||||
}
|
||||
cancelAllOrdersResponse := order.CancelAllResponse{
|
||||
Status: make(map[string]string),
|
||||
}
|
||||
openOrders, err := i.GetOrders(ctx,
|
||||
orderCancellation.WalletAddress,
|
||||
"",
|
||||
"open",
|
||||
0,
|
||||
0)
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
|
||||
for j := range openOrders {
|
||||
err = i.CancelExistingOrder(ctx,
|
||||
orderCancellation.WalletAddress,
|
||||
openOrders[j].ID)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.Status[openOrders[j].ID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns order information based on order ID
|
||||
func (i *ItBit) GetOrderInfo(_ context.Context, _ string, _ currency.Pair, _ asset.Item) (*order.Detail, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetDepositAddress returns a deposit address for a specified currency
|
||||
// NOTE: This has not been implemented due to the fact you need to generate a
|
||||
// specific wallet ID, and they restrict the amount of deposit addresses you can
|
||||
// request limiting them to 2.
|
||||
func (i *ItBit) GetDepositAddress(_ context.Context, _ currency.Code, _, _ string) (*deposit.Address, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (i *ItBit) WithdrawCryptocurrencyFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (i *ItBit) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (i *ItBit) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetFeeByType returns an estimate of fee based on type of transaction
|
||||
func (i *ItBit) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBuilder) (float64, error) {
|
||||
if feeBuilder == nil {
|
||||
return 0, fmt.Errorf("%T %w", feeBuilder, common.ErrNilPointer)
|
||||
}
|
||||
if !i.AreCredentialsValid(ctx) && // Todo check connection status
|
||||
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
|
||||
feeBuilder.FeeType = exchange.OfflineTradeFee
|
||||
}
|
||||
return i.GetFee(feeBuilder)
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (i *ItBit) GetActiveOrders(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wallets, err := i.GetWallets(ctx, url.Values{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var allOrders []Order
|
||||
for x := range wallets {
|
||||
var resp []Order
|
||||
resp, err = i.GetOrders(ctx, wallets[x].ID, "", "open", 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allOrders = append(allOrders, resp...)
|
||||
}
|
||||
|
||||
format, err := i.GetPairFormat(asset.Spot, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orders := make([]order.Detail, 0, len(allOrders))
|
||||
for j := range allOrders {
|
||||
var symbol currency.Pair
|
||||
symbol, err = currency.NewPairDelimiter(allOrders[j].Instrument,
|
||||
format.Delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(allOrders[j].Side)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", i.Name, err)
|
||||
}
|
||||
var orderDate time.Time
|
||||
orderDate, err = time.Parse(time.RFC3339, allOrders[j].CreatedTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
i.Name,
|
||||
"GetActiveOrders",
|
||||
allOrders[j].ID,
|
||||
allOrders[j].CreatedTime)
|
||||
}
|
||||
|
||||
orders = append(orders, order.Detail{
|
||||
OrderID: allOrders[j].ID,
|
||||
Side: side,
|
||||
Amount: allOrders[j].Amount,
|
||||
ExecutedAmount: allOrders[j].AmountFilled,
|
||||
RemainingAmount: allOrders[j].Amount - allOrders[j].AmountFilled,
|
||||
Exchange: i.Name,
|
||||
Date: orderDate,
|
||||
Pair: symbol,
|
||||
})
|
||||
}
|
||||
return req.Filter(i.Name, orders), nil
|
||||
}
|
||||
|
||||
// GetOrderHistory retrieves account order information
|
||||
// Can Limit response to specific order status
|
||||
func (i *ItBit) GetOrderHistory(ctx context.Context, req *order.MultiOrderRequest) (order.FilteredOrders, error) {
|
||||
err := req.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wallets, err := i.GetWallets(ctx, url.Values{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var allOrders []Order
|
||||
for x := range wallets {
|
||||
var resp []Order
|
||||
resp, err = i.GetOrders(ctx, wallets[x].ID, "", "", 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
allOrders = append(allOrders, resp...)
|
||||
}
|
||||
|
||||
format, err := i.GetPairFormat(asset.Spot, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
orders := make([]order.Detail, 0, len(allOrders))
|
||||
for j := range allOrders {
|
||||
if allOrders[j].Type == "open" {
|
||||
continue
|
||||
}
|
||||
var symbol currency.Pair
|
||||
symbol, err = currency.NewPairDelimiter(allOrders[j].Instrument,
|
||||
format.Delimiter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var side order.Side
|
||||
side, err = order.StringToOrderSide(allOrders[j].Side)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", i.Name, err)
|
||||
}
|
||||
var status order.Status
|
||||
status, err = order.StringToOrderStatus(allOrders[j].Status)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%s %v", i.Name, err)
|
||||
}
|
||||
var orderDate time.Time
|
||||
orderDate, err = time.Parse(time.RFC3339, allOrders[j].CreatedTime)
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys,
|
||||
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
||||
i.Name,
|
||||
"GetActiveOrders",
|
||||
allOrders[j].ID,
|
||||
allOrders[j].CreatedTime)
|
||||
}
|
||||
|
||||
detail := order.Detail{
|
||||
OrderID: allOrders[j].ID,
|
||||
Side: side,
|
||||
Status: status,
|
||||
Amount: allOrders[j].Amount,
|
||||
ExecutedAmount: allOrders[j].AmountFilled,
|
||||
RemainingAmount: allOrders[j].Amount - allOrders[j].AmountFilled,
|
||||
Price: allOrders[j].Price,
|
||||
AverageExecutedPrice: allOrders[j].VolumeWeightedAveragePrice,
|
||||
Exchange: i.Name,
|
||||
Date: orderDate,
|
||||
Pair: symbol,
|
||||
}
|
||||
detail.InferCostsAndTimes()
|
||||
orders = append(orders, detail)
|
||||
}
|
||||
return req.Filter(i.Name, orders), nil
|
||||
}
|
||||
|
||||
// ValidateAPICredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (i *ItBit) ValidateAPICredentials(ctx context.Context, assetType asset.Item) error {
|
||||
_, err := i.UpdateAccountInfo(ctx, assetType)
|
||||
return i.CheckTransientError(err)
|
||||
}
|
||||
|
||||
// GetHistoricCandles returns candles between a time period for a set time interval
|
||||
func (i *ItBit) GetHistoricCandles(_ context.Context, _ currency.Pair, _ asset.Item, _ kline.Interval, _, _ time.Time) (*kline.Item, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
|
||||
func (i *ItBit) GetHistoricCandlesExtended(_ context.Context, _ currency.Pair, _ asset.Item, _ kline.Interval, _, _ time.Time) (*kline.Item, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetFuturesContractDetails returns all contracts from the exchange by asset type
|
||||
func (i *ItBit) GetFuturesContractDetails(context.Context, asset.Item) ([]futures.Contract, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetLatestFundingRates returns the latest funding rates data
|
||||
func (i *ItBit) GetLatestFundingRates(context.Context, *fundingrate.LatestRateRequest) ([]fundingrate.LatestRateResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// UpdateOrderExecutionLimits updates order execution limits
|
||||
func (i *ItBit) UpdateOrderExecutionLimits(_ context.Context, _ asset.Item) error {
|
||||
return common.ErrNotYetImplemented
|
||||
}
|
||||
@@ -31,7 +31,6 @@ var Exchanges = []string{
|
||||
"gemini",
|
||||
"hitbtc",
|
||||
"huobi",
|
||||
"itbit",
|
||||
"kraken",
|
||||
"kucoin",
|
||||
"lbank",
|
||||
|
||||
@@ -77,7 +77,6 @@ _b in this context is an `IBotExchange` implemented struct_
|
||||
| Gemini | Yes | Yes | Yes |
|
||||
| HitBTC | Yes | Yes | Yes |
|
||||
| Huobi.Pro | Yes | Yes | No |
|
||||
| ItBit | Yes | NA | No |
|
||||
| Kraken | Yes | Yes | No |
|
||||
| Kucoin | Yes | No | Yes |
|
||||
| Lbank | Yes | No | Yes |
|
||||
|
||||
75
testdata/configtest.json
vendored
75
testdata/configtest.json
vendored
@@ -1791,81 +1791,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "ITBIT",
|
||||
"enabled": true,
|
||||
"verbose": false,
|
||||
"httpTimeout": 15000000000,
|
||||
"websocketResponseCheckTimeout": 30000000,
|
||||
"websocketResponseMaxLimit": 7000000000,
|
||||
"websocketTrafficTimeout": 30000000000,
|
||||
"websocketOrderbookBufferLimit": 5,
|
||||
"baseCurrencies": "USD,SGD",
|
||||
"currencyPairs": {
|
||||
"requestFormat": {
|
||||
"uppercase": true
|
||||
},
|
||||
"configFormat": {
|
||||
"uppercase": true
|
||||
},
|
||||
"useGlobalFormat": true,
|
||||
"lastUpdated": 1591062026,
|
||||
"assetTypes": [
|
||||
"spot"
|
||||
],
|
||||
"pairs": {
|
||||
"spot": {
|
||||
"enabled": "XBTUSD,XBTSGD",
|
||||
"available": "XBTUSD,XBTSGD"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api": {
|
||||
"authenticatedSupport": false,
|
||||
"authenticatedWebsocketApiSupport": false,
|
||||
"endpoints": {
|
||||
"url": "NON_DEFAULT_HTTP_LINK_TO_EXCHANGE_API",
|
||||
"urlSecondary": "NON_DEFAULT_HTTP_LINK_TO_EXCHANGE_API",
|
||||
"websocketURL": "NON_DEFAULT_HTTP_LINK_TO_WEBSOCKET_EXCHANGE_API"
|
||||
},
|
||||
"credentials": {
|
||||
"key": "Key",
|
||||
"secret": "Secret",
|
||||
"clientID": "ClientID"
|
||||
},
|
||||
"credentialsValidator": {
|
||||
"requiresSecret": true,
|
||||
"requiresClientID": true
|
||||
}
|
||||
},
|
||||
"features": {
|
||||
"supports": {
|
||||
"restAPI": true,
|
||||
"restCapabilities": {},
|
||||
"websocketAPI": false,
|
||||
"websocketCapabilities": {}
|
||||
},
|
||||
"enabled": {
|
||||
"autoPairUpdates": false,
|
||||
"websocketAPI": false
|
||||
}
|
||||
},
|
||||
"bankAccounts": [
|
||||
{
|
||||
"enabled": false,
|
||||
"bankName": "",
|
||||
"bankAddress": "",
|
||||
"bankPostalCode": "",
|
||||
"bankPostalCity": "",
|
||||
"bankCountry": "",
|
||||
"accountName": "",
|
||||
"accountNumber": "",
|
||||
"swiftCode": "",
|
||||
"iban": "",
|
||||
"supportedCurrencies": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Kraken",
|
||||
"enabled": true,
|
||||
|
||||
1
testdata/exchangelist.csv
vendored
1
testdata/exchangelist.csv
vendored
@@ -15,7 +15,6 @@ gateio,
|
||||
gemini,
|
||||
hitbtc,
|
||||
huobi,
|
||||
itbit,
|
||||
kraken,
|
||||
kucoin,
|
||||
lbank,
|
||||
|
||||
|
Reference in New Issue
Block a user