Skip to content

Commit

Permalink
Create exchange base struct
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Mar 29, 2017
1 parent 3edf81f commit ef59b4b
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 209 deletions.
13 changes: 2 additions & 11 deletions anxhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand All @@ -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 {
Expand Down
18 changes: 5 additions & 13 deletions bitfinexhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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() {
Expand Down
15 changes: 3 additions & 12 deletions bitstamphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 2 additions & 11 deletions btcchttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 3 additions & 12 deletions btcehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand All @@ -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 {
Expand Down
15 changes: 3 additions & 12 deletions btcmarkets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand All @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions exchanges/exchange.go
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 3 additions & 11 deletions gdaxhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand All @@ -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 {
Expand Down
12 changes: 2 additions & 10 deletions geminihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand All @@ -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 {
Expand Down
21 changes: 6 additions & 15 deletions huobihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()

Expand Down
23 changes: 7 additions & 16 deletions itbithttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
)

const (
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"
Expand Down
Loading

0 comments on commit ef59b4b

Please sign in to comment.