-
-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathgeneric_exchange_wrapper.go
70 lines (56 loc) · 3.54 KB
/
generic_exchange_wrapper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright © 2017 Alessandro Sanino <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package exchanges
import (
"errors"
"github.com/saniales/golang-crypto-trading-bot/environment"
"github.com/shopspring/decimal"
)
// TradeType represents a type of order, from trading fees point of view.
type TradeType string
const (
// TakerTrade represents the "buy" order type.
TakerTrade = "taker"
// MakerTrade represents the "sell" order type.
MakerTrade = "maker"
)
// ExchangeWrapper provides a generic wrapper for exchange services.
type ExchangeWrapper interface {
Name() string // Gets the name of the exchange.
GetCandles(market *environment.Market) ([]environment.CandleStick, error) // Gets the candle data from the exchange.
GetMarketSummary(market *environment.Market) (*environment.MarketSummary, error) // Gets the current market summary.
GetOrderBook(market *environment.Market) (*environment.OrderBook, error) // Gets the order(ASK + BID) book of a market.
BuyLimit(market *environment.Market, amount float64, limit float64) (string, error) // Performs a limit buy action.
SellLimit(market *environment.Market, amount float64, limit float64) (string, error) // Performs a limit sell action.
BuyMarket(market *environment.Market, amount float64) (string, error) // Performs a market buy action.
SellMarket(market *environment.Market, amount float64) (string, error) // Performs a market sell action.
CalculateTradingFees(market *environment.Market, amount float64, limit float64, orderType TradeType) float64 // Calculates the trading fees for an order on a specified market.
CalculateWithdrawFees(market *environment.Market, amount float64) float64 // Calculates the withdrawal fees on a specified market.
GetBalance(symbol string) (*decimal.Decimal, error) // Gets the balance of the user of the specified currency.
GetDepositAddress(coinTicker string) (string, bool) // Gets the deposit address for the specified coin on the exchange, if exists.
FeedConnect(markets []*environment.Market) error // Connects to the feed of the exchange.
Withdraw(destinationAddress string, coinTicker string, amount float64) error // Performs a withdraw operation from the exchange to a destination address.
String() string // Returns a string representation of the object.
}
// ErrWebsocketNotSupported is the error representing when an exchange does not support websocket.
var ErrWebsocketNotSupported = errors.New("Cannot use websocket: exchange does not support it")
// MarketNameFor gets the market name as seen by the exchange.
func MarketNameFor(m *environment.Market, wrapper ExchangeWrapper) string {
return m.ExchangeNames[wrapper.Name()]
}
// MarketTimeFrameFor gets the market timeframe
func MarketTimeFrameFor(m *environment.Market, wrapper ExchangeWrapper) string {
return m.ExchangeTimeFrames[wrapper.Name()]
}