diff --git a/anxhttp.go b/anxhttp.go index dd7350c0138..8ff26387120 100644 --- a/anxhttp.go +++ b/anxhttp.go @@ -10,6 +10,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -27,17 +28,7 @@ const ( ) type ANX struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - APIKey, APISecret string - TakerFee, MakerFee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase } type ANXOrder struct { diff --git a/bitfinexhttp.go b/bitfinexhttp.go index a0f038b2bae..19ebcc88551 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -12,6 +12,7 @@ import ( "github.com/gorilla/websocket" "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -170,19 +171,10 @@ type BitfinexSymbolDetails struct { } type Bitfinex struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - APIKey, APISecret string - ActiveOrders []BitfinexOrder - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string - WebsocketConn *websocket.Conn - WebsocketSubdChannels map[int]BitfinexWebsocketChanInfo + exchange.ExchangeBase + ActiveOrders []BitfinexOrder + WebsocketConn *websocket.Conn + WebsocketSubdChannels map[int]BitfinexWebsocketChanInfo } func (b *Bitfinex) SetDefaults() { diff --git a/bitstamphttp.go b/bitstamphttp.go index f70000d8442..d04396c762d 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -12,6 +12,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -44,18 +45,8 @@ const ( ) type Bitstamp struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - ClientID, APIKey, APISecret string - Balance BitstampBalances - TakerFee, MakerFee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase + Balance BitstampBalances } type BitstampTicker struct { diff --git a/btcchttp.go b/btcchttp.go index 7be092ec6b2..a56cc4cdcf6 100644 --- a/btcchttp.go +++ b/btcchttp.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -42,17 +43,7 @@ const ( ) type BTCC struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - APISecret, APIKey string - Fee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase } type BTCCTicker struct { diff --git a/btcehttp.go b/btcehttp.go index 3db235167cf..963016bc150 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -35,18 +36,8 @@ const ( ) type BTCE struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - APIKey, APISecret string - Fee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string - Ticker map[string]BTCeTicker + exchange.ExchangeBase + Ticker map[string]BTCeTicker } type BTCeTicker struct { diff --git a/btcmarkets.go b/btcmarkets.go index 0ae65fd41af..3938e86554b 100644 --- a/btcmarkets.go +++ b/btcmarkets.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -26,18 +27,8 @@ const ( ) type BTCMarkets struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - Fee float64 - Ticker map[string]BTCMarketsTicker - AuthenticatedAPISupport bool - APIKey, APISecret string - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase + Ticker map[string]BTCMarketsTicker } type BTCMarketsTicker struct { diff --git a/exchanges/exchange.go b/exchanges/exchange.go new file mode 100644 index 00000000000..ef2c7232c94 --- /dev/null +++ b/exchanges/exchange.go @@ -0,0 +1,21 @@ +package exchange + +import ( + "time" +) + +type ExchangeBase struct { + Name string + Enabled bool + Verbose bool + Websocket bool + RESTPollingDelay time.Duration + AuthenticatedAPISupport bool + APISecret, APIKey, ClientID string + TakerFee, MakerFee, Fee float64 + BaseCurrencies []string + AvailablePairs []string + EnabledPairs []string + WebsocketURL string + APIUrl string +} diff --git a/gdaxhttp.go b/gdaxhttp.go index 9afb04d9694..aef0eeaa646 100644 --- a/gdaxhttp.go +++ b/gdaxhttp.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -33,17 +34,8 @@ const ( ) type GDAX struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - Password, APIKey, APISecret string - TakerFee, MakerFee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase + Password string } type GDAXTicker struct { diff --git a/geminihttp.go b/geminihttp.go index 686aa36b5eb..7d7367e090d 100644 --- a/geminihttp.go +++ b/geminihttp.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -35,16 +36,7 @@ const ( ) type Gemini struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - APIKey, APISecret string - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase } type GeminiOrderbookEntry struct { diff --git a/huobihttp.go b/huobihttp.go index 506c583d7be..b6427a4ab6b 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -10,6 +10,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -18,17 +19,7 @@ const ( ) type HUOBI struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - AccessKey, SecretKey string - Fee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase } type HuobiTicker struct { @@ -91,8 +82,8 @@ func (h *HUOBI) Start() { } func (h *HUOBI) SetAPIKeys(apiKey, apiSecret string) { - h.AccessKey = apiKey - h.SecretKey = apiSecret + h.APIKey = apiKey + h.APISecret = apiSecret } func (h *HUOBI) GetFee() float64 { @@ -281,10 +272,10 @@ func (h *HUOBI) GetOrderIDByTradeID(coinType, orderID int) { } func (h *HUOBI) SendAuthenticatedRequest(method string, v url.Values) error { - v.Set("access_key", h.AccessKey) + v.Set("access_key", h.APIKey) v.Set("created", strconv.FormatInt(time.Now().Unix(), 10)) v.Set("method", method) - hash := common.GetMD5([]byte(v.Encode() + "&secret_key=" + h.SecretKey)) + hash := common.GetMD5([]byte(v.Encode() + "&secret_key=" + h.APISecret)) v.Set("sign", common.StringToLower(common.HexEncodeToString(hash))) encoded := v.Encode() diff --git a/itbithttp.go b/itbithttp.go index c0909349b8d..c185020c773 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -10,6 +10,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -18,17 +19,7 @@ const ( ) type ItBit struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - ClientKey, APISecret, UserID string - MakerFee, TakerFee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase } type ItBitTicker struct { @@ -98,9 +89,9 @@ func (i *ItBit) Start() { } func (i *ItBit) SetAPIKeys(apiKey, apiSecret, userID string) { - i.ClientKey = apiKey + i.APIKey = apiKey i.APISecret = apiSecret - i.UserID = userID + i.ClientID = userID } func (i *ItBit) GetFee(maker bool) float64 { @@ -203,7 +194,7 @@ func (i *ItBit) GetTradeHistory(currency, timestamp string) bool { } func (i *ItBit) GetWallets(params url.Values) { - params.Set("userId", i.UserID) + params.Set("userId", i.ClientID) path := "/wallets?" + params.Encode() err := i.SendAuthenticatedHTTPRequest("GET", path, nil) @@ -224,7 +215,7 @@ func (e *ItBit) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { func (i *ItBit) CreateWallet(walletName string) { path := "/wallets" params := make(map[string]interface{}) - params["userId"] = i.UserID + params["userId"] = i.ClientID params["name"] = walletName err := i.SendAuthenticatedHTTPRequest("POST", path, params) @@ -394,7 +385,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params signature := common.Base64Encode(hmac) headers := make(map[string]string) - headers["Authorization"] = i.ClientKey + ":" + signature + headers["Authorization"] = i.ClientID + ":" + signature headers["X-Auth-Timestamp"] = timestamp headers["X-Auth-Nonce"] = nonceStr headers["Content-Type"] = "application/json" diff --git a/kraken.go b/kraken.go index 28dd4ebd0eb..7b0664897ba 100644 --- a/kraken.go +++ b/kraken.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -40,18 +41,9 @@ const ( ) type Kraken struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - ClientKey, APISecret string - FiatFee, CryptoFee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string - Ticker map[string]KrakenTicker + exchange.ExchangeBase + CryptoFee, FiatFee float64 + Ticker map[string]KrakenTicker } func (k *Kraken) SetDefaults() { @@ -102,7 +94,7 @@ func (k *Kraken) Start() { } func (k *Kraken) SetAPIKeys(apiKey, apiSecret string) { - k.ClientKey = apiKey + k.APIKey = apiKey k.APISecret = apiSecret } @@ -666,7 +658,7 @@ func (k *Kraken) SendAuthenticatedHTTPRequest(method string, values url.Values) } headers := make(map[string]string) - headers["API-Key"] = k.ClientKey + headers["API-Key"] = k.APIKey headers["API-Sign"] = signature resp, err := common.SendHTTPRequest("POST", KRAKEN_API_URL+path, headers, strings.NewReader(values.Encode())) diff --git a/lakebtchttp.go b/lakebtchttp.go index a0ecd32dd36..3e3a3829f83 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -10,6 +10,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -30,17 +31,7 @@ const ( ) type LakeBTC struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - APIKey, APISecret string - TakerFee, MakerFee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase } type LakeBTCTicker struct { diff --git a/liquihttp.go b/liquihttp.go index 7e77ef6bb63..f33edf9490a 100644 --- a/liquihttp.go +++ b/liquihttp.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -32,19 +33,9 @@ const ( ) type Liqui struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - APIKey, APISecret string - Fee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string - Ticker map[string]LiquiTicker - Info LiquiInfo + exchange.ExchangeBase + Ticker map[string]LiquiTicker + Info LiquiInfo } type LiquiTicker struct { diff --git a/localbitcoinshttp.go b/localbitcoinshttp.go index 8f409aec4b0..58923382ce8 100644 --- a/localbitcoinshttp.go +++ b/localbitcoinshttp.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -27,17 +28,7 @@ const ( ) type LocalBitcoins struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - Password, APIKey, APISecret string - TakerFee, MakerFee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase } func (l *LocalBitcoins) SetDefaults() { diff --git a/okcoinhttp.go b/okcoinhttp.go index 2b2c1fa07fa..b9c05ed732b 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -11,6 +11,7 @@ import ( "github.com/gorilla/websocket" "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -70,22 +71,11 @@ var ( ) type OKCoin struct { - Name string - Enabled bool - Verbose bool - Websocket bool - WebsocketURL string - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - APIUrl, PartnerID, SecretKey string - TakerFee, MakerFee float64 - RESTErrors map[string]string - WebsocketErrors map[string]string - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string - FuturesValues []string - WebsocketConn *websocket.Conn + exchange.ExchangeBase + RESTErrors map[string]string + WebsocketErrors map[string]string + FuturesValues []string + WebsocketConn *websocket.Conn } type OKCoinTicker struct { @@ -252,8 +242,8 @@ func (o *OKCoin) SetURL(url string) { } func (o *OKCoin) SetAPIKeys(apiKey, apiSecret string) { - o.PartnerID = apiKey - o.SecretKey = apiSecret + o.APIKey = apiKey + o.APISecret = apiSecret } func (o *OKCoin) GetFee(maker bool) float64 { @@ -1222,8 +1212,8 @@ func (o *OKCoin) GetFuturesUserPosition4Fix(symbol, contractType string) { } func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values, result interface{}) (err error) { - v.Set("api_key", o.PartnerID) - hasher := common.GetMD5([]byte(v.Encode() + "&secret_key=" + o.SecretKey)) + v.Set("api_key", o.APIKey) + hasher := common.GetMD5([]byte(v.Encode() + "&secret_key=" + o.APISecret)) v.Set("sign", strings.ToUpper(common.HexEncodeToString(hasher))) encoded := v.Encode() diff --git a/okcoinwebsocket.go b/okcoinwebsocket.go index 675fd047b14..fac2d58c04e 100644 --- a/okcoinwebsocket.go +++ b/okcoinwebsocket.go @@ -340,9 +340,9 @@ func (o *OKCoin) ConvertToURLValues(values map[string]string) url.Values { } func (o *OKCoin) WebsocketSign(values map[string]string) string { - values["api_key"] = o.PartnerID + values["api_key"] = o.APIKey urlVals := o.ConvertToURLValues(values) - return strings.ToUpper(common.HexEncodeToString(common.GetMD5([]byte(urlVals.Encode() + "&secret_key=" + o.SecretKey)))) + return strings.ToUpper(common.HexEncodeToString(common.GetMD5([]byte(urlVals.Encode() + "&secret_key=" + o.APISecret)))) } func (o *OKCoin) AddChannelAuthenticated(channel string, values map[string]string) { diff --git a/poloniexhttp.go b/poloniexhttp.go index dc74cd95d8a..ab2f4afa52d 100644 --- a/poloniexhttp.go +++ b/poloniexhttp.go @@ -11,6 +11,7 @@ import ( "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/config" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -46,17 +47,7 @@ const ( ) type Poloniex struct { - Name string - Enabled bool - Verbose bool - Websocket bool - RESTPollingDelay time.Duration - AuthenticatedAPISupport bool - AccessKey, SecretKey string - Fee float64 - BaseCurrencies []string - AvailablePairs []string - EnabledPairs []string + exchange.ExchangeBase } type PoloniexTicker struct { @@ -117,8 +108,8 @@ func (p *Poloniex) Start() { } func (p *Poloniex) SetAPIKeys(apiKey, apiSecret string) { - p.AccessKey = apiKey - p.SecretKey = apiSecret + p.APIKey = apiKey + p.APISecret = apiSecret } func (p *Poloniex) GetFee() float64 { @@ -1015,7 +1006,7 @@ func (p *Poloniex) ToggleAutoRenew(orderNumber int64) (bool, error) { func (p *Poloniex) SendAuthenticatedHTTPRequest(method, endpoint string, values url.Values, result interface{}) error { headers := make(map[string]string) headers["Content-Type"] = "application/x-www-form-urlencoded" - headers["Key"] = p.AccessKey + headers["Key"] = p.APIKey nonce := time.Now().UnixNano() nonceStr := strconv.FormatInt(nonce, 10) @@ -1023,7 +1014,7 @@ func (p *Poloniex) SendAuthenticatedHTTPRequest(method, endpoint string, values values.Set("nonce", nonceStr) values.Set("command", endpoint) - hmac := common.GetHMAC(common.HASH_SHA512, []byte(values.Encode()), []byte(p.SecretKey)) + hmac := common.GetHMAC(common.HASH_SHA512, []byte(values.Encode()), []byte(p.APISecret)) headers["Sign"] = common.HexEncodeToString(hmac) path := fmt.Sprintf("%s/%s", POLONIEX_API_URL, POLONIEX_API_TRADING_ENDPOINT)