mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* port orderbook binance management from draft singular asset (spot) processing add additional updates to buffer management * integrate port * shifted burden of proof to exchange and remove repairing techniques that obfuscate issues and could caause artifacts * WIP * Update exchanges, update tests, update configuration so we can default off on buffer util. * Add buffer enabled switching to all exchanges and some that are missing, default to off. * lbtc set not aggregate books * Addr linter issues * EOD wip * optimization and bug fix pass * clean before test and benchmarking * add testing/benchmarks to sorting/reversing functions, dropped pointer to slice as we aren't changing slice len or cap * Add tests and removed ptr for main book as we just ammend amount * addr exchange test issues * ci issues * addr glorious issues * Addr MCB nits, fixed funding rate book for bitfinex and fixed potential panic on nil book return * addr linter issues * updated mistakes * Fix more tests * revert bypass * Addr mcb nits * fix zero price bug caused by exchange. Filted out bid result rather then unsubscribing. Updated orderbook to L2 so there is no aggregation. * Allow for zero bid and ask books to be loaded and warn if found. * remove authentication subscription conflicts as they do not have a channel ID return * WIP - Batching outbound requests for kraken as they do not give you the partial if you subscribe to do many things. * finalised outbound request for kraken * filter zero value due to invalid returned data from exchange, add in max subscription amount and increased outbound batch limit * expand to max allowed book length & fix issue where they were sending a zero length ask side when we sent a depth of zero * Updated function comments and added in more realistic book sizing for sort cases * change map ordering * amalgamate maps in buffer * Rm ln * fix kraken linter issues * add in buffer initialisation * increase timout by 30seconds * Coinbene: Add websocket orderbook length check. * Engine: Improve switch statement for orderbook summary dissplay. * Binance: Added tests, remove deadlock * Exchanges: Change orderbook field -> IsFundingRate * Orderbook Buffer: Added method to orderbookHolder * Kraken: removed superfluous integer for sleep * Bitmex: fixed error return * cmd/gctcli: force 8 decimal place usage for orderbook streaming * Kraken: Add checksum and fix bug where we were dropping returned data which was causing artifacts * Kraken: As per orderbook documentation added in maxdepth field to update to filter depth that goes beyond current scope * Bitfinex: Tracking down bug on margin-funding, added sequence and checksum validation websocket config on connect (WIP) * Bitfinex: Complete implementation of checksum * Bitfinex: Fix funding book insertion and checksum - Dropped updates and deleting items not on book are continuously occuring from stream * Bitfinex: Fix linter issues * Bitfinex: Fix even more linter issues. * Bitmex: Populate orderbook base identification fields to be passed back when error occurrs * OkGroup: Populate orderbook base identification fields to be passed back when error occurrs * BTSE: Change string check to 'connect success' to capture multiple user successful strings * Bitfinex: Updated handling of funding tickers * Bitfinex: Fix undocumented alignment bug for funding rates * Bitfinex: Updated error return with more information * Bitfinex: Change REST fetching to Raw book to keep it in line with websocket implementation. Fix woopsy. * Localbitcoins: Had to impose a rate limiter to stop errors, fixed return for easier error identification. * Exchanges: Update failing tests * LocalBitcoins: Addr nit and bumped time by 1 second for fetching books * Kraken: Dynamically scale precision based on str return for checksum calculations * Kraken: Add pair and asset type to validateCRC32 error reponse * BTSE: Filter out zero amount orderbook price levels in websocket return * Exchanges: Update orderbook functions to return orderbook base to differentiate errors. * BTSE: Fix spelling * Bitmex: Fix error return string * BTSE: Add orderbook filtering function * Coinbene: Change wording * BTSE: Add test for filtering * Binance: Addr nits, added in variables for buffers and worker amounts and fixed error log messages * GolangCI: Remove excess 0 * Binance: Reduces double ups on asset and pair in errors * Binance: Fix error checking
636 lines
18 KiB
Go
636 lines
18 KiB
Go
package itbit
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"sort"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/common"
|
|
"github.com/thrasher-corp/gocryptotrader/config"
|
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/account"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/trade"
|
|
"github.com/thrasher-corp/gocryptotrader/log"
|
|
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
|
)
|
|
|
|
// GetDefaultConfig returns a default exchange config
|
|
func (i *ItBit) GetDefaultConfig() (*config.ExchangeConfig, error) {
|
|
i.SetDefaults()
|
|
exchCfg := new(config.ExchangeConfig)
|
|
exchCfg.Name = i.Name
|
|
exchCfg.HTTPTimeout = exchange.DefaultHTTPTimeout
|
|
exchCfg.BaseCurrencies = i.BaseCurrencies
|
|
|
|
err := i.SetupDefaults(exchCfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if i.Features.Supports.RESTCapabilities.AutoPairUpdates {
|
|
err = i.UpdateTradablePairs(true)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return exchCfg, nil
|
|
}
|
|
|
|
// SetDefaults sets the defaults for the exchange
|
|
func (i *ItBit) SetDefaults() {
|
|
i.Name = "ITBIT"
|
|
i.Enabled = true
|
|
i.Verbose = true
|
|
i.API.CredentialsValidator.RequiresClientID = true
|
|
i.API.CredentialsValidator.RequiresSecret = true
|
|
|
|
requestFmt := ¤cy.PairFormat{Uppercase: true}
|
|
configFmt := ¤cy.PairFormat{Uppercase: true}
|
|
err := i.SetGlobalPairsManager(requestFmt, configFmt, asset.Spot)
|
|
if err != nil {
|
|
log.Errorln(log.ExchangeSys, err)
|
|
}
|
|
|
|
i.Features = exchange.Features{
|
|
Supports: exchange.FeaturesSupported{
|
|
REST: true,
|
|
Websocket: false,
|
|
RESTCapabilities: protocol.Features{
|
|
TickerFetching: true,
|
|
TradeFetching: true,
|
|
OrderbookFetching: true,
|
|
AccountInfo: true,
|
|
GetOrder: true,
|
|
GetOrders: true,
|
|
CancelOrder: true,
|
|
SubmitOrder: true,
|
|
DepositHistory: true,
|
|
WithdrawalHistory: true,
|
|
UserTradeHistory: true,
|
|
CryptoDeposit: true,
|
|
TradeFee: true,
|
|
FiatWithdrawalFee: true,
|
|
},
|
|
WithdrawPermissions: exchange.WithdrawCryptoViaWebsiteOnly |
|
|
exchange.WithdrawFiatViaWebsiteOnly,
|
|
},
|
|
Enabled: exchange.FeaturesEnabled{
|
|
AutoPairUpdates: false,
|
|
},
|
|
}
|
|
|
|
i.Requester = request.New(i.Name,
|
|
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
|
|
|
|
i.API.Endpoints.URLDefault = itbitAPIURL
|
|
i.API.Endpoints.URL = i.API.Endpoints.URLDefault
|
|
}
|
|
|
|
// Setup sets the exchange parameters from exchange config
|
|
func (i *ItBit) Setup(exch *config.ExchangeConfig) error {
|
|
if !exch.Enabled {
|
|
i.SetEnabled(false)
|
|
return nil
|
|
}
|
|
return i.SetupDefaults(exch)
|
|
}
|
|
|
|
// Start starts the ItBit go routine
|
|
func (i *ItBit) Start(wg *sync.WaitGroup) {
|
|
wg.Add(1)
|
|
go func() {
|
|
i.Run()
|
|
wg.Done()
|
|
}()
|
|
}
|
|
|
|
// Run implements the ItBit wrapper
|
|
func (i *ItBit) Run() {
|
|
if i.Verbose {
|
|
i.PrintEnabledPairs()
|
|
}
|
|
}
|
|
|
|
// FetchTradablePairs returns a list of the exchanges tradable pairs
|
|
func (i *ItBit) FetchTradablePairs(asset asset.Item) ([]string, error) {
|
|
return nil, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// UpdateTradablePairs updates the exchanges available pairs and stores
|
|
// them in the exchanges config
|
|
func (i *ItBit) UpdateTradablePairs(forceUpdate bool) error {
|
|
return common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// UpdateTicker updates and returns the ticker for a currency pair
|
|
func (i *ItBit) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
|
fpair, err := i.FormatExchangeCurrency(p, assetType)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
tick, err := i.GetTicker(fpair.String())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = ticker.ProcessTicker(&ticker.Price{
|
|
Last: tick.LastPrice,
|
|
High: tick.High24h,
|
|
Low: tick.Low24h,
|
|
Bid: tick.Bid,
|
|
Ask: tick.Ask,
|
|
Volume: tick.Volume24h,
|
|
Open: tick.OpenToday,
|
|
Pair: p,
|
|
LastUpdated: tick.ServertimeUTC,
|
|
ExchangeName: i.Name,
|
|
AssetType: assetType})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return ticker.GetTicker(i.Name, p, assetType)
|
|
}
|
|
|
|
// FetchTicker returns the ticker for a currency pair
|
|
func (i *ItBit) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error) {
|
|
tickerNew, err := ticker.GetTicker(i.Name, p, assetType)
|
|
if err != nil {
|
|
return i.UpdateTicker(p, assetType)
|
|
}
|
|
return tickerNew, nil
|
|
}
|
|
|
|
// FetchOrderbook returns orderbook base on the currency pair
|
|
func (i *ItBit) FetchOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
|
ob, err := orderbook.Get(i.Name, p, assetType)
|
|
if err != nil {
|
|
return i.UpdateOrderbook(p, assetType)
|
|
}
|
|
return ob, nil
|
|
}
|
|
|
|
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
|
func (i *ItBit) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
|
book := &orderbook.Base{ExchangeName: i.Name, Pair: p, AssetType: assetType, NotAggregated: true}
|
|
fpair, err := i.FormatExchangeCurrency(p, assetType)
|
|
if err != nil {
|
|
return book, err
|
|
}
|
|
|
|
orderbookNew, err := i.GetOrderbook(fpair.String())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for x := range orderbookNew.Bids {
|
|
var price, amount float64
|
|
price, err = strconv.ParseFloat(orderbookNew.Bids[x][0], 64)
|
|
if err != nil {
|
|
return book, err
|
|
}
|
|
amount, err = strconv.ParseFloat(orderbookNew.Bids[x][1], 64)
|
|
if err != nil {
|
|
return book, err
|
|
}
|
|
book.Bids = append(book.Bids,
|
|
orderbook.Item{
|
|
Amount: amount,
|
|
Price: price,
|
|
})
|
|
}
|
|
|
|
for x := range orderbookNew.Asks {
|
|
var price, amount float64
|
|
price, err = strconv.ParseFloat(orderbookNew.Asks[x][0], 64)
|
|
if err != nil {
|
|
return book, err
|
|
}
|
|
amount, err = strconv.ParseFloat(orderbookNew.Asks[x][1], 64)
|
|
if err != nil {
|
|
return book, err
|
|
}
|
|
book.Asks = append(book.Asks,
|
|
orderbook.Item{
|
|
Amount: amount,
|
|
Price: price,
|
|
})
|
|
}
|
|
err = book.Process()
|
|
if err != nil {
|
|
return book, err
|
|
}
|
|
return orderbook.Get(i.Name, p, assetType)
|
|
}
|
|
|
|
// UpdateAccountInfo retrieves balances for all enabled currencies
|
|
func (i *ItBit) UpdateAccountInfo() (account.Holdings, error) {
|
|
var info account.Holdings
|
|
info.Exchange = i.Name
|
|
|
|
wallets, err := i.GetWallets(url.Values{})
|
|
if err != nil {
|
|
return info, err
|
|
}
|
|
|
|
type balance struct {
|
|
TotalValue float64
|
|
Hold float64
|
|
}
|
|
|
|
var amounts = make(map[string]*balance)
|
|
|
|
for x := range wallets {
|
|
for _, cb := range wallets[x].Balances {
|
|
if _, ok := amounts[cb.Currency]; !ok {
|
|
amounts[cb.Currency] = &balance{}
|
|
}
|
|
|
|
amounts[cb.Currency].TotalValue += cb.TotalBalance
|
|
amounts[cb.Currency].Hold += cb.TotalBalance - cb.AvailableBalance
|
|
}
|
|
}
|
|
|
|
var fullBalance []account.Balance
|
|
for key := range amounts {
|
|
fullBalance = append(fullBalance, account.Balance{
|
|
CurrencyName: currency.NewCode(key),
|
|
TotalValue: amounts[key].TotalValue,
|
|
Hold: amounts[key].Hold,
|
|
})
|
|
}
|
|
|
|
info.Accounts = append(info.Accounts, account.SubAccount{
|
|
Currencies: fullBalance,
|
|
})
|
|
|
|
err = account.Process(&info)
|
|
if err != nil {
|
|
return account.Holdings{}, err
|
|
}
|
|
|
|
return info, nil
|
|
}
|
|
|
|
// FetchAccountInfo retrieves balances for all enabled currencies
|
|
func (i *ItBit) FetchAccountInfo() (account.Holdings, error) {
|
|
acc, err := account.GetHoldings(i.Name)
|
|
if err != nil {
|
|
return i.UpdateAccountInfo()
|
|
}
|
|
|
|
return acc, nil
|
|
}
|
|
|
|
// GetFundingHistory returns funding history, deposits and
|
|
// withdrawals
|
|
func (i *ItBit) GetFundingHistory() ([]exchange.FundHistory, error) {
|
|
return nil, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// GetWithdrawalsHistory returns previous withdrawals data
|
|
func (i *ItBit) GetWithdrawalsHistory(c currency.Code) (resp []exchange.WithdrawalHistory, err error) {
|
|
return nil, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetRecentTrades returns the most recent trades for a currency and asset
|
|
func (i *ItBit) GetRecentTrades(p currency.Pair, assetType asset.Item) ([]trade.Data, error) {
|
|
var err error
|
|
p, err = i.FormatExchangeCurrency(p, assetType)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var tradeData Trades
|
|
tradeData, err = i.GetTradeHistory(p.String(), "")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var resp []trade.Data
|
|
for x := range tradeData.RecentTrades {
|
|
resp = append(resp, trade.Data{
|
|
Exchange: i.Name,
|
|
TID: tradeData.RecentTrades[x].MatchNumber,
|
|
CurrencyPair: p,
|
|
AssetType: assetType,
|
|
Price: tradeData.RecentTrades[x].Price,
|
|
Amount: tradeData.RecentTrades[x].Amount,
|
|
Timestamp: tradeData.RecentTrades[x].Timestamp,
|
|
})
|
|
}
|
|
|
|
err = i.AddTradesToBuffer(resp...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
sort.Sort(trade.ByDate(resp))
|
|
return resp, nil
|
|
}
|
|
|
|
// GetHistoricTrades returns historic trade data within the timeframe provided
|
|
func (i *ItBit) GetHistoricTrades(_ currency.Pair, _ asset.Item, _, _ time.Time) ([]trade.Data, error) {
|
|
// cannot do time based retrieval of trade data
|
|
return nil, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// SubmitOrder submits a new order
|
|
func (i *ItBit) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
|
var submitOrderResponse order.SubmitResponse
|
|
if err := s.Validate(); err != nil {
|
|
return submitOrderResponse, err
|
|
}
|
|
|
|
var wallet string
|
|
wallets, err := i.GetWallets(url.Values{})
|
|
if err != nil {
|
|
return submitOrderResponse, err
|
|
}
|
|
|
|
// Determine what wallet ID to use if there is any actual available currency to make the trade!
|
|
for i := range wallets {
|
|
for j := range wallets[i].Balances {
|
|
if wallets[i].Balances[j].Currency == s.Pair.Base.String() &&
|
|
wallets[i].Balances[j].AvailableBalance >= s.Amount {
|
|
wallet = wallets[i].ID
|
|
}
|
|
}
|
|
}
|
|
|
|
if wallet == "" {
|
|
return submitOrderResponse,
|
|
fmt.Errorf("no wallet found with currency: %s with amount >= %v",
|
|
s.Pair.Base,
|
|
s.Amount)
|
|
}
|
|
|
|
fPair, err := i.FormatExchangeCurrency(s.Pair, s.AssetType)
|
|
if err != nil {
|
|
return submitOrderResponse, err
|
|
}
|
|
|
|
response, err := i.PlaceOrder(wallet,
|
|
s.Side.String(),
|
|
s.Type.String(),
|
|
fPair.Base.String(),
|
|
s.Amount,
|
|
s.Price,
|
|
fPair.String(),
|
|
"")
|
|
if err != nil {
|
|
return submitOrderResponse, err
|
|
}
|
|
if response.ID != "" {
|
|
submitOrderResponse.OrderID = response.ID
|
|
}
|
|
|
|
if response.AmountFilled == s.Amount {
|
|
submitOrderResponse.FullyMatched = true
|
|
}
|
|
submitOrderResponse.IsOrderPlaced = true
|
|
return submitOrderResponse, nil
|
|
}
|
|
|
|
// ModifyOrder will allow of changing orderbook placement and limit to
|
|
// market conversion
|
|
func (i *ItBit) ModifyOrder(action *order.Modify) (string, error) {
|
|
return "", common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// CancelOrder cancels an order by its corresponding ID number
|
|
func (i *ItBit) CancelOrder(o *order.Cancel) error {
|
|
if err := o.Validate(o.StandardCancel()); err != nil {
|
|
return err
|
|
}
|
|
return i.CancelExistingOrder(o.WalletAddress, o.ID)
|
|
}
|
|
|
|
// CancelBatchOrders cancels an orders by their corresponding ID numbers
|
|
func (i *ItBit) CancelBatchOrders(o []order.Cancel) (order.CancelBatchResponse, error) {
|
|
return order.CancelBatchResponse{}, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// CancelAllOrders cancels all orders associated with a currency pair
|
|
func (i *ItBit) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
|
if err := orderCancellation.Validate(); err != nil {
|
|
return order.CancelAllResponse{}, err
|
|
}
|
|
cancelAllOrdersResponse := order.CancelAllResponse{
|
|
Status: make(map[string]string),
|
|
}
|
|
openOrders, err := i.GetOrders(orderCancellation.WalletAddress, "", "open", 0, 0)
|
|
if err != nil {
|
|
return cancelAllOrdersResponse, err
|
|
}
|
|
|
|
for j := range openOrders {
|
|
err = i.CancelExistingOrder(orderCancellation.WalletAddress, openOrders[j].ID)
|
|
if err != nil {
|
|
cancelAllOrdersResponse.Status[openOrders[j].ID] = err.Error()
|
|
}
|
|
}
|
|
|
|
return cancelAllOrdersResponse, nil
|
|
}
|
|
|
|
// GetOrderInfo returns order information based on order ID
|
|
func (i *ItBit) GetOrderInfo(orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error) {
|
|
var orderDetail order.Detail
|
|
return orderDetail, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// GetDepositAddress returns a deposit address for a specified currency
|
|
// NOTE: This has not been implemented due to the fact you need to generate a
|
|
// a specific wallet ID and they restrict the amount of deposit address you can
|
|
// request limiting them to 2.
|
|
func (i *ItBit) GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error) {
|
|
return "", common.ErrNotYetImplemented
|
|
}
|
|
|
|
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
|
// submitted
|
|
func (i *ItBit) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
|
return nil, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// WithdrawFiatFunds returns a withdrawal ID when a
|
|
// withdrawal is submitted
|
|
func (i *ItBit) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
|
return nil, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
|
// withdrawal is submitted
|
|
func (i *ItBit) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
|
return nil, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// GetFeeByType returns an estimate of fee based on type of transaction
|
|
func (i *ItBit) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error) {
|
|
if !i.AllowAuthenticatedRequest() && // Todo check connection status
|
|
feeBuilder.FeeType == exchange.CryptocurrencyTradeFee {
|
|
feeBuilder.FeeType = exchange.OfflineTradeFee
|
|
}
|
|
return i.GetFee(feeBuilder)
|
|
}
|
|
|
|
// GetActiveOrders retrieves any orders that are active/open
|
|
func (i *ItBit) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
|
if err := req.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
wallets, err := i.GetWallets(url.Values{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var allOrders []Order
|
|
for x := range wallets {
|
|
var resp []Order
|
|
resp, err = i.GetOrders(wallets[x].ID, "", "open", 0, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
allOrders = append(allOrders, resp...)
|
|
}
|
|
|
|
format, err := i.GetPairFormat(asset.Spot, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var orders []order.Detail
|
|
for j := range allOrders {
|
|
var symbol currency.Pair
|
|
symbol, err := currency.NewPairDelimiter(allOrders[j].Instrument,
|
|
format.Delimiter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
side := order.Side(strings.ToUpper(allOrders[j].Side))
|
|
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
|
|
if err != nil {
|
|
log.Errorf(log.ExchangeSys,
|
|
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
|
i.Name,
|
|
"GetActiveOrders",
|
|
allOrders[j].ID,
|
|
allOrders[j].CreatedTime)
|
|
}
|
|
|
|
orders = append(orders, order.Detail{
|
|
ID: allOrders[j].ID,
|
|
Side: side,
|
|
Amount: allOrders[j].Amount,
|
|
ExecutedAmount: allOrders[j].AmountFilled,
|
|
RemainingAmount: (allOrders[j].Amount - allOrders[j].AmountFilled),
|
|
Exchange: i.Name,
|
|
Date: orderDate,
|
|
Pair: symbol,
|
|
})
|
|
}
|
|
|
|
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
|
order.FilterOrdersBySide(&orders, req.Side)
|
|
order.FilterOrdersByCurrencies(&orders, req.Pairs)
|
|
return orders, nil
|
|
}
|
|
|
|
// GetOrderHistory retrieves account order information
|
|
// Can Limit response to specific order status
|
|
func (i *ItBit) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
|
if err := req.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
wallets, err := i.GetWallets(url.Values{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var allOrders []Order
|
|
for x := range wallets {
|
|
var resp []Order
|
|
resp, err = i.GetOrders(wallets[x].ID, "", "", 0, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
allOrders = append(allOrders, resp...)
|
|
}
|
|
|
|
format, err := i.GetPairFormat(asset.Spot, false)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var orders []order.Detail
|
|
for j := range allOrders {
|
|
if allOrders[j].Type == "open" {
|
|
continue
|
|
}
|
|
var symbol currency.Pair
|
|
symbol, err = currency.NewPairDelimiter(allOrders[j].Instrument,
|
|
format.Delimiter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
side := order.Side(strings.ToUpper(allOrders[j].Side))
|
|
orderDate, err := time.Parse(time.RFC3339, allOrders[j].CreatedTime)
|
|
if err != nil {
|
|
log.Errorf(log.ExchangeSys,
|
|
"Exchange %v Func %v Order %v Could not parse date to unix with value of %v",
|
|
i.Name,
|
|
"GetActiveOrders",
|
|
allOrders[j].ID,
|
|
allOrders[j].CreatedTime)
|
|
}
|
|
|
|
orders = append(orders, order.Detail{
|
|
ID: allOrders[j].ID,
|
|
Side: side,
|
|
Amount: allOrders[j].Amount,
|
|
ExecutedAmount: allOrders[j].AmountFilled,
|
|
RemainingAmount: (allOrders[j].Amount - allOrders[j].AmountFilled),
|
|
Exchange: i.Name,
|
|
Date: orderDate,
|
|
Pair: symbol,
|
|
})
|
|
}
|
|
|
|
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
|
order.FilterOrdersBySide(&orders, req.Side)
|
|
order.FilterOrdersByCurrencies(&orders, req.Pairs)
|
|
return orders, nil
|
|
}
|
|
|
|
// ValidateCredentials validates current credentials used for wrapper
|
|
// functionality
|
|
func (i *ItBit) ValidateCredentials() error {
|
|
_, err := i.UpdateAccountInfo()
|
|
return i.CheckTransientError(err)
|
|
}
|
|
|
|
// GetHistoricCandles returns candles between a time period for a set time interval
|
|
func (i *ItBit) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
|
return kline.Item{}, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
|
|
func (i *ItBit) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
|
return kline.Item{}, common.ErrFunctionNotSupported
|
|
}
|