Skip to content

Commit

Permalink
Added HTTP API support for Brighton Peak Exchange.
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Dec 13, 2015
1 parent bb6af76 commit b54ff7f
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 0 deletions.
185 changes: 185 additions & 0 deletions brightonpeakhttp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package main

import (
"log"
"time"
)

const (
BRIGHTONPEAK_API_URL = "https://api.brightonpeak.com:8400"
BRIGHTONPEAK_WEBSOCKET_URL = "wss://api.brightonpeak.com:8401"
)

type BrightonPeak struct {
Name string
Enabled bool
Verbose bool
Websocket bool
RESTPollingDelay time.Duration
AuthenticatedAPISupport bool
APIKey, APISecret, ClientID string
TakerFee, MakerFee float64
BaseCurrencies []string
AvailablePairs []string
EnabledPairs []string
API Alphapoint
}

func (b *BrightonPeak) SetDefaults() {
b.Name = "Brighton Peak"
b.Enabled = true
b.TakerFee = 0.5
b.MakerFee = 0.5
b.Verbose = false
b.Websocket = false
b.RESTPollingDelay = 10
b.API.APIUrl = BRIGHTONPEAK_API_URL
b.API.WebsocketURL = BRIGHTONPEAK_WEBSOCKET_URL
}

func (b *BrightonPeak) GetName() string {
return b.Name
}

func (b *BrightonPeak) SetEnabled(enabled bool) {
b.Enabled = enabled
}

func (b *BrightonPeak) IsEnabled() bool {
return b.Enabled
}

func (b *BrightonPeak) SetAPIKeys(apiKey, apiSecret, clientID string) {
b.API.UserID = clientID
b.API.APIKey = apiKey
b.API.APISecret = apiSecret
}

func (b *BrightonPeak) GetFee(maker bool) float64 {
if maker {
return b.MakerFee
} else {
return b.TakerFee
}
}

func (b *BrightonPeak) Run() {
if b.Verbose {
log.Printf("%s Websocket: %s. (url: %s).\n", b.GetName(), IsEnabled(b.Websocket), BRIGHTONPEAK_WEBSOCKET_URL)
log.Printf("%s polling delay: %ds.\n", b.GetName(), b.RESTPollingDelay)
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
}

if b.Websocket {
//go b.WebsocketClient()
}

exchangeProducts, err := b.GetProductPairs()
if err != nil || !exchangeProducts.IsAccepted {
log.Printf("%s Failed to get available products.\n", b.GetName())
} else {
currencies := []string{}
for _, x := range exchangeProducts.ProductPairs {
currencies = append(currencies, x.Name)
}
diff := StringSliceDifference(b.AvailablePairs, currencies)
if len(diff) > 0 {
exch, err := GetExchangeConfig(b.Name)
if err != nil {
log.Println(err)
} else {
log.Printf("%s Updating available pairs. Difference: %s.\n", b.Name, diff)
exch.AvailablePairs = JoinStrings(currencies, ",")
UpdateExchangeConfig(exch)
}
}
}

for b.Enabled {
for _, x := range b.EnabledPairs {
ticker, err := b.GetTicker(x)

if err != nil {
log.Println(err)
continue
}
log.Printf("%s %s Last %f High %f Low %f Volume %f\n", b.GetName(), x, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
AddExchangeInfo(b.GetName(), x[0:3], x[3:], ticker.Last, 0)
}
time.Sleep(time.Second * b.RESTPollingDelay)
}
}

func (b *BrightonPeak) GetTicker(symbol string) (AlphapointTicker, error) {
return b.API.GetTicker(symbol)
}

func (b *BrightonPeak) GetTrades(symbol string, startIndex, count int) (AlphapointTrades, error) {
return b.API.GetTrades(symbol, startIndex, count)
}

func (b *BrightonPeak) GetTradesByDate(symbol string, startIndex, count int) (AlphapointTrades, error) {
return b.API.GetTrades(symbol, startIndex, count)
}

func (b *BrightonPeak) GetOrderBook(symbol string) (AlphapointOrderbook, error) {
return b.API.GetOrderbook(symbol)
}

func (b *BrightonPeak) GetProductPairs() (AlphapointProductPairs, error) {
return b.API.GetProductPairs()
}

func (b *BrightonPeak) GetProducts() (AlphapointProducts, error) {
return b.API.GetProducts()
}

func (b *BrightonPeak) GreateAccount(firstName, lastName, email, phone, password string) error {
return b.API.CreateAccount(firstName, lastName, email, phone, password)
}

func (b *BrightonPeak) GetUserInfo() (AlphapointUserInfo, error) {
return b.API.GetUserInfo()
}

func (b *BrightonPeak) SetUserInfo() {} // to-do

func (b *BrightonPeak) GetAccountInfo() (AlphapointAccountInfo, error) {
return b.API.GetAccountInfo()
}

func (b *BrightonPeak) GetAccountTrades(symbol string, startIndex, count int) (AlphapointTrades, error) {
return b.API.GetAccountTrades(symbol, startIndex, count)
}

func (b *BrightonPeak) GetDepositAddresses() ([]AlphapointDepositAddresses, error) {
return b.API.GetDepositAddresses()
}

func (b *BrightonPeak) WithdrawCoins(symbol, product string, amount float64, address string) error {
return b.API.WithdrawCoins(symbol, product, amount, address)
}

func (b *BrightonPeak) CreateOrder(symbol, side string, orderType int, quantity, price float64) (int64, error) {
return b.API.CreateOrder(symbol, side, orderType, quantity, price)
}

func (b *BrightonPeak) ModifyOrder(symbol string, OrderID, action int64) (int64, error) {
return b.API.ModifyOrder(symbol, OrderID, action)
}

func (b *BrightonPeak) CancelOrder(symbol string, OrderID int64) (int64, error) {
return b.API.CancelOrder(symbol, OrderID)
}

func (b *BrightonPeak) CancelAllOrders(symbol string) error {
return b.API.CancelAllOrders(symbol)
}

func (b *BrightonPeak) GetOrders() ([]AlphapointOpenOrders, error) {
return b.API.GetOrders()
}

func (b *BrightonPeak) GetOrderFee(symbol, side string, quantity, price float64) (float64, error) {
return b.API.GetOrderFee(symbol, side, quantity, price)
}
14 changes: 14 additions & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@
"EnabledPairs": "BTCUSD",
"BaseCurrencies": "USD"
},
{
"Name": "Brighton Peak",
"Enabled": true,
"Verbose": true,
"Websocket": false,
"RESTPollingDelay": 10,
"AuthenticatedAPISupport": false,
"APIKey": "Key",
"APISecret": "Secret",
"ClientID": "ClientID",
"AvailablePairs": "BTCAUD,LTCAUD,LTCBTC",
"EnabledPairs": "BTCAUD,LTCAUD,LTCBTC",
"BaseCurrencies": "AUD"
},
{
"Name": "BTCC",
"Enabled": true,
Expand Down
8 changes: 8 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ func (e *Event) CheckCondition() bool {
} else {
lastPrice = result.Last
}
} else if bot.exchange.brightonpeak.GetName() == e.Exchange {
result, err := bot.exchange.brightonpeak.GetTicker("BTCUSD")
if err != nil {
lastPrice = 0
} else {
lastPrice = result.Last
}
} else if bot.exchange.coinbase.GetName() == e.Exchange {
result, err := bot.exchange.coinbase.GetTicker("BTC-USD")
if err != nil {
Expand Down Expand Up @@ -267,6 +274,7 @@ func CheckEvents() {
func IsValidExchange(Exchange string) bool {
if bot.exchange.bitfinex.GetName() == Exchange && bot.exchange.bitfinex.IsEnabled() ||
bot.exchange.bitstamp.GetName() == Exchange && bot.exchange.bitstamp.IsEnabled() ||
bot.exchange.brightonpeak.GetName() == Exchange && bot.exchange.brightonpeak.IsEnabled() ||
bot.exchange.btcc.GetName() == Exchange && bot.exchange.btcc.IsEnabled() ||
bot.exchange.btce.GetName() == Exchange && bot.exchange.btce.IsEnabled() ||
bot.exchange.btcmarkets.GetName() == Exchange && bot.exchange.btcmarkets.IsEnabled() ||
Expand Down
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Exchange struct {
btcc BTCC
bitstamp Bitstamp
bitfinex Bitfinex
brightonpeak BrightonPeak
btce BTCE
btcmarkets BTCMarkets
coinbase Coinbase
Expand Down Expand Up @@ -97,6 +98,7 @@ func main() {
bot.exchange.kraken.SetDefaults()
bot.exchange.btcc.SetDefaults()
bot.exchange.bitstamp.SetDefaults()
bot.exchange.brightonpeak.SetDefaults()
bot.exchange.bitfinex.SetDefaults()
bot.exchange.btce.SetDefaults()
bot.exchange.btcmarkets.SetDefaults()
Expand Down Expand Up @@ -181,6 +183,20 @@ func main() {
bot.exchange.bitfinex.EnabledPairs = SplitStrings(exch.EnabledPairs, ",")
go bot.exchange.bitfinex.Run()
}
} else if bot.exchange.brightonpeak.GetName() == exch.Name {
if !exch.Enabled {
bot.exchange.brightonpeak.SetEnabled(false)
} else {
bot.exchange.brightonpeak.AuthenticatedAPISupport = exch.AuthenticatedAPISupport
bot.exchange.brightonpeak.SetAPIKeys(exch.APIKey, exch.APISecret, exch.ClientID)
bot.exchange.brightonpeak.RESTPollingDelay = exch.RESTPollingDelay
bot.exchange.brightonpeak.Verbose = exch.Verbose
bot.exchange.brightonpeak.Websocket = exch.Websocket
bot.exchange.brightonpeak.BaseCurrencies = SplitStrings(exch.BaseCurrencies, ",")
bot.exchange.brightonpeak.AvailablePairs = SplitStrings(exch.AvailablePairs, ",")
bot.exchange.brightonpeak.EnabledPairs = SplitStrings(exch.EnabledPairs, ",")
go bot.exchange.brightonpeak.Run()
}
} else if bot.exchange.btce.GetName() == exch.Name {
if !exch.Enabled {
bot.exchange.btce.SetEnabled(false)
Expand Down

0 comments on commit b54ff7f

Please sign in to comment.