forked from tensam/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added HTTP API support for Brighton Peak Exchange.
- Loading branch information
Showing
4 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters