mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 07:26:47 +00:00
* Initial changes, removing exchange name as an arg and puts it in the pointer struct. Adds case to ws routines * Adds CancelAllOrders func, adds GetByExchangeAndID. Adds modify handler in routines.go * initial poor attempts to have bitmex work with new datahandler handlers. fixes ordersides * bitmex Completes new order * Better bitmex handling, but not complete. Begins a gargantuan task of unifying order data structs. Sometimes an order update will contain lot's of information, so its best to be able to update all fields of our orders, rather than just an arbitrary subset. As a result, everything will be broken for the foreseeable future :glitch_crab: * Removes old order handler which did nothing. Updates order properties for everything everywhere - now consistent. Changes order status. Adds asset type and wallet address to all order types * Adds order updater to update only relevant fields since the object is generic, we don't know what fields are passed from what exchanges. Adds "lastupdated" field to order.Detail. Expands order cancellation for engine orders. * Ensures that new orders are added to the ordermanager's order store. Saaa many comments. Internalises orderStore get func. Adds internalOrderID to orderdetail and adds websocket support for it * Fixes a cancelAllOrders oopsie doopsie * Adds potential func to update orderdetails from an orderdetail struct. Unsure if will keep. * Begins btcmarkets implementation. Expands order "stringToOrder" funcs to allow for some more flexible string coversions. Removes order.Submit via websocket as it would cause unlimited order place issues :D * Finishes btc markets without testing * Adds untested ws auth func to btse * Finises btse, fixes btcmarkets bug * Adds coinbasepro support * Fixes a few more fields in coinbase pro and readds the extra subs * Begins work on coinbene. Plus theyve added a new ws connection yeee * Wasted a bunch of time adding support to an additional websocket that isn't needed ;_; Fixed a bug in coinbasepro. Fully kitted out coinbene support. Updates order types with all fields * Removes extra websocket connection ;_; * Finishes gemini. Fixes order side unknown * Adds okgroup support. Moves byte reading to another function to allow for unit testing. Updates routines to use pointers. Updates date update handling for order details * Finishes order data for okgroup websocket, but starts the STRANGE process of converting all other websocket endpoints to be a little less silly * Cleans up okroup websocket implementation. Fixes bug in Gemini * Adds poloniex support. Updates ws order handling * new bitmex support. Adds some tests now that its all in its own func. Fixes poloniex bug * Begins work on authenticated binance websocket * Attempts to track user data via binance websocket * Maybe finishes Binance websocket support * Begins adding test coverage to orders.go. Updates names of script properties to match updated * Begins an experiment with code coverage. Fixes more rebase issues * Completes orders coverage. Botches a few other things though. Fixes more scripting stuff * All tests in engine package pass * Adds some loevely routine tests * Moves ordermanager to test Bot ordermanager Adds lovely routine tests to ensure things that get sent to be handled the data handler are handled by the data handler by handling them * Replaces "wsHandleData" with "wsReadData" as that's what its going to do now. * Splits all wsHandleData into wsReadData and wsHandleData to allow for easy testing via sending []byte json examples to test proper functionality. Breaks so many tests * Fixes majority of test issues. But data races which are tough on the engine package * "Fixes" test by removing shutdown test. It interferes with too many things. Requires some thought * Tests all the binance websocket points * Adds better bitfinex websocket support. * Adds testing for bitfinex, bitstamp and btcmarkets. Fixes websocket bugs encountered * Adds BTSE ws tests. Fixes bugs in ws * Adds coinbase pro tests. Fixes any issues * Coinbene tests * Starts to handle coinut. Runs into a problem conceptually regarding websocket roundtrip and orders. Both events need to happen without impacting eachother/racing * Addresses a data race issue regarding websocket and bot order management submission - order submission locks at an earlier point to prevent routines.go from creating an order before order submission creates it. Updates rpcserver to use order management bot to submit orders. * Finishes the hectic coinut testing * Adds tests for gateio * Fixes rebase issues. Updates tests to work without being overloaded * Begins testing of gemini. fixes up minor issues * ginishes gemini tests and fixes * Adds hitbtc tests. Fixes all the many issues with hitbtc websocket * Adds remaining tests. Increases default test channel limit again * Begins work towards huobi tests * Finishes huobi tests * Fixed all mythical rebase adventures * Begins kraken transformation * Finishes kraken. Fixes coinbene leverage now that its changed * Begins okgroup testing * Adds okgroup ws tests * Does some poloniex * Fixes basic curreny issue by extracting to func * Begins redesign of poloniex websocket datahandling. Completes authenticated handling, now onto unauth * Finishes poloniex revision * Finishes ZB additions * Fixes data races * Fixes rebase issues. Fixes bad kraken logic * Fixes after reviewing code * lint everywhere * Fixes lingering lints * lint * Adds test coverage to order detail and modify updating * Fixes linting * Fixes huge int, fixes date tests * Adds GetByExchange, adds test for it. Protects fakepass echange. Renames DisplayQty to DisplayQuantity. Removes verbose. Adds some websocket properties. Updates bitmex asset type in test * Addresses timestamps, type abbreviations, verbosity. Expands binance kline switch cases. Updates some websocket capabilities. * Adds coverage to the stringToOrderType/Status functions introduced in PR * Minor fixes addressing some time, error text and use of StringDataCompareInsensitive * Introduces shiny new system which checks if there is an awaiting ID, if found, processes via wrapper method, else, goes through wsHandleData method. Removes weird locking system from wrapper/websocket data race. Updates bitfinex to properly handle websocket order requests and notifications * Moves fakePassingExchange to test_helper. Fixes some order side implementations for trades. Botches a new error type * Adds new error type to track and handle order classification errors separately * Fully fleshes out ClassificationError for all instances of status conversion. Even in order trades and some wrapper functions * Introduces common.SimpleTimeFormat for "2006-01-02 15:04:05". Fixes binance and bitfinex issues with auth endpoint use, map casting. Expands more order.ClassificationError usage. Fixes some more generic websocket response errors * Future proofs order updating by utilising asset types. Expands testing to accomodate. Adds shiny new time type. Expands wrapper websocket functionality definitions * minty linty * Broken end of day code addressing basic nits on comments, returns and currency conversion * Adds testing to btcmarkets websocket. Also updates websocket orderbook to use update instead * Fixes fun rebase fun fun so fun * Addresses minor nits regarding changed interface and comments * Creates new function `GetRequestFormattedPairAndAssetType` to retrieve a currency pair and asset type based on a string. It will iterate over enabled pairs and compare them to formatted pairs and then return that pair if found. * Fixes test * Adds a single line to the end of the file, because that would be really bad if it wasn't there * Updates fakepassexchange to not use params, updates test params, uses fatal in some tests where its important, updates order manager to have a rwmutex, removes some returns, improves ws key test for binance, updates properties to reflect their actual values, adds some more websocket properties * Addresses binance switch linting * Updates leverage property to int64 * Fixes what was broken
572 lines
16 KiB
Go
572 lines
16 KiB
Go
package itbit
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"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/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/websocket/wshandler"
|
|
"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
|
|
|
|
i.CurrencyPairs = currency.PairsManager{
|
|
AssetTypes: asset.Items{
|
|
asset.Spot,
|
|
},
|
|
UseGlobalFormat: true,
|
|
RequestFormat: ¤cy.PairFormat{
|
|
Uppercase: true,
|
|
},
|
|
ConfigFormat: ¤cy.PairFormat{
|
|
Uppercase: true,
|
|
},
|
|
}
|
|
|
|
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),
|
|
nil)
|
|
|
|
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) {
|
|
tickerPrice := new(ticker.Price)
|
|
tick, err := i.GetTicker(i.FormatExchangeCurrency(p, assetType).String())
|
|
if err != nil {
|
|
return tickerPrice, err
|
|
}
|
|
tickerPrice = &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,
|
|
}
|
|
err = ticker.ProcessTicker(i.Name, tickerPrice, assetType)
|
|
if err != nil {
|
|
return tickerPrice, 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) {
|
|
orderBook := new(orderbook.Base)
|
|
orderbookNew, err := i.GetOrderbook(i.FormatExchangeCurrency(p, assetType).String())
|
|
if err != nil {
|
|
return orderBook, err
|
|
}
|
|
|
|
for x := range orderbookNew.Bids {
|
|
var price, amount float64
|
|
price, err = strconv.ParseFloat(orderbookNew.Bids[x][0], 64)
|
|
if err != nil {
|
|
return orderBook, err
|
|
}
|
|
amount, err = strconv.ParseFloat(orderbookNew.Bids[x][1], 64)
|
|
if err != nil {
|
|
return orderBook, err
|
|
}
|
|
orderBook.Bids = append(orderBook.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 orderBook, err
|
|
}
|
|
amount, err = strconv.ParseFloat(orderbookNew.Asks[x][1], 64)
|
|
if err != nil {
|
|
return orderBook, err
|
|
}
|
|
orderBook.Asks = append(orderBook.Asks,
|
|
orderbook.Item{
|
|
Amount: amount,
|
|
Price: price,
|
|
})
|
|
}
|
|
|
|
orderBook.Pair = p
|
|
orderBook.ExchangeName = i.Name
|
|
orderBook.AssetType = assetType
|
|
|
|
err = orderBook.Process()
|
|
if err != nil {
|
|
return orderBook, 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
|
|
}
|
|
|
|
// GetExchangeHistory returns historic trade data since exchange opening.
|
|
func (i *ItBit) GetExchangeHistory(p currency.Pair, assetType asset.Item) ([]exchange.TradeHistory, error) {
|
|
return nil, common.ErrNotYetImplemented
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
|
|
response, err := i.PlaceOrder(wallet,
|
|
s.Side.String(),
|
|
s.Type.String(),
|
|
s.Pair.Base.String(),
|
|
s.Amount,
|
|
s.Price,
|
|
s.Pair.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(order *order.Cancel) error {
|
|
return i.CancelExistingOrder(order.WalletAddress, order.ID)
|
|
}
|
|
|
|
// CancelAllOrders cancels all orders associated with a currency pair
|
|
func (i *ItBit) CancelAllOrders(orderCancellation *order.Cancel) (order.CancelAllResponse, error) {
|
|
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 information on a current open order
|
|
func (i *ItBit) GetOrderInfo(orderID string) (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
|
|
}
|
|
|
|
// GetWebsocket returns a pointer to the exchange websocket
|
|
func (i *ItBit) GetWebsocket() (*wshandler.Websocket, 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) {
|
|
wallets, err := i.GetWallets(url.Values{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var allOrders []Order
|
|
for x := range wallets {
|
|
resp, err := i.GetOrders(wallets[x].ID, "", "open", 0, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
allOrders = append(allOrders, resp...)
|
|
}
|
|
|
|
var orders []order.Detail
|
|
for j := range allOrders {
|
|
symbol := currency.NewPairDelimiter(allOrders[j].Instrument,
|
|
i.GetPairFormat(asset.Spot, false).Delimiter)
|
|
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) {
|
|
wallets, err := i.GetWallets(url.Values{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var allOrders []Order
|
|
for x := range wallets {
|
|
resp, err := i.GetOrders(wallets[x].ID, "", "", 0, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
allOrders = append(allOrders, resp...)
|
|
}
|
|
|
|
var orders []order.Detail
|
|
for j := range allOrders {
|
|
if allOrders[j].Type == "open" {
|
|
continue
|
|
}
|
|
|
|
symbol := currency.NewPairDelimiter(allOrders[j].Instrument,
|
|
i.GetPairFormat(asset.Spot, false).Delimiter)
|
|
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
|
|
}
|
|
|
|
// SubscribeToWebsocketChannels appends to ChannelsToSubscribe
|
|
// which lets websocket.manageSubscriptions handle subscribing
|
|
func (i *ItBit) SubscribeToWebsocketChannels(channels []wshandler.WebsocketChannelSubscription) error {
|
|
return common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// UnsubscribeToWebsocketChannels removes from ChannelsToSubscribe
|
|
// which lets websocket.manageSubscriptions handle unsubscribing
|
|
func (i *ItBit) UnsubscribeToWebsocketChannels(channels []wshandler.WebsocketChannelSubscription) error {
|
|
return common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// GetSubscriptions returns a copied list of subscriptions
|
|
func (i *ItBit) GetSubscriptions() ([]wshandler.WebsocketChannelSubscription, error) {
|
|
return nil, common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// AuthenticateWebsocket sends an authentication message to the websocket
|
|
func (i *ItBit) AuthenticateWebsocket() error {
|
|
return common.ErrFunctionNotSupported
|
|
}
|
|
|
|
// ValidateCredentials validates current credentials used for wrapper
|
|
// functionality
|
|
func (i *ItBit) ValidateCredentials() error {
|
|
_, err := i.UpdateAccountInfo()
|
|
return i.CheckTransientError(err)
|
|
}
|