mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Add Bittrex wrapper
This commit is contained in:
25
README.md
25
README.md
@@ -1,4 +1,5 @@
|
||||
## Cryptocurrency trading bot written in Golang
|
||||
# Cryptocurrency trading bot written in Golang
|
||||
|
||||
[](https://travis-ci.org/thrasher-/gocryptotrader)
|
||||
[](https://github.com/thrasher-/gocryptotrader/blob/master/LICENSE)
|
||||
[](https://godoc.org/github.com/thrasher-/gocryptotrader)
|
||||
@@ -21,6 +22,7 @@ Join our slack to discuss all things related to GoCryptoTrader! [GoCryptoTrader
|
||||
| ANXPRO | Yes | No | NA |
|
||||
| Bitfinex | Yes | Yes | NA |
|
||||
| Bitstamp | Yes | Yes | NA |
|
||||
| Bittrex | Yes | No | NA |
|
||||
| BTCC | Yes | Yes | No |
|
||||
| BTCE | Yes | NA | NA |
|
||||
| BTCMarkets | Yes | NA | NA |
|
||||
@@ -41,6 +43,7 @@ We are aiming to support the top 20 highest volume exchanges based off the [Coin
|
||||
** NA means not applicable as the Exchange does not support the feature.
|
||||
|
||||
## Current Features
|
||||
|
||||
+ Support for all Exchange fiat and digital currencies, with the ability to individually toggle them on/off.
|
||||
+ AES encrypted config file.
|
||||
+ REST API support for all exchanges.
|
||||
@@ -54,6 +57,7 @@ We are aiming to support the top 20 highest volume exchanges based off the [Coin
|
||||
+ WebGUI.
|
||||
|
||||
## Planned Features
|
||||
|
||||
Planned features can be found on our [community Trello page](https://trello.com/b/ZAhMhpOy/gocryptotrader).
|
||||
|
||||
## Contribution
|
||||
@@ -62,24 +66,29 @@ Please feel free to submit any pull requests or suggest any desired features to
|
||||
|
||||
When submitting a PR, please abide by our coding guidelines:
|
||||
|
||||
* Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
|
||||
* Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
|
||||
* Code must adhere to our [coding style](https://github.com/thrasher-/gocryptotrader/blob/master/doc/coding_style.md).
|
||||
* Pull requests need to be based on and opened against the `master` branch.
|
||||
+ Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
|
||||
+ Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
|
||||
+ Code must adhere to our [coding style](https://github.com/thrasher-/gocryptotrader/blob/master/doc/coding_style.md).
|
||||
+ Pull requests need to be based on and opened against the `master` branch.
|
||||
|
||||
## Compiling instructions
|
||||
Download and install Go from https://golang.org/dl/
|
||||
|
||||
Download and install Go from [Go Downloads](https://golang.org/dl/)
|
||||
|
||||
```
|
||||
go get github.com/thrasher-/gocryptotrader
|
||||
cd $GOPATH/src/github.com/thrasher-/gocryptotrader
|
||||
go install
|
||||
cp $GOPATH/src/github.com/thrasher-/gocryptotrader/config_example.dat $GOPATH/bin/config.dat
|
||||
```
|
||||
Make any neccessary changes to the config file.
|
||||
Run the application!
|
||||
|
||||
Make any neccessary changes to the config file.
|
||||
Run the application!
|
||||
|
||||
## Donations
|
||||
|
||||
If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to: 1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB
|
||||
|
||||
## Binaries
|
||||
|
||||
Binaries will be published once the codebase reaches a stable condition.
|
||||
|
||||
@@ -87,6 +87,20 @@
|
||||
"EnabledPairs": "BTCUSD,BTCEUR,EURUSD,XRPUSD,XRPEUR",
|
||||
"BaseCurrencies": "USD,EUR"
|
||||
},
|
||||
{
|
||||
"Name": "Bittrex",
|
||||
"Enabled": true,
|
||||
"Verbose": false,
|
||||
"Websocket": false,
|
||||
"RESTPollingDelay": 10,
|
||||
"AuthenticatedAPISupport": false,
|
||||
"APIKey": "Key",
|
||||
"APISecret": "Secret",
|
||||
"ClientID": "",
|
||||
"AvailablePairs": "BTCLTC,BTCDOGE,BTCVTC,BTCPPC,BT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BTCUBQ,BTCKMD,BTCGBG,BTCSIB,BTCION,BTCLMC,BTCQWARK,BTCCRW,BTCSWT,BTCTIME,BTCMLN,BTCARK,BTCDYN,BTCTKS,BTCMUSIC,BTCDTB,BTCINCNT,BTCGBYTE,BTCGNT,BTCNXC,BTCEDG,BTCLGD,BTCTRST,ETHGNT,ETHREP,USDTETH,ETHWINGS,BTCWINGS,BTCRLC,BTCGNO,BTCGUP,BTCLUN,ETHGUP,ETHRLC,ETHLUN,ETHSNGLS,ETHGNO,BTCAPX,BTCTKN,ETHTKN,BTCHMQ,ETHHMQ,BTCANT,ETHTRST,ETHANT,BTCSC,ETHBAT,BTCBAT,BTCZEN,BTC1ST,BTCQRL,ETH1ST,ETHQRL,BTCCRB,ETHCRB,ETHLGD,BTCPTOY,ETHPTOY,BTCMYST,ETHMYST,BTCCFI,ETHCFI,BTCBNT,ETHBNT,BTCNMR,ETHNMR,ETHTIME,ETHLTC,ETHXRP,BTCSNT,ETHSNT,BTCDCT,BTCXEL,BTCMCO,ETHMCO,BTCADT,ETHADT,BTCFUN,ETHFUN,BTCPAY,ETHPAY,BTCMTL,ETHMTL,BTCSTORJ,ETHSTORJ,BTCADX,ETHADX,ETHDASH,ETHSC,ETHZEC,USDTZEC,USDTLTC,USDTETC,USDTXRP,BTCOMG,ETHOMG,BTCCVC,ETHCVC,BTCPART,BTCQTUM,ETHQTUM,ETHXMR,ETHXEM,ETHXLM,ETHNEO,USDTXMR,USDTDASH,ETHBCC,USDTBCC,BTCBCC,USDTNEO,ETHWAVES,ETHSTRAT,ETHDGB,ETHFCT,ETHBTS",
|
||||
"EnabledPairs": "BTCLTC,BTCDOGE,BTCDASH",
|
||||
"BaseCurrencies": "USD"
|
||||
},
|
||||
{
|
||||
"Name": "BTCC",
|
||||
"Enabled": true,
|
||||
|
||||
137
exchanges/bittrex/bittrex_wrapper.go
Normal file
137
exchanges/bittrex/bittrex_wrapper.go
Normal file
@@ -0,0 +1,137 @@
|
||||
package bittrex
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
|
||||
)
|
||||
|
||||
// Start stats the Bittrex go routine
|
||||
func (b *Bittrex) Start() {
|
||||
go b.Run()
|
||||
}
|
||||
|
||||
// Run implements the Bittrex wrapper
|
||||
func (b *Bittrex) Run() {
|
||||
if b.Verbose {
|
||||
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)
|
||||
}
|
||||
|
||||
exchangeProducts, err := b.GetMarkets()
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get available symbols.\n", b.GetName())
|
||||
} else {
|
||||
var currencies []string
|
||||
for x := range exchangeProducts {
|
||||
if !exchangeProducts[x].IsActive {
|
||||
continue
|
||||
}
|
||||
currencies = append(currencies,
|
||||
strings.Replace(exchangeProducts[x].MarketName, "-", "", -1))
|
||||
}
|
||||
err = b.UpdateAvailableCurrencies(currencies)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get config.\n", b.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
for b.Enabled {
|
||||
for _, x := range b.EnabledPairs {
|
||||
currency := pair.NewCurrencyPair(x[0:3], x[3:])
|
||||
currency.Delimiter = "-"
|
||||
go func() {
|
||||
ticker, err := b.GetTickerPrice(currency)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
log.Printf("Bittrex %s Last %f Bid %f Ask %f Volume %f\n", currency.Pair().String(), ticker.Last, ticker.Bid, ticker.Ask, ticker.Volume)
|
||||
stats.AddExchangeInfo(b.GetName(), currency.GetFirstCurrency().String(), currency.GetSecondCurrency().String(), ticker.Last, ticker.Volume)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * b.RESTPollingDelay)
|
||||
}
|
||||
}
|
||||
|
||||
//GetExchangeAccountInfo Retrieves balances for all enabled currencies for the Bittrexexchange
|
||||
func (b *Bittrex) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
|
||||
var response exchange.AccountInfo
|
||||
response.ExchangeName = b.GetName()
|
||||
accountBalance, err := b.GetAccountBalances()
|
||||
if err != nil {
|
||||
return response, err
|
||||
}
|
||||
|
||||
for i := 0; i < len(accountBalance); i++ {
|
||||
var exchangeCurrency exchange.AccountCurrencyInfo
|
||||
exchangeCurrency.CurrencyName = accountBalance[i].Currency
|
||||
exchangeCurrency.TotalValue = accountBalance[i].Balance
|
||||
exchangeCurrency.Hold = accountBalance[i].Balance - accountBalance[i].Available
|
||||
response.Currencies = append(response.Currencies, exchangeCurrency)
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// GetTickerPrice returns the ticker for a currencyp pair
|
||||
func (b *Bittrex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(b.GetName(), p)
|
||||
if err == nil {
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
var tickerPrice ticker.TickerPrice
|
||||
tick, err := b.GetMarketSummary(p.Pair().Lower().String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
tickerPrice.Pair = p
|
||||
tickerPrice.Ask = tick[0].Ask
|
||||
tickerPrice.Bid = tick[0].Bid
|
||||
tickerPrice.Last = tick[0].Last
|
||||
tickerPrice.Volume = tick[0].Volume
|
||||
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
}
|
||||
|
||||
// GetOrderbookEx returns the orderbook for a currencyp pair
|
||||
func (b *Bittrex) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
|
||||
ob, err := orderbook.GetOrderbook(b.GetName(), p)
|
||||
if err == nil {
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
var orderBook orderbook.OrderbookBase
|
||||
orderbookNew, err := b.GetOrderbook(p.Pair().Lower().String())
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
|
||||
for x := range orderbookNew.Buy {
|
||||
orderBook.Bids = append(orderBook.Bids,
|
||||
orderbook.OrderbookItem{
|
||||
Amount: orderbookNew.Buy[x].Quantity,
|
||||
Price: orderbookNew.Buy[x].Rate,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
for x := range orderbookNew.Sell {
|
||||
orderBook.Asks = append(orderBook.Asks,
|
||||
orderbook.OrderbookItem{
|
||||
Amount: orderbookNew.Sell[x].Quantity,
|
||||
Price: orderbookNew.Sell[x].Rate,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(b.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
}
|
||||
3
main.go
3
main.go
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/anx"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/bitfinex"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/bitstamp"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/bittrex"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/btcc"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/btce"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/btcmarkets"
|
||||
@@ -42,6 +43,7 @@ type ExchangeMain struct {
|
||||
btcc btcc.BTCC
|
||||
bitstamp bitstamp.Bitstamp
|
||||
bitfinex bitfinex.Bitfinex
|
||||
bittrex bittrex.Bittrex
|
||||
btce btce.BTCE
|
||||
btcmarkets btcmarkets.BTCMarkets
|
||||
coinut coinut.COINUT
|
||||
@@ -143,6 +145,7 @@ func main() {
|
||||
new(btcc.BTCC),
|
||||
new(bitstamp.Bitstamp),
|
||||
new(bitfinex.Bitfinex),
|
||||
new(bittrex.Bittrex),
|
||||
new(btce.BTCE),
|
||||
new(btcmarkets.BTCMarkets),
|
||||
new(coinut.COINUT),
|
||||
|
||||
Reference in New Issue
Block a user