Currency package update (#247)

* Initial currency overhaul before service system implementation

* Remove redundant currency string in orderbook.Base
Unexport lastupdated field in orderbook.Base as it was being instantiated multiple times
Add error handling for process orderbook

*  Remove redundant currency string in ticker.Price
 Unexport lastupdated field in ticker.Price
 Add error handling for process ticker function and fix tests

* Phase Two Update

* Update translations to use map type - thankyou to kempeng for spotting this

* Change pair method name from Display -> Format for better readability

* Fixes misspelling and tests

* Implement requested changes from GloriousCode

* Remove reduntant function and streamlined return in currency_translation.go

* Revert pair method naming conventions

* Change currency naming conventions

* Changed code type to exported Item type with underlying string to reduce complexity

* Added interim orderbook process method to orderbook.Base type

* Changed feebuilder struct field to currency.Pair

* Adds fall over system for backup fx providers

* deprecate function and children and fix linter issue with btcmarkets

* Fixed requested changes

* Fix bug and move mtx for rates

* Fixed after rebase oopsies

* Fix linter issues

* Fixes race conditions in testing functions

* Final phase coinmarketcap update

* fix linter issues

* Implement requested changes

* Adds configuration variables to increase/decrease time durations between updating currency file and fetching new currency rates

* Add a collection of tests to improve codecov

* After rebase oopsy fixes for btse

* Fix requested changes

* fix after rebase oopsies and add more efficient comparison checks within currency pair

* Fix linter issues
This commit is contained in:
Ryan O'Hara-Reid
2019-03-19 11:49:05 +11:00
committed by Adrian Gallagher
parent ed760e184e
commit 0990f9d118
189 changed files with 11982 additions and 8055 deletions

View File

@@ -12,8 +12,6 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency/symbol"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -95,9 +93,9 @@ func (c *COINUT) Setup(exch config.ExchangeConfig) {
c.RESTPollingDelay = exch.RESTPollingDelay
c.Verbose = exch.Verbose
c.Websocket.SetWsStatusAndConnection(exch.Websocket)
c.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
c.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
c.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
c.BaseCurrencies = exch.BaseCurrencies
c.AvailablePairs = exch.AvailablePairs
c.EnabledPairs = exch.EnabledPairs
err := c.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
@@ -370,7 +368,13 @@ func (c *COINUT) SendHTTPRequest(apiRequest string, params map[string]interface{
headers["Content-Type"] = "application/json"
var rawMsg json.RawMessage
err = c.SendPayload(http.MethodPost, c.APIUrl, headers, bytes.NewBuffer(payload), &rawMsg, authenticated, c.Verbose)
err = c.SendPayload(http.MethodPost,
c.APIUrl,
headers,
bytes.NewBuffer(payload),
&rawMsg,
authenticated,
c.Verbose)
if err != nil {
return err
}
@@ -394,11 +398,17 @@ func (c *COINUT) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
var fee float64
switch feeBuilder.FeeType {
case exchange.CryptocurrencyTradeFee:
fee = c.calculateTradingFee(feeBuilder.FirstCurrency, feeBuilder.SecondCurrency, feeBuilder.PurchasePrice, feeBuilder.Amount, feeBuilder.IsMaker)
fee = c.calculateTradingFee(feeBuilder.Pair.Base,
feeBuilder.Pair.Quote,
feeBuilder.PurchasePrice,
feeBuilder.Amount,
feeBuilder.IsMaker)
case exchange.InternationalBankWithdrawalFee:
fee = getInternationalBankWithdrawalFee(feeBuilder.CurrencyItem, feeBuilder.Amount)
fee = getInternationalBankWithdrawalFee(feeBuilder.FiatCurrency,
feeBuilder.Amount)
case exchange.InternationalBankDepositFee:
fee = getInternationalBankDepositFee(feeBuilder.CurrencyItem, feeBuilder.Amount)
fee = getInternationalBankDepositFee(feeBuilder.FiatCurrency,
feeBuilder.Amount)
}
if fee < 0 {
@@ -408,13 +418,13 @@ func (c *COINUT) GetFee(feeBuilder exchange.FeeBuilder) (float64, error) {
return fee, nil
}
func (c *COINUT) calculateTradingFee(firstCurrency, secondCurrency string, purchasePrice, amount float64, isMaker bool) float64 {
func (c *COINUT) calculateTradingFee(base, quote currency.Code, purchasePrice, amount float64, isMaker bool) float64 {
var fee float64
switch {
case isMaker:
fee = 0
case currency.IsCryptoFiatPair(pair.NewCurrencyPair(firstCurrency, secondCurrency)):
case currency.NewPair(base, quote).IsCryptoFiatPair():
fee = 0.002
default:
fee = 0.001
@@ -423,23 +433,23 @@ func (c *COINUT) calculateTradingFee(firstCurrency, secondCurrency string, purch
return fee * amount * purchasePrice
}
func getInternationalBankWithdrawalFee(currency string, amount float64) float64 {
func getInternationalBankWithdrawalFee(c currency.Code, amount float64) float64 {
var fee float64
switch currency {
case symbol.USD:
switch c {
case currency.USD:
if amount*0.001 < 10 {
fee = 10
} else {
fee = amount * 0.001
}
case symbol.CAD:
case currency.CAD:
if amount*0.005 < 10 {
fee = 2
} else {
fee = amount * 0.005
}
case symbol.SGD:
case currency.SGD:
if amount*0.001 < 10 {
fee = 10
} else {
@@ -450,16 +460,16 @@ func getInternationalBankWithdrawalFee(currency string, amount float64) float64
return fee
}
func getInternationalBankDepositFee(currency string, amount float64) float64 {
func getInternationalBankDepositFee(c currency.Code, amount float64) float64 {
var fee float64
if currency == symbol.USD {
if c == currency.USD {
if amount*0.001 < 10 {
fee = 10
} else {
fee = amount * 0.001
}
} else if currency == symbol.CAD {
} else if c == currency.CAD {
if amount*0.005 < 10 {
fee = 2
} else {

View File

@@ -6,8 +6,7 @@ import (
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency/symbol"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
)
@@ -53,13 +52,10 @@ func TestGetInstruments(t *testing.T) {
func setFeeBuilder() exchange.FeeBuilder {
return exchange.FeeBuilder{
Amount: 1,
Delimiter: "",
FeeType: exchange.CryptocurrencyTradeFee,
FirstCurrency: symbol.BTC,
SecondCurrency: symbol.LTC,
IsMaker: false,
PurchasePrice: 1,
Amount: 1,
FeeType: exchange.CryptocurrencyTradeFee,
Pair: currency.NewPair(currency.BTC, currency.LTC),
PurchasePrice: 1,
}
}
@@ -120,7 +116,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.CurrencyItem = symbol.EUR
feeBuilder.FiatCurrency = currency.EUR
if resp, err := c.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
@@ -129,7 +125,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.CurrencyItem = symbol.USD
feeBuilder.FiatCurrency = currency.USD
if resp, err := c.GetFee(feeBuilder); resp != float64(10) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(10), resp)
t.Error(err)
@@ -138,7 +134,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankDepositFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankDepositFee
feeBuilder.CurrencyItem = symbol.SGD
feeBuilder.FiatCurrency = currency.SGD
if resp, err := c.GetFee(feeBuilder); resp != float64(0) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
t.Error(err)
@@ -147,7 +143,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.CurrencyItem = symbol.USD
feeBuilder.FiatCurrency = currency.USD
if resp, err := c.GetFee(feeBuilder); resp != float64(10) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(10), resp)
t.Error(err)
@@ -156,7 +152,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.CurrencyItem = symbol.CAD
feeBuilder.FiatCurrency = currency.CAD
if resp, err := c.GetFee(feeBuilder); resp != float64(2) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(2), resp)
t.Error(err)
@@ -165,7 +161,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.CurrencyItem = symbol.SGD
feeBuilder.FiatCurrency = currency.SGD
if resp, err := c.GetFee(feeBuilder); resp != float64(10) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(10), resp)
t.Error(err)
@@ -174,7 +170,7 @@ func TestGetFee(t *testing.T) {
// InternationalBankWithdrawalFee Basic
feeBuilder = setFeeBuilder()
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
feeBuilder.CurrencyItem = symbol.CAD
feeBuilder.FiatCurrency = currency.CAD
if resp, err := c.GetFee(feeBuilder); resp != float64(2) || err != nil {
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(2), resp)
t.Error(err)
@@ -212,8 +208,9 @@ func TestGetOrderHistory(t *testing.T) {
TestSetup(t)
var getOrdersRequest = exchange.GetOrdersRequest{
OrderType: exchange.AnyOrderType,
Currencies: []pair.CurrencyPair{pair.NewCurrencyPair(symbol.BTC, symbol.LTC)},
OrderType: exchange.AnyOrderType,
Currencies: []currency.Pair{currency.NewPair(currency.BTC,
currency.LTC)},
}
_, err := c.GetOrderHistory(getOrdersRequest)
@@ -239,10 +236,10 @@ func TestSubmitOrder(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
var p = pair.CurrencyPair{
Delimiter: "",
FirstCurrency: symbol.BTC,
SecondCurrency: symbol.USD,
var p = currency.Pair{
Delimiter: "",
Base: currency.BTC,
Quote: currency.USD,
}
response, err := c.SubmitOrder(p, exchange.BuyOrderSide, exchange.LimitOrderType, 1, 10, "1234234")
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
@@ -261,7 +258,7 @@ func TestCancelExchangeOrder(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
@@ -288,7 +285,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
}
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
@@ -337,7 +334,7 @@ func TestWithdraw(t *testing.T) {
TestSetup(t)
var withdrawCryptoRequest = exchange.WithdrawRequest{
Amount: 100,
Currency: symbol.LTC,
Currency: currency.LTC,
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
Description: "WITHDRAW IT ALL",
}
@@ -385,7 +382,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
}
func TestGetDepositAddress(t *testing.T) {
_, err := c.GetDepositAddress(symbol.BTC, "")
_, err := c.GetDepositAddress(currency.BTC, "")
if err == nil {
t.Error("Test Failed - GetDepositAddress() function unsupported cannot be nil")
}

View File

@@ -2,11 +2,10 @@ package coinut
// GenericResponse is the generic response you will get from coinut
type GenericResponse struct {
Nonce int64 `json:"nonce"`
Reply string `json:"reply"`
Status []string `json:"status"`
TransID int64 `json:"trans_id"`
Timestamp int64 `json:"timestamp"`
Nonce int64 `json:"nonce"`
Reply string `json:"reply"`
Status []string `json:"status"`
TransID int64 `json:"trans_id"`
}
// InstrumentBase holds information on base currency

View File

@@ -9,7 +9,7 @@ import (
"github.com/gorilla/websocket"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
)
@@ -111,7 +111,7 @@ func (c *COINUT) WsHandleData() {
c.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Exchange: c.GetName(),
Asset: "SPOT",
Pair: pair.NewCurrencyPairFromString(currencyPair),
Pair: currency.NewPairFromString(currencyPair),
}
case "inst_order_book_update":
@@ -133,7 +133,7 @@ func (c *COINUT) WsHandleData() {
c.Websocket.DataHandler <- exchange.WebsocketOrderbookUpdate{
Exchange: c.GetName(),
Asset: "SPOT",
Pair: pair.NewCurrencyPairFromString(currencyPair),
Pair: currency.NewPairFromString(currencyPair),
}
case "inst_trade":
@@ -156,7 +156,7 @@ func (c *COINUT) WsHandleData() {
c.Websocket.DataHandler <- exchange.TradeData{
Timestamp: time.Unix(tradeUpdate.Timestamp, 0),
CurrencyPair: pair.NewCurrencyPairFromString(currencyPair),
CurrencyPair: currency.NewPairFromString(currencyPair),
AssetType: "SPOT",
Exchange: c.GetName(),
Price: tradeUpdate.Price,
@@ -277,7 +277,7 @@ func (c *COINUT) WsSubscribe() error {
for _, p := range pairs {
ticker := wsRequest{
Request: "inst_tick",
InstID: instrumentListByString[p.Pair().String()],
InstID: instrumentListByString[p.String()],
Subscribe: true,
Nonce: c.GetNonce(),
}
@@ -294,7 +294,7 @@ func (c *COINUT) WsSubscribe() error {
ob := wsRequest{
Request: "inst_order_book",
InstID: instrumentListByString[p.Pair().String()],
InstID: instrumentListByString[p.String()],
Subscribe: true,
Nonce: c.GetNonce(),
}
@@ -333,17 +333,15 @@ func (c *COINUT) WsProcessOrderbookSnapshot(ob WsOrderbookSnapshot) error {
var newOrderbook orderbook.Base
newOrderbook.Asks = asks
newOrderbook.Bids = bids
newOrderbook.CurrencyPair = instrumentListByCode[ob.InstID]
newOrderbook.Pair = pair.NewCurrencyPairFromString(instrumentListByCode[ob.InstID])
newOrderbook.Pair = currency.NewPairFromString(instrumentListByCode[ob.InstID])
newOrderbook.AssetType = "SPOT"
newOrderbook.LastUpdated = time.Now()
return c.Websocket.Orderbook.LoadSnapshot(newOrderbook, c.GetName(), false)
}
// WsProcessOrderbookUpdate process an orderbook update
func (c *COINUT) WsProcessOrderbookUpdate(ob WsOrderbookUpdate) error {
p := pair.NewCurrencyPairFromString(instrumentListByCode[ob.InstID])
p := currency.NewPairFromString(instrumentListByCode[ob.InstID])
if ob.Side == "buy" {
return c.Websocket.Orderbook.Update([]orderbook.Item{

View File

@@ -9,8 +9,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency/symbol"
"github.com/thrasher-/gocryptotrader/currency"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
@@ -47,7 +46,13 @@ func (c *COINUT) Run() {
currencies = append(currencies, x)
}
err = c.UpdateCurrencies(currencies, false, false)
var newCurrencies currency.Pairs
for _, p := range currencies {
newCurrencies = append(newCurrencies,
currency.NewPairFromString(p))
}
err = c.UpdateCurrencies(newCurrencies, false, false)
if err != nil {
log.Errorf("%s Failed to update available currencies.\n", c.GetName())
}
@@ -64,59 +69,59 @@ func (c *COINUT) GetAccountInfo() (exchange.AccountInfo, error) {
var balances = []exchange.AccountCurrencyInfo{
{
CurrencyName: symbol.BCH,
CurrencyName: currency.BCH,
TotalValue: bal.BCH,
},
{
CurrencyName: symbol.BTC,
CurrencyName: currency.BTC,
TotalValue: bal.BTC,
},
{
CurrencyName: symbol.BTG,
CurrencyName: currency.BTG,
TotalValue: bal.BTG,
},
{
CurrencyName: symbol.CAD,
CurrencyName: currency.CAD,
TotalValue: bal.CAD,
},
{
CurrencyName: symbol.ETC,
CurrencyName: currency.ETC,
TotalValue: bal.ETC,
},
{
CurrencyName: symbol.ETH,
CurrencyName: currency.ETH,
TotalValue: bal.ETH,
},
{
CurrencyName: symbol.LCH,
CurrencyName: currency.LCH,
TotalValue: bal.LCH,
},
{
CurrencyName: symbol.LTC,
CurrencyName: currency.LTC,
TotalValue: bal.LTC,
},
{
CurrencyName: symbol.MYR,
CurrencyName: currency.MYR,
TotalValue: bal.MYR,
},
{
CurrencyName: symbol.SGD,
CurrencyName: currency.SGD,
TotalValue: bal.SGD,
},
{
CurrencyName: symbol.USD,
CurrencyName: currency.USD,
TotalValue: bal.USD,
},
{
CurrencyName: symbol.USDT,
CurrencyName: currency.USDT,
TotalValue: bal.USDT,
},
{
CurrencyName: symbol.XMR,
CurrencyName: currency.XMR,
TotalValue: bal.XMR,
},
{
CurrencyName: symbol.ZEC,
CurrencyName: currency.ZEC,
TotalValue: bal.ZEC,
},
}
@@ -129,9 +134,9 @@ func (c *COINUT) GetAccountInfo() (exchange.AccountInfo, error) {
}
// UpdateTicker updates and returns the ticker for a currency pair
func (c *COINUT) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
func (c *COINUT) UpdateTicker(p currency.Pair, assetType string) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := c.GetInstrumentTicker(c.InstrumentMap[p.Pair().String()])
tick, err := c.GetInstrumentTicker(c.InstrumentMap[p.String()])
if err != nil {
return ticker.Price{}, err
}
@@ -141,13 +146,18 @@ func (c *COINUT) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pri
tickerPrice.Last = tick.Last
tickerPrice.High = tick.HighestBuy
tickerPrice.Low = tick.LowestSell
ticker.ProcessTicker(c.GetName(), p, tickerPrice, assetType)
err = ticker.ProcessTicker(c.GetName(), tickerPrice, assetType)
if err != nil {
return tickerPrice, err
}
return ticker.GetTicker(c.Name, p, assetType)
}
// GetTickerPrice returns the ticker for a currency pair
func (c *COINUT) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
func (c *COINUT) GetTickerPrice(p currency.Pair, assetType string) (ticker.Price, error) {
tickerNew, err := ticker.GetTicker(c.GetName(), p, assetType)
if err != nil {
return c.UpdateTicker(p, assetType)
@@ -156,8 +166,8 @@ func (c *COINUT) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.P
}
// GetOrderbookEx returns orderbook base on the currency pair
func (c *COINUT) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.GetOrderbook(c.GetName(), p, assetType)
func (c *COINUT) GetOrderbookEx(p currency.Pair, assetType string) (orderbook.Base, error) {
ob, err := orderbook.Get(c.GetName(), p, assetType)
if err != nil {
return c.UpdateOrderbook(p, assetType)
}
@@ -165,9 +175,9 @@ func (c *COINUT) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orderboo
}
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (c *COINUT) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
func (c *COINUT) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := c.GetInstrumentOrderbook(c.InstrumentMap[p.Pair().String()], 200)
orderbookNew, err := c.GetInstrumentOrderbook(c.InstrumentMap[p.String()], 200)
if err != nil {
return orderBook, err
}
@@ -180,8 +190,16 @@ func (c *COINUT) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbo
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: orderbookNew.Sell[x].Quantity, Price: orderbookNew.Sell[x].Price})
}
orderbook.ProcessOrderbook(c.GetName(), p, orderBook, assetType)
return orderbook.GetOrderbook(c.Name, p, assetType)
orderBook.Pair = p
orderBook.ExchangeName = c.GetName()
orderBook.AssetType = assetType
err = orderBook.Process()
if err != nil {
return orderBook, err
}
return orderbook.Get(c.Name, p, assetType)
}
// GetFundingHistory returns funding history, deposits and
@@ -193,14 +211,14 @@ func (c *COINUT) GetFundingHistory() ([]exchange.FundHistory, error) {
}
// GetExchangeHistory returns historic trade data since exchange opening.
func (c *COINUT) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error) {
func (c *COINUT) GetExchangeHistory(p currency.Pair, assetType string) ([]exchange.TradeHistory, error) {
var resp []exchange.TradeHistory
return resp, common.ErrNotYetImplemented
}
// SubmitOrder submits a new order
func (c *COINUT) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
func (c *COINUT) SubmitOrder(p currency.Pair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (exchange.SubmitOrderResponse, error) {
var submitOrderResponse exchange.SubmitOrderResponse
var err error
var APIresponse interface{}
@@ -217,7 +235,7 @@ func (c *COINUT) SubmitOrder(p pair.CurrencyPair, side exchange.OrderSide, order
return submitOrderResponse, err
}
currencyArray := instruments.Instruments[p.Pair().String()]
currencyArray := instruments.Instruments[p.String()]
currencyID := currencyArray[0].InstID
switch orderType {
@@ -336,7 +354,7 @@ func (c *COINUT) GetOrderInfo(orderID string) (exchange.OrderDetail, error) {
}
// GetDepositAddress returns a deposit address for a specified currency
func (c *COINUT) GetDepositAddress(cryptocurrency pair.CurrencyItem, accountID string) (string, error) {
func (c *COINUT) GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error) {
return "", common.ErrFunctionNotSupported
}
@@ -379,7 +397,10 @@ func (c *COINUT) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]
for instrument, allInstrumentData := range instruments.Instruments {
for _, instrumentData := range allInstrumentData {
for _, currency := range getOrdersRequest.Currencies {
currStr := fmt.Sprintf("%v%v%v", currency.FirstCurrency.String(), c.ConfigCurrencyPairFormat.Delimiter, currency.SecondCurrency.String())
currStr := fmt.Sprintf("%v%v%v",
currency.Base.String(),
c.ConfigCurrencyPairFormat.Delimiter,
currency.Quote.String())
if strings.EqualFold(currStr, instrument) {
openOrders, err := c.GetOpenOrders(instrumentData.InstID)
if err != nil {
@@ -398,7 +419,7 @@ func (c *COINUT) GetActiveOrders(getOrdersRequest exchange.GetOrdersRequest) ([]
for instrument, allInstrumentData := range instruments.Instruments {
for _, instrumentData := range allInstrumentData {
if instrumentData.InstID == int(order.InstrumentID) {
currPair := pair.NewCurrencyPairDelimiter(instrument, "")
currPair := currency.NewPairDelimiter(instrument, "")
orderSide := exchange.OrderSide(strings.ToUpper(order.Side))
orderDate := time.Unix(order.Timestamp, 0)
orders = append(orders, exchange.OrderDetail{
@@ -433,7 +454,10 @@ func (c *COINUT) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]
for instrument, allInstrumentData := range instruments.Instruments {
for _, instrumentData := range allInstrumentData {
for _, currency := range getOrdersRequest.Currencies {
currStr := fmt.Sprintf("%v%v%v", currency.FirstCurrency.String(), c.ConfigCurrencyPairFormat.Delimiter, currency.SecondCurrency.String())
currStr := fmt.Sprintf("%v%v%v",
currency.Base.String(),
c.ConfigCurrencyPairFormat.Delimiter,
currency.Quote.String())
if strings.EqualFold(currStr, instrument) {
orders, err := c.GetTradeHistory(instrumentData.InstID, -1, -1)
if err != nil {
@@ -452,7 +476,7 @@ func (c *COINUT) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]
for instrument, allInstrumentData := range instruments.Instruments {
for _, instrumentData := range allInstrumentData {
if instrumentData.InstID == int(order.Order.InstrumentID) {
currPair := pair.NewCurrencyPairDelimiter(instrument, "")
currPair := currency.NewPairDelimiter(instrument, "")
orderSide := exchange.OrderSide(strings.ToUpper(order.Order.Side))
orderDate := time.Unix(order.Order.Timestamp, 0)
orders = append(orders, exchange.OrderDetail{
@@ -469,7 +493,8 @@ func (c *COINUT) GetOrderHistory(getOrdersRequest exchange.GetOrdersRequest) ([]
}
}
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks, getOrdersRequest.EndTicks)
exchange.FilterOrdersByTickRange(&orders, getOrdersRequest.StartTicks,
getOrdersRequest.EndTicks)
exchange.FilterOrdersBySide(&orders, getOrdersRequest.OrderSide)
return orders, nil