mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
Added initial implementation for Cryptsy Exchange.
This commit is contained in:
@@ -122,7 +122,7 @@ func CalculateNetProfit(amount, priceThen, priceNow, costs float64) (float64) {
|
||||
func SendHTTPRequest(method, path string, headers map[string]string, body io.Reader) (string, error) {
|
||||
result := strings.ToUpper(method)
|
||||
|
||||
if result != "POST" && result != "GET" {
|
||||
if result != "POST" && result != "GET" && result != "DELETE" {
|
||||
return "", errors.New("Invalid HTTP method specified.")
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,17 @@
|
||||
"Verbose": false,
|
||||
"PollingDelay": 10
|
||||
},
|
||||
{
|
||||
"Name": "Cryptsy",
|
||||
"Pairs": "42BTC,42XRP,ACBTC,ACXRP,ACOINBTC,ADTLTC,AEROBTC,AEROXRP,AGSBTC,ALFBTC,ALNBTC,ALNXRP,AMCBTC,ANCBTC,ANCLTC,ANCXRP,APEXBTC,APEXXRP,ARCHBTC,ARGBTC,ARGXRP,ARIBTC,ASCLTC,AURBTC,AURLTC,AURXRP,AXRBTC,BATLTC,BCXBTC,BENBTC,BETBTC,BITBBTC,BLKBTC,BLKLTC,BLKXRP,BLUBTC,BLUXRP,BNCRBTC,BOSTBTC,BQCBTC,BTBBTC,BTBXRP,BTCUSD,BTCDBTC,BTCDXRP,BTEBTC,BTGBTC,BTGXRP,BTMBTC,BTMXRP,BUKBTC,CACHBTC,CAIxBTC,CANNBTC,CANNXRP,CAPBTC,CAPXRP,CASHBTC,CATBTC,CBXBTC,CBXLTC,CBXXRP,CCNBTC,CENTXRP,CINBTC,CINNIBTC,CKCBTC,CKCXRP,CLAMBTC,CLOAKBTC,CLOAKLTC,CLOAKXRP,CLRBTC,CLRXRP,CMCBTC,CNCBTC,CNCLTC,CNCXRP,CNLBTC,COLLTC,COLXRP,COMMBTC,COOLBTC,CPRLTC,CRACKBTC,CRACKXRP,CRAIGBTC,CRAIGXRP,CRCBTC,CRYPTBTC,C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TCBTC,UTCXRP,UTILBTC,VDOBTC,VIABTC,VIAXRP,VOOTBTC,VRCBTC,VRCLTC,VRCXRP,VTCBTC,VTCLTC,VTCXRP,WCBTC,WCXRP,WDCBTC,WDCLTC,WDCXRP,XAIBTC,XBOTBTC,XBOTXRP,XCBTC,XCLTC,XCXRP,XCASHBTC,XCRBTC,XCRXRP,XJOBTC,XLBBTC,XNCLTC,XPMBTC,XPMLTC,XPMXRP,XPYBTC,XPYUSD,XRPBTC,XRPUSD,XSTBTC,XSTXRP,XXXBTC,XXXXRP,YACBTC,YACLTC,YACXRP,YBCBTC,ZCCBTC,ZEDBTC,ZEITLTC,ZEITXRP,ZETBTC,ZETLTC,ZETXRP,ZRCBTC,ZRCUSD",
|
||||
"ClientID": "Password",
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"BaseCurrencies": "USD",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"PollingDelay": 10
|
||||
},
|
||||
{
|
||||
"Name": "Huobi",
|
||||
"Pairs": "BTCCNY,LTCCNY,LTCBTC",
|
||||
|
||||
462
cryptsyhttp.go
Normal file
462
cryptsyhttp.go
Normal file
@@ -0,0 +1,462 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
CRYPTSY_API_URL = "https://api.cryptsy.com/api/v2/"
|
||||
CRYPTSY_API_VERISON = "2"
|
||||
CRYPTSY_MARKETS = "markets"
|
||||
CRYPTSY_VOLUME = "volume"
|
||||
CRYPTSY_TICKER = "ticker"
|
||||
CRYPTSY_FEES = "fees"
|
||||
CRYPSTY_TRIGGERS = "triggers"
|
||||
CRYPTSY_CURRENCIES = "currencies"
|
||||
CRYPTSY_ORDERBOOK = "orderbook"
|
||||
CRYPTSY_TRADEHISTORY = "tradehistory"
|
||||
CRYPTSY_OHLC = "ohlc"
|
||||
CRYPTSY_INFO = "info"
|
||||
CRYPTSY_BALANCES = "balances"
|
||||
CRYPTSY_DEPOSITS = "deposits"
|
||||
CRYPTSY_ADDRESSES = "addresses"
|
||||
CRYPTSY_ORDER = "order"
|
||||
CRYPTSY_ORDERS = "orders"
|
||||
CRYPTSY_TRIGGERS = "triggers"
|
||||
)
|
||||
|
||||
type Cryptsy struct {
|
||||
Name string
|
||||
Enabled bool
|
||||
Verbose bool
|
||||
PollingDelay time.Duration
|
||||
APIKey, APISecret string
|
||||
TakerFee, MakerFee float64
|
||||
}
|
||||
|
||||
type CryptsyMarket struct {
|
||||
DayStats struct {
|
||||
PriceHigh float64 `json:"price_high"`
|
||||
PriceLow float64 `json:"price_low"`
|
||||
Volume float64 `json:"volume"`
|
||||
VolumeBtc float64 `json:"volume_btc"`
|
||||
} `json:"24hr"`
|
||||
CoinCurrencyID string `json:"coin_currency_id"`
|
||||
ID string `json:"id"`
|
||||
Label string `json:"label"`
|
||||
LastTrade struct {
|
||||
Date string `json:"date"`
|
||||
Price float64 `json:"price"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
} `json:"last_trade"`
|
||||
MaintenanceMode string `json:"maintenance_mode"`
|
||||
MarketCurrencyID string `json:"market_currency_id"`
|
||||
VerifiedOnly bool `json:"verifiedonly"`
|
||||
}
|
||||
|
||||
type CryptsyVolume struct {
|
||||
ID string `json:"id"`
|
||||
Volume float64 `json:"volume"`
|
||||
VolumeBtc float64 `json:"volume_btc"`
|
||||
}
|
||||
|
||||
type CryptsyTicker struct {
|
||||
ID string `json:"id"`
|
||||
Bid float64 `json:"bid"`
|
||||
Ask float64 `json:"ask"`
|
||||
}
|
||||
|
||||
type CryptsyOrderbook struct {
|
||||
BuyOrders []struct {
|
||||
Price float64 `json:"price"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Total float64 `json:"total"`
|
||||
} `json:"buyorders"`
|
||||
Sellorder [] struct {
|
||||
Price float64 `json:"price"`
|
||||
Quantity float64 `json:"quantity"`
|
||||
Total float64 `json:"total"`
|
||||
} `json:"sellorders"`
|
||||
}
|
||||
|
||||
type CryptsyTradeHistory struct {
|
||||
Datetime string `json:"datetime"`
|
||||
InitiateOrderType string `json:"initiate_ordertype"`
|
||||
Quantity float64 `json:"quantitiy"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
Total float64 `json:"total"`
|
||||
TradeID float64 `json:"tradeid"`
|
||||
TradePrice float64 `json:"tradeprice"`
|
||||
}
|
||||
|
||||
type CryptsyOHLC struct {
|
||||
Close float64 `json:"close"`
|
||||
Date string `json:"date"`
|
||||
High float64 `json:"high"`
|
||||
}
|
||||
|
||||
type CryptsyInfo struct {
|
||||
ID int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
AccountType string `json:"accounttype"`
|
||||
Email string `json:"email"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
TradeKey string `json:"trade_key"`
|
||||
}
|
||||
|
||||
type CryptsyDeposit struct {
|
||||
Currency string `json:"currency"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
TRXID string `json:"txrid"`
|
||||
}
|
||||
|
||||
type CryptsyCurrency struct {
|
||||
Code string `json:"code"`
|
||||
ID string `json:"id"`
|
||||
Maintenance string `json:"maintenance"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (c *Cryptsy) SetDefaults() {
|
||||
c.Name = "Cryptsy"
|
||||
c.Enabled = true
|
||||
c.Verbose = false
|
||||
c.TakerFee = 0.33
|
||||
c.MakerFee = 0.33
|
||||
c.Verbose = false
|
||||
c.PollingDelay = 10
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetName() (string) {
|
||||
return c.Name
|
||||
}
|
||||
|
||||
func (c *Cryptsy) SetEnabled(enabled bool) {
|
||||
c.Enabled = enabled
|
||||
}
|
||||
|
||||
func (c *Cryptsy) IsEnabled() (bool) {
|
||||
return c.Enabled
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetFee(maker bool) (float64) {
|
||||
if maker {
|
||||
return c.MakerFee
|
||||
} else {
|
||||
return c.TakerFee
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) Run() {
|
||||
if c.Verbose {
|
||||
log.Printf("%s polling delay: %ds.\n", c.GetName(), c.PollingDelay)
|
||||
}
|
||||
|
||||
for c.Enabled {
|
||||
go func() {
|
||||
CryptsyBTC := c.GetMarkets("BTCUSD")
|
||||
log.Printf("Cryptsy BTC: Last %f High %f Low %f Volume %f\n", CryptsyBTC[0].LastTrade.Price, CryptsyBTC[0].DayStats.PriceHigh, CryptsyBTC[0].DayStats.PriceLow, CryptsyBTC[0].DayStats.Volume)
|
||||
AddExchangeInfo(c.GetName(), "BTC", CryptsyBTC[0].LastTrade.Price, CryptsyBTC[0].DayStats.Volume)
|
||||
}()
|
||||
go func() {
|
||||
CryptsyLTC := c.GetMarkets("LTCUSD")
|
||||
log.Printf("Cryptsy LTC: Last %f High %f Low %f Volume %f\n", CryptsyLTC[0].LastTrade.Price, CryptsyLTC[0].DayStats.PriceHigh, CryptsyLTC[0].DayStats.PriceLow, CryptsyLTC[0].DayStats.Volume)
|
||||
AddExchangeInfo(c.GetName(), "LTC", CryptsyLTC[0].LastTrade.Price, CryptsyLTC[0].DayStats.Volume)
|
||||
}()
|
||||
time.Sleep(time.Second * c.PollingDelay)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) SetAPIKeys(apiKey, apiSecret string) {
|
||||
c.APIKey = apiKey
|
||||
c.APISecret = apiSecret
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetMarkets(id string) ([]CryptsyMarket) {
|
||||
type Response struct {
|
||||
Data []CryptsyMarket `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
response := Response{}
|
||||
err := SendHTTPGetRequest(CRYPTSY_API_URL + CRYPTSY_MARKETS, true, &response)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return []CryptsyMarket{}
|
||||
}
|
||||
|
||||
if !response.Success {
|
||||
return []CryptsyMarket{}
|
||||
}
|
||||
|
||||
if len(id) > 0 {
|
||||
for _, x := range response.Data {
|
||||
label := strings.Replace(x.Label, "/", "", -1)
|
||||
if label == id {
|
||||
result := make([]CryptsyMarket, 0)
|
||||
result = append(result, x)
|
||||
return result
|
||||
}
|
||||
}
|
||||
log.Println("Unable to find market id.")
|
||||
return []CryptsyMarket{}
|
||||
}
|
||||
return response.Data
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetVolume(id string) ([]CryptsyVolume) {
|
||||
type Response struct {
|
||||
Data []CryptsyVolume `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
response := Response{}
|
||||
path := fmt.Sprintf("%s/%s", CRYPTSY_API_URL + CRYPTSY_MARKETS, CRYPTSY_VOLUME)
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return []CryptsyVolume{}
|
||||
}
|
||||
|
||||
if !response.Success {
|
||||
return []CryptsyVolume{}
|
||||
}
|
||||
|
||||
if len(id) > 0 {
|
||||
for _, x := range response.Data {
|
||||
if x.ID == id {
|
||||
result := make([]CryptsyVolume, 0)
|
||||
result = append(result, x)
|
||||
return result
|
||||
}
|
||||
}
|
||||
log.Println("Unable to find market id.")
|
||||
return []CryptsyVolume{}
|
||||
}
|
||||
return response.Data
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetTicker(id string) ([]CryptsyTicker) {
|
||||
type Response struct {
|
||||
Data []CryptsyTicker `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
response := Response{}
|
||||
path := fmt.Sprintf("%s/%s", CRYPTSY_API_URL + CRYPTSY_MARKETS, CRYPTSY_TICKER)
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return []CryptsyTicker{}
|
||||
}
|
||||
|
||||
if !response.Success {
|
||||
return []CryptsyTicker{}
|
||||
}
|
||||
|
||||
if len(id) > 0 {
|
||||
for _, x := range response.Data {
|
||||
if x.ID == id {
|
||||
result := make([]CryptsyTicker, 0)
|
||||
result = append(result, x)
|
||||
return result
|
||||
}
|
||||
}
|
||||
log.Println("Unable to find market id.")
|
||||
return []CryptsyTicker{}
|
||||
}
|
||||
return response.Data
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetMarketFees(id string) {
|
||||
path := fmt.Sprintf("%s/%s/%s", CRYPTSY_API_URL + CRYPTSY_MARKETS, id, CRYPTSY_FEES)
|
||||
err := c.SendAuthenticatedHTTPRequest("GET", path, url.Values{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetMarketTriggers(id string) {
|
||||
path := fmt.Sprintf("%s/%s/%s", CRYPTSY_API_URL + CRYPTSY_MARKETS, id, CRYPTSY_TRIGGERS)
|
||||
err := c.SendAuthenticatedHTTPRequest("GET", path, url.Values{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetOrderbook(id string) {
|
||||
type Response struct {
|
||||
Data CryptsyOrderbook `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
response := Response{}
|
||||
path := fmt.Sprintf("%s/%s/%s", CRYPTSY_API_URL + CRYPTSY_MARKETS, id, CRYPTSY_ORDERBOOK)
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
log.Println(response)
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetTradeHistory(id string) {
|
||||
type Response struct {
|
||||
Data []CryptsyTradeHistory `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
response := Response{}
|
||||
path := fmt.Sprintf("%s/%s/%s", CRYPTSY_API_URL + CRYPTSY_MARKETS, id, CRYPTSY_TRADEHISTORY)
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
log.Println(response)
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetOHLC(id string) {
|
||||
type Response struct {
|
||||
Data []CryptsyOHLC `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
response := Response{}
|
||||
path := fmt.Sprintf("%s/%s/%s", CRYPTSY_API_URL + CRYPTSY_MARKETS, id, CRYPTSY_OHLC)
|
||||
err := SendHTTPGetRequest(path, true, &response)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
log.Println(response)
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetCurrencies(id string) ([]CryptsyCurrency) {
|
||||
type Response struct {
|
||||
Data []CryptsyCurrency `json:"data"`
|
||||
Success bool `json:"success"`
|
||||
}
|
||||
|
||||
response := Response{}
|
||||
err := SendHTTPGetRequest(CRYPTSY_API_URL + CRYPTSY_CURRENCIES, true, &response)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return []CryptsyCurrency{}
|
||||
}
|
||||
|
||||
if !response.Success {
|
||||
return []CryptsyCurrency{}
|
||||
}
|
||||
|
||||
if len(id) > 0 {
|
||||
for _, x := range response.Data {
|
||||
if x.ID == id {
|
||||
result := make([]CryptsyCurrency, 0)
|
||||
result = append(result, x)
|
||||
return result
|
||||
}
|
||||
}
|
||||
log.Println("Unable to find market id.")
|
||||
return []CryptsyCurrency{}
|
||||
}
|
||||
return response.Data
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetInfo() {
|
||||
err := c.SendAuthenticatedHTTPRequest("GET", CRYPTSY_API_URL + CRYPTSY_INFO, url.Values{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetBalances(balanceType, id string) {
|
||||
req := url.Values{}
|
||||
|
||||
if len(balanceType) > 0 {
|
||||
req.Set("type", balanceType)
|
||||
}
|
||||
err := c.SendAuthenticatedHTTPRequest("GET", CRYPTSY_API_URL + CRYPTSY_BALANCES, req)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetDeposits(limit int, id string) {
|
||||
req := url.Values{}
|
||||
|
||||
if limit > 0 {
|
||||
req.Set("liimt", strconv.Itoa(limit))
|
||||
}
|
||||
|
||||
err := c.SendAuthenticatedHTTPRequest("GET", CRYPTSY_API_URL + CRYPTSY_DEPOSITS, req)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) CreateOrder(marketid, orderType string, amount, price float64) {
|
||||
req := url.Values{}
|
||||
req.Set("marketid", marketid)
|
||||
req.Set("ordertype", orderType)
|
||||
req.Set("quantity", strconv.FormatFloat(amount, 'f', 8, 64))
|
||||
req.Set("price", strconv.FormatFloat(amount, 'f', 8, 64))
|
||||
|
||||
err := c.SendAuthenticatedHTTPRequest("POST", CRYPTSY_API_URL + CRYPTSY_ORDER, req)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) GetOrder(orderID int64) {
|
||||
path := fmt.Sprintf("%s/%s", CRYPTSY_API_URL + CRYPTSY_ORDER, strconv.FormatInt(orderID, 10))
|
||||
err := c.SendAuthenticatedHTTPRequest("GET", path, url.Values{})
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) DeleteOrder(orderID int64) {
|
||||
path := fmt.Sprintf("%s/%s", CRYPTSY_API_URL + CRYPTSY_ORDER, strconv.FormatInt(orderID, 10))
|
||||
err := c.SendAuthenticatedHTTPRequest("DELETE", path, url.Values{})
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cryptsy) SendAuthenticatedHTTPRequest(method, path string, params url.Values) (err error) {
|
||||
nonce := strconv.FormatInt(time.Now().Unix(), 10)
|
||||
params.Set("nonce", nonce)
|
||||
encoded := params.Encode()
|
||||
hmac := GetHMAC(HASH_SHA512, []byte(encoded), []byte(c.APISecret))
|
||||
readStr := ""
|
||||
|
||||
if method == "GET" || method == "DELETE" {
|
||||
path += "?" + encoded
|
||||
} else if method == "POST" {
|
||||
readStr = encoded
|
||||
}
|
||||
|
||||
if c.Verbose {
|
||||
log.Printf("Sending %s request to %s with params %s\n", method, path, encoded)
|
||||
}
|
||||
|
||||
headers := make(map[string]string)
|
||||
headers["Key"] = c.APIKey
|
||||
headers["Sign"] = HexEncodeToString(hmac)
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
|
||||
resp, err := SendHTTPRequest(method, path, headers, strings.NewReader(readStr))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.Verbose {
|
||||
log.Printf("Recieved raw: \n%s\n", resp)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -116,6 +116,8 @@ func (e *Event) CheckCondition() (bool) {
|
||||
lastPrice = bot.exchange.bitstamp.GetTicker().Last
|
||||
} else if bot.exchange.coinbase.GetName() == e.Exchange {
|
||||
lastPrice = bot.exchange.coinbase.GetTicker("BTC-USD").Price
|
||||
} else if bot.exchange.coinbase.GetName() == e.Exchange {
|
||||
lastPrice = bot.exchange.cryptsy.GetMarkets("BTCUSD")[0].LastTrade.Price
|
||||
} else if bot.exchange.lakebtc.GetName() == e.Exchange {
|
||||
lastPrice = bot.exchange.lakebtc.GetTicker().CNY.Last
|
||||
} else if bot.exchange.btcchina.GetName() == e.Exchange {
|
||||
@@ -229,6 +231,7 @@ func IsValidExchange(Exchange string) (bool) {
|
||||
bot.exchange.btce.GetName() == Exchange && bot.exchange.btcchina.IsEnabled() ||
|
||||
bot.exchange.btcmarkets.GetName() == Exchange && bot.exchange.btcmarkets.IsEnabled() ||
|
||||
bot.exchange.coinbase.GetName() == Exchange && bot.exchange.coinbase.IsEnabled() ||
|
||||
bot.exchange.cryptsy.GetName() == Exchange && bot.exchange.cryptsy.IsEnabled() ||
|
||||
bot.exchange.huobi.GetName() == Exchange && bot.exchange.huobi.IsEnabled() ||
|
||||
bot.exchange.itbit.GetName() == Exchange && bot.exchange.itbit.IsEnabled() ||
|
||||
bot.exchange.kraken.GetName() == Exchange && bot.exchange.kraken.IsEnabled() ||
|
||||
|
||||
19
main.go
19
main.go
@@ -15,6 +15,7 @@ type Exchange struct {
|
||||
btce BTCE
|
||||
btcmarkets BTCMarkets
|
||||
coinbase Coinbase
|
||||
cryptsy Cryptsy
|
||||
okcoinChina OKCoin
|
||||
okcoinIntl OKCoin
|
||||
itbit ItBit
|
||||
@@ -84,6 +85,7 @@ func main() {
|
||||
bot.exchange.btce.SetDefaults()
|
||||
bot.exchange.btcmarkets.SetDefaults()
|
||||
bot.exchange.coinbase.SetDefaults()
|
||||
bot.exchange.cryptsy.SetDefaults()
|
||||
bot.exchange.okcoinChina.SetURL(OKCOIN_API_URL_CHINA)
|
||||
bot.exchange.okcoinChina.SetDefaults()
|
||||
bot.exchange.okcoinIntl.SetURL(OKCOIN_API_URL)
|
||||
@@ -202,6 +204,23 @@ func main() {
|
||||
log.Printf("%s Verbose output disabled.\n", exch.Name)
|
||||
}
|
||||
}
|
||||
} else if bot.exchange.cryptsy.GetName() == exch.Name {
|
||||
if !exch.Enabled {
|
||||
bot.exchange.cryptsy.SetEnabled(false)
|
||||
log.Printf("%s disabled.\n", exch.Name)
|
||||
} else {
|
||||
log.Printf("%s enabled.\n", exch.Name)
|
||||
bot.exchange.cryptsy.SetAPIKeys(exch.APIKey, exch.APISecret)
|
||||
bot.exchange.cryptsy.PollingDelay = exch.PollingDelay
|
||||
go bot.exchange.cryptsy.Run()
|
||||
|
||||
if exch.Verbose {
|
||||
bot.exchange.cryptsy.Verbose = true
|
||||
log.Printf("%s Verbose output enabled.\n", exch.Name)
|
||||
} else {
|
||||
log.Printf("%s Verbose output disabled.\n", exch.Name)
|
||||
}
|
||||
}
|
||||
} else if bot.exchange.okcoinChina.GetName() == exch.Name {
|
||||
if !exch.Enabled {
|
||||
bot.exchange.okcoinChina.SetEnabled(false)
|
||||
|
||||
Reference in New Issue
Block a user