Made use of Pairs and BaseCurrencies variables, formatting changes.

This commit is contained in:
Adrian Gallagher
2015-05-06 20:20:42 +10:00
parent 8183d1a955
commit f6bcdf8a76
14 changed files with 976 additions and 920 deletions

View File

@@ -1,64 +1,66 @@
package main
import (
"fmt"
"log"
"net/url"
"strconv"
"strings"
"time"
"fmt"
"log"
)
const (
BTCE_API_PUBLIC_URL = "https://btc-e.com/api"
BTCE_API_PRIVATE_URL = "https://btc-e.com/tapi"
BTCE_API_PUBLIC_VERSION = "3"
BTCE_API_PUBLIC_URL = "https://btc-e.com/api"
BTCE_API_PRIVATE_URL = "https://btc-e.com/tapi"
BTCE_API_PUBLIC_VERSION = "3"
BTCE_API_PRIVATE_VERSION = "1"
BTCE_INFO = "info"
BTCE_TICKER = "ticker"
BTCE_DEPTH = "depth"
BTCE_TRADES = "trades"
BTCE_ACCOUNT_INFO = "getInfo"
BTCE_INFO = "info"
BTCE_TICKER = "ticker"
BTCE_DEPTH = "depth"
BTCE_TRADES = "trades"
BTCE_ACCOUNT_INFO = "getInfo"
BTCE_TRANSACTION_HISTORY = "TransHistory"
BTCE_TRADE_HISTORY = "TradeHistory"
BTCE_ACTIVE_ORDERS = "ActiveOrders"
BTCE_TRADE = "Trade"
BTCE_CANCEL_ORDER = "CancelOrder"
BTCE_TRADE_HISTORY = "TradeHistory"
BTCE_ACTIVE_ORDERS = "ActiveOrders"
BTCE_TRADE = "Trade"
BTCE_CANCEL_ORDER = "CancelOrder"
)
type BTCE struct {
Name string
Enabled bool
Verbose bool
Websocket bool
RESTPollingDelay time.Duration
Name string
Enabled bool
Verbose bool
Websocket bool
RESTPollingDelay time.Duration
APIKey, APISecret string
Fee float64
Fee float64
BaseCurrencies []string
Pairs []string
}
type BTCeTicker struct {
High float64
Low float64
Avg float64
Vol float64
High float64
Low float64
Avg float64
Vol float64
Vol_cur float64
Last float64
Buy float64
Sell float64
Last float64
Buy float64
Sell float64
Updated int64
}
type BTCEOrderbook struct {
Asks[][]float64 `json:"asks"`
Bids[][]float64 `json:"bids"`
Asks [][]float64 `json:"asks"`
Bids [][]float64 `json:"bids"`
}
type BTCETrades struct {
Type string `json:"type"`
Price float64 `json:"bid"`
Amount float64 `json:"amount"`
TID int64 `json:"tid"`
Timestamp int64 `json:"timestamp"`
Type string `json:"type"`
Price float64 `json:"bid"`
Amount float64 `json:"amount"`
TID int64 `json:"tid"`
Timestamp int64 `json:"timestamp"`
}
func (b *BTCE) SetDefaults() {
@@ -70,7 +72,7 @@ func (b *BTCE) SetDefaults() {
b.RESTPollingDelay = 10
}
func (b *BTCE) GetName() (string) {
func (b *BTCE) GetName() string {
return b.Name
}
@@ -78,7 +80,7 @@ func (b *BTCE) SetEnabled(enabled bool) {
b.Enabled = enabled
}
func (b *BTCE) IsEnabled() (bool) {
func (b *BTCE) IsEnabled() bool {
return b.Enabled
}
@@ -87,7 +89,7 @@ func (b *BTCE) SetAPIKeys(apiKey, apiSecret string) {
b.APISecret = apiSecret
}
func (b *BTCE) GetFee() (float64) {
func (b *BTCE) GetFee() float64 {
return b.Fee
}
@@ -121,7 +123,7 @@ func (b *BTCE) GetInfo() {
}
}
func (b *BTCE) GetTicker(symbol string) (BTCeTicker) {
func (b *BTCE) GetTicker(symbol string) BTCeTicker {
type Response struct {
Data map[string]BTCeTicker
}
@@ -137,7 +139,7 @@ func (b *BTCE) GetTicker(symbol string) (BTCeTicker) {
return response.Data[symbol]
}
func (b *BTCE) GetDepth(symbol string) () {
func (b *BTCE) GetDepth(symbol string) {
type Response struct {
Data map[string]BTCEOrderbook
}
@@ -155,7 +157,7 @@ func (b *BTCE) GetDepth(symbol string) () {
log.Println(depth)
}
func (b *BTCE) GetTrades(symbol string) () {
func (b *BTCE) GetTrades(symbol string) {
type Response struct {
Data map[string][]BTCETrades
}
@@ -235,7 +237,7 @@ func (b *BTCE) GetTransactionHistory(TIDFrom, Count, TIDEnd int64, order, since,
func (b *BTCE) GetTradeHistory(TIDFrom, Count, TIDEnd int64, order, since, end, pair string) {
req := url.Values{}
req.Add("from", strconv.FormatInt(TIDFrom, 10))
req.Add("count", strconv.FormatInt(Count, 10))
req.Add("from_id", strconv.FormatInt(TIDFrom, 10))
@@ -276,8 +278,8 @@ func (b *BTCE) SendAuthenticatedHTTPRequest(method string, values url.Values) (e
}
if b.Verbose {
log.Printf("Recieved raw: %s\n",resp)
log.Printf("Recieved raw: %s\n", resp)
}
return nil
}
}