mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-19 07:26:49 +00:00
Make BTCC only use BTCUSD and update config files
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
btccAPIUrl = "https://api.btcchina.com/"
|
||||
btccAPIUrl = "https://spotusd-data.btcc.com"
|
||||
btccAPIAuthenticatedMethod = "api_trade_v1.php"
|
||||
btccAPIVersion = "2.0.1.3"
|
||||
btccOrderBuy = "buyOrder2"
|
||||
@@ -97,21 +97,10 @@ func (b *BTCC) GetFee() float64 {
|
||||
// currencyPair - Example "btccny", "ltccny" or "ltcbtc"
|
||||
func (b *BTCC) GetTicker(currencyPair string) (Ticker, error) {
|
||||
resp := Response{}
|
||||
req := fmt.Sprintf("%sdata/ticker?market=%s", btccAPIUrl, currencyPair)
|
||||
|
||||
req := fmt.Sprintf("%s/data/pro/ticker?symbol=%s", btccAPIUrl, currencyPair)
|
||||
return resp.Ticker, common.SendHTTPGetRequest(req, true, b.Verbose, &resp)
|
||||
}
|
||||
|
||||
// GetTradesLast24h returns the trades executed on the exchange over the past
|
||||
// 24 hours by currency pair
|
||||
// currencyPair - Example "btccny", "ltccny" or "ltcbtc"
|
||||
func (b *BTCC) GetTradesLast24h(currencyPair string) ([]Trade, error) {
|
||||
trades := []Trade{}
|
||||
req := fmt.Sprintf("%sdata/trades?market=%s", btccAPIUrl, currencyPair)
|
||||
|
||||
return trades, common.SendHTTPGetRequest(req, true, b.Verbose, &trades)
|
||||
}
|
||||
|
||||
// GetTradeHistory returns trade history data
|
||||
// currencyPair - Example "btccny", "ltccny" or "ltcbtc"
|
||||
// limit - limits the returned trades example "10"
|
||||
@@ -119,9 +108,7 @@ func (b *BTCC) GetTradesLast24h(currencyPair string) ([]Trade, error) {
|
||||
// time - returns trade records starting from unix time 1406794449
|
||||
func (b *BTCC) GetTradeHistory(currencyPair string, limit, sinceTid int64, time time.Time) ([]Trade, error) {
|
||||
trades := []Trade{}
|
||||
|
||||
req := fmt.Sprintf("%sdata/historydata?market=%s", btccAPIUrl, currencyPair)
|
||||
|
||||
req := fmt.Sprintf("%s/data/pro/historydata?symbol=%s", btccAPIUrl, currencyPair)
|
||||
v := url.Values{}
|
||||
|
||||
if limit > 0 {
|
||||
@@ -135,20 +122,18 @@ func (b *BTCC) GetTradeHistory(currencyPair string, limit, sinceTid int64, time
|
||||
}
|
||||
|
||||
req = common.EncodeURLValues(req, v)
|
||||
|
||||
return trades, common.SendHTTPGetRequest(req, true, b.Verbose, &trades)
|
||||
}
|
||||
|
||||
// GetOrderBook returns current market order book
|
||||
// GetOrderBook returns current symbol order book
|
||||
// currencyPair - Example "btccny", "ltccny" or "ltcbtc"
|
||||
// limit - limits the returned trades example "10" if 0 will return full
|
||||
// orderbook
|
||||
func (b *BTCC) GetOrderBook(currencyPair string, limit int) (Orderbook, error) {
|
||||
result := Orderbook{}
|
||||
|
||||
req := fmt.Sprintf("%sdata/orderbook?market=%s&limit=%d", btccAPIUrl, currencyPair, limit)
|
||||
req := fmt.Sprintf("%s/data/pro/orderbook?symbol=%s&limit=%d", btccAPIUrl, currencyPair, limit)
|
||||
if limit == 0 {
|
||||
req = fmt.Sprintf("%sdata/orderbook?market=%s", btccAPIUrl, currencyPair)
|
||||
req = fmt.Sprintf("%s/data/pro/orderbook?symbol=%s", btccAPIUrl, currencyPair)
|
||||
}
|
||||
|
||||
return result, common.SendHTTPGetRequest(req, true, b.Verbose, &result)
|
||||
@@ -164,13 +149,13 @@ func (b *BTCC) GetAccountInfo(infoType string) error {
|
||||
return b.SendAuthenticatedHTTPRequest(btccAccountInfo, params)
|
||||
}
|
||||
|
||||
func (b *BTCC) PlaceOrder(buyOrder bool, price, amount float64, market string) {
|
||||
func (b *BTCC) PlaceOrder(buyOrder bool, price, amount float64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, strconv.FormatFloat(price, 'f', -1, 64))
|
||||
params = append(params, strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
req := btccOrderBuy
|
||||
@@ -185,12 +170,12 @@ func (b *BTCC) PlaceOrder(buyOrder bool, price, amount float64, market string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) CancelOrder(orderID int64, market string) {
|
||||
func (b *BTCC) CancelOrder(orderID int64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, orderID)
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(btccOrderCancel, params)
|
||||
@@ -215,15 +200,15 @@ func (b *BTCC) GetDeposits(currency string, pending bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) GetMarketDepth(market string, limit int64) {
|
||||
func (b *BTCC) GetMarketDepth(symbol string, limit int64) {
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
if limit > 0 {
|
||||
params = append(params, limit)
|
||||
}
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(btccMarketdepth, params)
|
||||
@@ -233,12 +218,12 @@ func (b *BTCC) GetMarketDepth(market string, limit int64) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) GetOrder(orderID int64, market string, detailed bool) {
|
||||
func (b *BTCC) GetOrder(orderID int64, symbol string, detailed bool) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, orderID)
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
if detailed {
|
||||
@@ -252,15 +237,15 @@ func (b *BTCC) GetOrder(orderID int64, market string, detailed bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) GetOrders(openonly bool, market string, limit, offset, since int64, detailed bool) {
|
||||
func (b *BTCC) GetOrders(openonly bool, symbol string, limit, offset, since int64, detailed bool) {
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
if openonly {
|
||||
params = append(params, openonly)
|
||||
}
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
if limit > 0 {
|
||||
@@ -358,15 +343,15 @@ func (b *BTCC) RequestWithdrawal(currency string, amount float64) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) IcebergOrder(buyOrder bool, price, amount, discAmount, variance float64, market string) {
|
||||
func (b *BTCC) IcebergOrder(buyOrder bool, price, amount, discAmount, variance float64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, strconv.FormatFloat(price, 'f', -1, 64))
|
||||
params = append(params, strconv.FormatFloat(amount, 'f', -1, 64))
|
||||
params = append(params, strconv.FormatFloat(discAmount, 'f', -1, 64))
|
||||
params = append(params, strconv.FormatFloat(variance, 'f', -1, 64))
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
req := btccIcebergBuy
|
||||
@@ -381,12 +366,12 @@ func (b *BTCC) IcebergOrder(buyOrder bool, price, amount, discAmount, variance f
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) GetIcebergOrder(orderID int64, market string) {
|
||||
func (b *BTCC) GetIcebergOrder(orderID int64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, orderID)
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(btccIcebergOrder, params)
|
||||
@@ -396,7 +381,7 @@ func (b *BTCC) GetIcebergOrder(orderID int64, market string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) GetIcebergOrders(limit, offset int64, market string) {
|
||||
func (b *BTCC) GetIcebergOrders(limit, offset int64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
if limit > 0 {
|
||||
@@ -407,8 +392,8 @@ func (b *BTCC) GetIcebergOrders(limit, offset int64, market string) {
|
||||
params = append(params, offset)
|
||||
}
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(btccIcebergOrders, params)
|
||||
@@ -418,12 +403,12 @@ func (b *BTCC) GetIcebergOrders(limit, offset int64, market string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) CancelIcebergOrder(orderID int64, market string) {
|
||||
func (b *BTCC) CancelIcebergOrder(orderID int64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, orderID)
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(btccIcebergCancel, params)
|
||||
@@ -433,7 +418,7 @@ func (b *BTCC) CancelIcebergOrder(orderID int64, market string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) PlaceStopOrder(buyOder bool, stopPrice, price, amount, trailingAmt, trailingPct float64, market string) {
|
||||
func (b *BTCC) PlaceStopOrder(buyOder bool, stopPrice, price, amount, trailingAmt, trailingPct float64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
if stopPrice > 0 {
|
||||
@@ -451,8 +436,8 @@ func (b *BTCC) PlaceStopOrder(buyOder bool, stopPrice, price, amount, trailingAm
|
||||
params = append(params, strconv.FormatFloat(trailingPct, 'f', -1, 64))
|
||||
}
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
req := btccStoporderBuy
|
||||
@@ -467,12 +452,12 @@ func (b *BTCC) PlaceStopOrder(buyOder bool, stopPrice, price, amount, trailingAm
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) GetStopOrder(orderID int64, market string) {
|
||||
func (b *BTCC) GetStopOrder(orderID int64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, orderID)
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(btccStoporder, params)
|
||||
@@ -482,7 +467,7 @@ func (b *BTCC) GetStopOrder(orderID int64, market string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) GetStopOrders(status, orderType string, stopPrice float64, limit, offset int64, market string) {
|
||||
func (b *BTCC) GetStopOrders(status, orderType string, stopPrice float64, limit, offset int64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
if len(status) > 0 {
|
||||
@@ -505,8 +490,8 @@ func (b *BTCC) GetStopOrders(status, orderType string, stopPrice float64, limit,
|
||||
params = append(params, limit)
|
||||
}
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(btccStoporders, params)
|
||||
@@ -516,12 +501,12 @@ func (b *BTCC) GetStopOrders(status, orderType string, stopPrice float64, limit,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BTCC) CancelStopOrder(orderID int64, market string) {
|
||||
func (b *BTCC) CancelStopOrder(orderID int64, symbol string) {
|
||||
params := make([]interface{}, 0)
|
||||
params = append(params, orderID)
|
||||
|
||||
if len(market) > 0 {
|
||||
params = append(params, market)
|
||||
if len(symbol) > 0 {
|
||||
params = append(params, symbol)
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(btccStoporderCancel, params)
|
||||
@@ -587,7 +572,8 @@ func (b *BTCC) SendAuthenticatedHTTPRequest(method string, params []interface{})
|
||||
postData["method"] = method
|
||||
postData["params"] = params
|
||||
postData["id"] = 1
|
||||
apiURL := btccAPIUrl + btccAPIAuthenticatedMethod
|
||||
|
||||
apiURL := fmt.Sprintf("%s/%s", btccAPIUrl, btccAPIAuthenticatedMethod)
|
||||
data, err := common.JSONEncode(postData)
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -53,21 +53,14 @@ func TestGetFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetTicker(t *testing.T) {
|
||||
_, err := b.GetTicker("ltccny")
|
||||
if err == nil {
|
||||
_, err := b.GetTicker("BTCUSD")
|
||||
if err != nil {
|
||||
t.Error("Test failed - GetTicker() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTradesLast24h(t *testing.T) {
|
||||
_, err := b.GetTradesLast24h("ltccny")
|
||||
if err != nil {
|
||||
t.Error("Test failed - GetTradesLast24h() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTradeHistory(t *testing.T) {
|
||||
_, err := b.GetTradeHistory("ltccny", 0, 0, time.Time{})
|
||||
_, err := b.GetTradeHistory("BTCUSD", 0, 0, time.Time{})
|
||||
if err != nil {
|
||||
t.Error("Test failed - GetTradeHistory() error", err)
|
||||
}
|
||||
@@ -75,12 +68,12 @@ func TestGetTradeHistory(t *testing.T) {
|
||||
|
||||
func TestGetOrderBook(t *testing.T) {
|
||||
b.Verbose = true
|
||||
_, err := b.GetOrderBook("ltccny", 100)
|
||||
if err == nil {
|
||||
_, err := b.GetOrderBook("BTCUSD", 100)
|
||||
if err != nil {
|
||||
t.Error("Test failed - GetOrderBook() error", err)
|
||||
}
|
||||
_, err = b.GetOrderBook("ltccny", 0)
|
||||
if err == nil {
|
||||
_, err = b.GetOrderBook("BTCUSD", 0)
|
||||
if err != nil {
|
||||
t.Error("Test failed - GetOrderBook() error", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,32 +3,32 @@ package btcc
|
||||
// Response is the generalized response type
|
||||
type Response struct {
|
||||
Ticker Ticker `json:"ticker"`
|
||||
BtcCny Ticker `json:"ticker_btccny"`
|
||||
LtcCny Ticker `json:"ticker_ltccny"`
|
||||
LtcBtc Ticker `json:"ticker_ltcbtc"`
|
||||
}
|
||||
|
||||
// Ticker holds basic ticker information
|
||||
type Ticker struct {
|
||||
High float64 `json:"high,string"`
|
||||
Low float64 `json:"low,string"`
|
||||
Buy float64 `json:"buy,string"`
|
||||
Sell float64 `json:"sell,string"`
|
||||
Last float64 `json:"last,string"`
|
||||
Vol float64 `json:"vol,string"`
|
||||
Date int64 `json:"date"`
|
||||
Vwap float64 `json:"vwap,string"`
|
||||
PrevClose float64 `json:"prev_close,string"`
|
||||
Open float64 `json:"open,string"`
|
||||
BidPrice float64 `json:"BidPrice"`
|
||||
AskPrice float64 `json:"AskPrice"`
|
||||
Open float64 `json:"Open"`
|
||||
High float64 `json:"High"`
|
||||
Low float64 `json:"Low"`
|
||||
Last float64 `json:"Last"`
|
||||
LastQuantity float64 `json:"LastQuantity"`
|
||||
PrevCls float64 `json:"PrevCls"`
|
||||
Volume float64 `json:"Volume"`
|
||||
Volume24H float64 `json:"Volume24H"`
|
||||
Timestamp int64 `json:"Timestamp"`
|
||||
ExecutionLimitDown float64 `json:"ExecutionLimitDown"`
|
||||
ExecutionLimitUp float64 `json:"ExecutionLimitUp"`
|
||||
}
|
||||
|
||||
// Trade holds executed trade data
|
||||
type Trade struct {
|
||||
Date int64 `json:"date,string"`
|
||||
Price float64 `json:"price"`
|
||||
Amount float64 `json:"amount"`
|
||||
TID int64 `json:"tid,string"`
|
||||
Type string `json:"type"`
|
||||
ID int64 `json:"Id"`
|
||||
Timestamp int64 `json:"Timestamp"`
|
||||
Price float64 `json:"Price"`
|
||||
Quantity float64 `json:"Quantity"`
|
||||
Side string `json:"Side"`
|
||||
}
|
||||
|
||||
// Orderbook holds orderbook data
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/config"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
@@ -26,6 +27,38 @@ func (b *BTCC) Run() {
|
||||
if b.Websocket {
|
||||
go b.WebsocketClient()
|
||||
}
|
||||
|
||||
if common.DataContains(b.EnabledPairs, "CNY") || common.DataContains(b.AvailablePairs, "CNY") || common.DataContains(b.BaseCurrencies, "CNY") {
|
||||
log.Println("WARNING: BTCC only supports BTCUSD now, upgrading available, enabled and base currencies to BTCUSD/USD")
|
||||
pairs := []string{"BTCUSD"}
|
||||
cfg := config.GetConfig()
|
||||
exchCfg, err := cfg.GetExchangeConfig(b.Name)
|
||||
if err != nil {
|
||||
log.Printf("%s failed to get exchange config. %s\n", b.Name, err)
|
||||
return
|
||||
}
|
||||
|
||||
exchCfg.BaseCurrencies = "USD"
|
||||
exchCfg.AvailablePairs = pairs[0]
|
||||
exchCfg.EnabledPairs = pairs[0]
|
||||
b.BaseCurrencies = []string{"USD"}
|
||||
|
||||
err = b.UpdateAvailableCurrencies(pairs, true)
|
||||
if err != nil {
|
||||
log.Printf("%s failed to update available currencies. %s\n", b.Name, err)
|
||||
}
|
||||
|
||||
err = b.UpdateEnabledCurrencies(pairs, true)
|
||||
if err != nil {
|
||||
log.Printf("%s failed to update enabled currencies. %s\n", b.Name, err)
|
||||
}
|
||||
|
||||
err = cfg.UpdateExchangeConfig(exchCfg)
|
||||
if err != nil {
|
||||
log.Printf("%s failed to update config. %s\n", b.Name, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateTicker updates and returns the ticker for a currency pair
|
||||
@@ -36,11 +69,11 @@ func (b *BTCC) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price
|
||||
return tickerPrice, err
|
||||
}
|
||||
tickerPrice.Pair = p
|
||||
tickerPrice.Ask = tick.Sell
|
||||
tickerPrice.Bid = tick.Buy
|
||||
tickerPrice.Ask = tick.AskPrice
|
||||
tickerPrice.Bid = tick.BidPrice
|
||||
tickerPrice.Low = tick.Low
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Vol
|
||||
tickerPrice.Volume = tick.Volume24H
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice, assetType)
|
||||
return ticker.GetTicker(b.Name, p, assetType)
|
||||
|
||||
Reference in New Issue
Block a user