mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 07:26:48 +00:00
Utilising authenticated websocket functions in exchange wrappers (#384)
* Basic concept commit * Initial changes to support bitfinex v2. Reverts linter changes as they suck. Exports bitfinex ws types * Adds ticker, trade and orderbook support * Candles sub that returns no data COMPLETE * Adds authenticated ws support * Adds the barebones endpoints to support * Adds more endpoints * Even more endpoints * minicommit to switch and test * All the interactive types * Adds support for simultaneous connections. Updates tests. Nothing is working * Successfully adds place order. Moves all authenticated endpoints to new switch case * Cancel order and modify order * Cancel all orders, cancel multi orders * Finalises implementation. Uses testMain * Adds WS wrapper support for some funcs * Fixing rebasing issues * Replaces use of currency as a variable. Updates a lot of coinut websocket auth endpoint stuff * Fixes some fun for loops with GetEnabledPairs * Fixes tests impacted by currency var change * Adds coinut support for WS functions. Replaces `order` vars with `ord`. Fixes some for loops too. Removes verbose from bitfinex * So many panics * I'm fixing a hole, where the panics get in, and stops my mind from wandering, where it will go * Moves func `CanUseAuthenticatedWebsocketEndpoint` to Websocket package as it fits better. Adds test coverage of `CanUseAuthenticatedWebsocketEndpoint` * Finishes up all of coinuts ws implementations. * GateIO implementation * Adds some helper funcs for types, sides and status. Adds support for huobi. Removes unnecessary type * Adds forgotten huobi endpoint * Fixes cancel order endpoint * go hates my formatting and so do I * The process to get authenticated kraken websocket to work. Uses testmain. Adds new auth channel, auth subscriptions, auth data handling. Not working yet * Finishes open orders handling * Mini update for status only updates * Fixes some kraken points * Finishes WS kraken since it doesn't work * Unfinished commit, cleaning up types * Finishes the const replacing * Fixes extra GetNAmes after rebase * An end to the cleanup. testmain for gateio * Adds ZB support * Bitfinex cleanup. Renamed func * Testmain-47s for everyone!!! yayaaaaaaa * Adds kraken websocket wrapper support * Fixes rebase issues * Fixes tests from rebase * Adds test for conversion. Fixes for loop. Updates test order pricing. Fixes some poor made tests. Adds proper error handling for ws responses instead of logging them. Fixed issue where commented code ruined kraken ws. * Fixes secret linting issues. Prioritises bitfinex channelID responses over authorised * Fixes sloppy error/var declarations * Fixes crazy bad logic where submit order errors weren't really considered. Parralols alphapoint/alphapoint_test.go. Removes buffer for multi-websocket comms channel. * Removal of inline string and removal of redundant nil checkerinos * Fixes err checks. Checks whether float has decimal. Fixes append. Drops omitempties. Parallel to some tests. Moves var declarations * Replaces my lazy sprintfs with strconv.FormatInt(time.Now().Unix(), 10) * Adds shiny new FullyMatched bool. Fixes coinbene buy sell consts * Fixes oopsie with coinbene const replacement * Fixes currency issue * Cleans up new places that use JSONDecode * Fixes huge panic bug from string int conversion. Adds large testtable for strings to order types * Fixes some more strconversion issues. Fixes table test var usage. Changes mapperino name * Added some new scenarios for number splitting * Fixes lint issues * negative num fix * Typo fix * Accuracy warning comment
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package gateio
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
@@ -25,29 +27,28 @@ const (
|
||||
var g Gateio
|
||||
var wsSetupRan bool
|
||||
|
||||
func TestSetDefaults(t *testing.T) {
|
||||
func TestMain(m *testing.M) {
|
||||
g.SetDefaults()
|
||||
}
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
||||
if err != nil {
|
||||
t.Fatal("GateIO load config error", err)
|
||||
log.Fatal("GateIO load config error", err)
|
||||
}
|
||||
gateioConfig, err := cfg.GetExchangeConfig("GateIO")
|
||||
gConf, err := cfg.GetExchangeConfig("GateIO")
|
||||
if err != nil {
|
||||
t.Error("GateIO Setup() init error")
|
||||
log.Fatal("GateIO Setup() init error")
|
||||
}
|
||||
gateioConfig.API.AuthenticatedSupport = true
|
||||
gateioConfig.API.AuthenticatedWebsocketSupport = true
|
||||
gateioConfig.API.Credentials.Key = apiKey
|
||||
gateioConfig.API.Credentials.Secret = apiSecret
|
||||
gConf.API.AuthenticatedSupport = true
|
||||
gConf.API.AuthenticatedWebsocketSupport = true
|
||||
gConf.API.Credentials.Key = apiKey
|
||||
gConf.API.Credentials.Secret = apiSecret
|
||||
|
||||
err = g.Setup(gateioConfig)
|
||||
err = g.Setup(gConf)
|
||||
if err != nil {
|
||||
t.Fatal("GateIO setup error", err)
|
||||
log.Fatal("GateIO setup error", err)
|
||||
}
|
||||
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestGetSymbols(t *testing.T) {
|
||||
@@ -100,7 +101,7 @@ func TestCancelExistingOrder(t *testing.T) {
|
||||
func TestGetBalances(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
@@ -173,7 +174,7 @@ func setFeeBuilder() *exchange.FeeBuilder {
|
||||
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
var feeBuilder = setFeeBuilder()
|
||||
g.GetFeeByType(feeBuilder)
|
||||
if apiKey == "" || apiSecret == "" {
|
||||
if !areTestAPIKeysSet() {
|
||||
if feeBuilder.FeeType != exchange.OfflineTradeFee {
|
||||
t.Errorf("Expected %v, received %v", exchange.OfflineTradeFee, feeBuilder.FeeType)
|
||||
}
|
||||
@@ -185,9 +186,6 @@ func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetFee(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var feeBuilder = setFeeBuilder()
|
||||
if areTestAPIKeysSet() {
|
||||
// CryptocurrencyTradeFee Basic
|
||||
@@ -265,20 +263,14 @@ func TestGetFee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFormatWithdrawPermissions(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
expectedResult := exchange.AutoWithdrawCryptoText + " & " + exchange.NoFiatWithdrawalsText
|
||||
|
||||
withdrawPermissions := g.FormatWithdrawPermissions()
|
||||
|
||||
if withdrawPermissions != expectedResult {
|
||||
t.Errorf("Expected: %s, Received: %s", expectedResult, withdrawPermissions)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActiveOrders(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
@@ -292,9 +284,6 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetOrderHistory(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
var getOrdersRequest = order.GetOrdersRequest{
|
||||
OrderType: order.AnyType,
|
||||
}
|
||||
@@ -318,9 +307,6 @@ func areTestAPIKeysSet() bool {
|
||||
}
|
||||
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
@@ -346,15 +332,11 @@ func TestSubmitOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
@@ -372,15 +354,11 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
||||
|
||||
var orderCancellation = &order.Cancel{
|
||||
OrderID: "1",
|
||||
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
||||
@@ -417,6 +395,9 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
_, err := g.ModifyOrder(&order.Modify{})
|
||||
if err == nil {
|
||||
t.Error("ModifyOrder() Expected error")
|
||||
@@ -424,8 +405,6 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
withdrawCryptoRequest := exchange.CryptoWithdrawRequest{
|
||||
GenericWithdrawRequestInfo: exchange.GenericWithdrawRequestInfo{
|
||||
Amount: -1,
|
||||
@@ -449,9 +428,6 @@ func TestWithdraw(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -464,9 +440,6 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -492,9 +465,6 @@ func TestGetDepositAddress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestGetOrderInfo(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
|
||||
if !areTestAPIKeysSet() {
|
||||
t.Skip("no API keys set skipping test")
|
||||
}
|
||||
@@ -509,8 +479,6 @@ func TestGetOrderInfo(t *testing.T) {
|
||||
|
||||
// TestWsGetBalance dials websocket, sends balance request.
|
||||
func TestWsGetBalance(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport || !areTestAPIKeysSet() {
|
||||
t.Skip(wshandler.WebsocketNotEnabled)
|
||||
}
|
||||
@@ -541,12 +509,14 @@ func TestWsGetBalance(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
_, err = g.wsGetBalance([]string{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWsGetOrderInfo dials websocket, sends order info request.
|
||||
func TestWsGetOrderInfo(t *testing.T) {
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport || !areTestAPIKeysSet() {
|
||||
t.Skip(wshandler.WebsocketNotEnabled)
|
||||
}
|
||||
@@ -573,7 +543,7 @@ func TestWsGetOrderInfo(t *testing.T) {
|
||||
if resp.Result.Status != "success" {
|
||||
t.Fatal("Unsuccessful login")
|
||||
}
|
||||
_, err = g.wsGetOrderInfo("EOS_USDT", 0, 10)
|
||||
_, err = g.wsGetOrderInfo("EOS_USDT", 0, 1000)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -583,8 +553,6 @@ func setupWSTestAuth(t *testing.T) {
|
||||
if wsSetupRan {
|
||||
return
|
||||
}
|
||||
g.SetDefaults()
|
||||
TestSetup(t)
|
||||
if !g.Websocket.IsEnabled() && !g.API.AuthenticatedWebsocketSupport {
|
||||
t.Skip(wshandler.WebsocketNotEnabled)
|
||||
}
|
||||
|
||||
@@ -445,19 +445,19 @@ type WebSocketOrderQueryResult struct {
|
||||
|
||||
// WebSocketOrderQueryRecords contains order information from a order.query websocket request
|
||||
type WebSocketOrderQueryRecords struct {
|
||||
ID int `json:"id"`
|
||||
ID int64 `json:"id"`
|
||||
Market string `json:"market"`
|
||||
User int `json:"user"`
|
||||
User int64 `json:"user"`
|
||||
Ctime float64 `json:"ctime"`
|
||||
Mtime float64 `json:"mtime"`
|
||||
Price string `json:"price"`
|
||||
Amount string `json:"amount"`
|
||||
Left string `json:"left"`
|
||||
DealFee string `json:"dealFee"`
|
||||
OrderType int `json:"orderType"`
|
||||
Type int `json:"type"`
|
||||
FilledAmount string `json:"filledAmount"`
|
||||
FilledTotal string `json:"filledTotal"`
|
||||
Price float64 `json:"price,string"`
|
||||
Amount float64 `json:"amount,string"`
|
||||
Left float64 `json:"left,string"`
|
||||
DealFee float64 `json:"dealFee,string"`
|
||||
OrderType int64 `json:"orderType"`
|
||||
Type int64 `json:"type"`
|
||||
FilledAmount float64 `json:"filledAmount,string"`
|
||||
FilledTotal float64 `json:"filledTotal,string"`
|
||||
}
|
||||
|
||||
// WebsocketAuthenticationResponse contains the result of a login request
|
||||
@@ -473,14 +473,14 @@ type WebsocketAuthenticationResponse struct {
|
||||
type wsGetBalanceRequest struct {
|
||||
ID int64 `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Params []string `json:"params,omitempty"`
|
||||
Params []string `json:"params"`
|
||||
}
|
||||
|
||||
// WsGetBalanceResponse stores WS GetBalance response
|
||||
type WsGetBalanceResponse struct {
|
||||
Error interface{} `json:"error"`
|
||||
Result map[currency.Code]WsGetBalanceResponseData `json:"result,omitempty"`
|
||||
ID int64 `json:"id"`
|
||||
Error interface{} `json:"error"`
|
||||
Result map[string]WsGetBalanceResponseData `json:"result"`
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
|
||||
// WsGetBalanceResponseData contains currency data
|
||||
|
||||
@@ -40,6 +40,7 @@ func (g *Gateio) WsConnect() error {
|
||||
_, err = g.wsServerSignIn()
|
||||
if err != nil {
|
||||
log.Errorf(log.ExchangeSys, "%v - authentication failed: %v\n", g.Name, err)
|
||||
g.Websocket.SetCanUseAuthenticatedEndpoints(false)
|
||||
}
|
||||
g.GenerateAuthenticatedSubscriptions()
|
||||
g.GenerateDefaultSubscriptions()
|
||||
@@ -416,7 +417,7 @@ func (g *Gateio) wsGetOrderInfo(market string, offset, limit int) (*WebSocketOrd
|
||||
if !g.Websocket.CanUseAuthenticatedEndpoints() {
|
||||
return nil, fmt.Errorf("%v not authorised to get order info", g.Name)
|
||||
}
|
||||
order := WebsocketRequest{
|
||||
ord := WebsocketRequest{
|
||||
ID: g.WebsocketConn.GenerateMessageID(true),
|
||||
Method: "order.query",
|
||||
Params: []interface{}{
|
||||
@@ -425,7 +426,7 @@ func (g *Gateio) wsGetOrderInfo(market string, offset, limit int) (*WebSocketOrd
|
||||
limit,
|
||||
},
|
||||
}
|
||||
resp, err := g.WebsocketConn.SendMessageReturnResponse(order.ID, order)
|
||||
resp, err := g.WebsocketConn.SendMessageReturnResponse(ord.ID, ord)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/convert"
|
||||
"github.com/thrasher-corp/gocryptotrader/config"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
@@ -99,6 +100,8 @@ func (g *Gateio) SetDefaults() {
|
||||
Unsubscribe: true,
|
||||
AuthenticatedEndpoints: true,
|
||||
MessageCorrelation: true,
|
||||
GetOrder: true,
|
||||
AccountBalance: true,
|
||||
},
|
||||
WithdrawPermissions: exchange.AutoWithdrawCrypto |
|
||||
exchange.NoFiatWithdrawals,
|
||||
@@ -269,9 +272,9 @@ func (g *Gateio) FetchOrderbook(p currency.Pair, assetType asset.Item) (orderboo
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (g *Gateio) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbook.Base, error) {
|
||||
var orderBook orderbook.Base
|
||||
currency := g.FormatExchangeCurrency(p, assetType).String()
|
||||
curr := g.FormatExchangeCurrency(p, assetType).String()
|
||||
|
||||
orderbookNew, err := g.GetOrderbook(currency)
|
||||
orderbookNew, err := g.GetOrderbook(curr)
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
@@ -306,61 +309,78 @@ func (g *Gateio) UpdateOrderbook(p currency.Pair, assetType asset.Item) (orderbo
|
||||
// ZB exchange
|
||||
func (g *Gateio) GetAccountInfo() (exchange.AccountInfo, error) {
|
||||
var info exchange.AccountInfo
|
||||
|
||||
balance, err := g.GetBalances()
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
var balances []exchange.AccountCurrencyInfo
|
||||
|
||||
switch l := balance.Locked.(type) {
|
||||
case map[string]interface{}:
|
||||
for x := range l {
|
||||
lockedF, err := strconv.ParseFloat(l[x].(string), 64)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(x),
|
||||
Hold: lockedF,
|
||||
if g.Websocket.CanUseAuthenticatedWebsocketForWrapper() {
|
||||
resp, err := g.wsGetBalance([]string{})
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
var currData []exchange.AccountCurrencyInfo
|
||||
for k := range resp.Result {
|
||||
currData = append(currData, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(k),
|
||||
TotalValue: resp.Result[k].Available + resp.Result[k].Freeze,
|
||||
Hold: resp.Result[k].Freeze,
|
||||
})
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
info.Accounts = append(info.Accounts, exchange.Account{
|
||||
Currencies: currData,
|
||||
})
|
||||
} else {
|
||||
balance, err := g.GetBalances()
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
switch v := balance.Available.(type) {
|
||||
case map[string]interface{}:
|
||||
for x := range v {
|
||||
availAmount, err := strconv.ParseFloat(v[x].(string), 64)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
var updated bool
|
||||
for i := range balances {
|
||||
if balances[i].CurrencyName == currency.NewCode(x) {
|
||||
balances[i].TotalValue = balances[i].Hold + availAmount
|
||||
updated = true
|
||||
break
|
||||
switch l := balance.Locked.(type) {
|
||||
case map[string]interface{}:
|
||||
for x := range l {
|
||||
lockedF, err := strconv.ParseFloat(l[x].(string), 64)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
}
|
||||
if !updated {
|
||||
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(x),
|
||||
TotalValue: availAmount,
|
||||
Hold: lockedF,
|
||||
})
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
info.Accounts = append(info.Accounts, exchange.Account{
|
||||
Currencies: balances,
|
||||
})
|
||||
switch v := balance.Available.(type) {
|
||||
case map[string]interface{}:
|
||||
for x := range v {
|
||||
availAmount, err := strconv.ParseFloat(v[x].(string), 64)
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
|
||||
var updated bool
|
||||
for i := range balances {
|
||||
if balances[i].CurrencyName == currency.NewCode(x) {
|
||||
balances[i].TotalValue = balances[i].Hold + availAmount
|
||||
updated = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !updated {
|
||||
balances = append(balances, exchange.AccountCurrencyInfo{
|
||||
CurrencyName: currency.NewCode(x),
|
||||
TotalValue: availAmount,
|
||||
})
|
||||
}
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
info.Accounts = append(info.Accounts, exchange.Account{
|
||||
Currencies: balances,
|
||||
})
|
||||
}
|
||||
|
||||
info.Exchange = g.Name
|
||||
|
||||
@@ -401,15 +421,18 @@ func (g *Gateio) SubmitOrder(s *order.Submit) (order.SubmitResponse, error) {
|
||||
}
|
||||
|
||||
response, err := g.SpotNewOrder(spotNewOrderRequestParams)
|
||||
if err != nil {
|
||||
return submitOrderResponse, err
|
||||
}
|
||||
if response.OrderNumber > 0 {
|
||||
submitOrderResponse.OrderID = strconv.FormatInt(response.OrderNumber, 10)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
if response.LeftAmount == 0 {
|
||||
submitOrderResponse.FullyMatched = true
|
||||
}
|
||||
submitOrderResponse.IsOrderPlaced = true
|
||||
|
||||
return submitOrderResponse, err
|
||||
return submitOrderResponse, nil
|
||||
}
|
||||
|
||||
// ModifyOrder will allow of changing orderbook placement and limit to
|
||||
@@ -457,7 +480,6 @@ func (g *Gateio) CancelAllOrders(_ *order.Cancel) (order.CancelAllResponse, erro
|
||||
// GetOrderInfo returns information on a current open order
|
||||
func (g *Gateio) GetOrderInfo(orderID string) (order.Detail, error) {
|
||||
var orderDetail order.Detail
|
||||
|
||||
orders, err := g.GetOpenOrders("")
|
||||
if err != nil {
|
||||
return orderDetail, errors.New("failed to get open orders")
|
||||
@@ -534,40 +556,79 @@ func (g *Gateio) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
func (g *Gateio) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var orders []order.Detail
|
||||
var currPair string
|
||||
if len(req.Currencies) == 1 {
|
||||
currPair = req.Currencies[0].String()
|
||||
}
|
||||
if g.Websocket.CanUseAuthenticatedWebsocketForWrapper() {
|
||||
for i := 0; ; i += 100 {
|
||||
resp, err := g.wsGetOrderInfo(req.OrderType.String(), i, 100)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
|
||||
resp, err := g.GetOpenOrders(currPair)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var orders []order.Detail
|
||||
for i := range resp.Orders {
|
||||
if resp.Orders[i].Status != "open" {
|
||||
continue
|
||||
for j := range resp.WebSocketOrderQueryRecords {
|
||||
orderSide := order.Buy
|
||||
if resp.WebSocketOrderQueryRecords[j].Type == 1 {
|
||||
orderSide = order.Sell
|
||||
}
|
||||
orderType := order.Market
|
||||
if resp.WebSocketOrderQueryRecords[j].OrderType == 1 {
|
||||
orderType = order.Limit
|
||||
}
|
||||
firstNum, decNum, err := convert.SplitFloatDecimals(resp.WebSocketOrderQueryRecords[j].Ctime)
|
||||
if err != nil {
|
||||
return orders, err
|
||||
}
|
||||
orderDate := time.Unix(firstNum, decNum)
|
||||
orders = append(orders, order.Detail{
|
||||
Exchange: g.Name,
|
||||
AccountID: strconv.FormatInt(resp.WebSocketOrderQueryRecords[j].User, 10),
|
||||
ID: strconv.FormatInt(resp.WebSocketOrderQueryRecords[j].ID, 10),
|
||||
CurrencyPair: currency.NewPairFromString(resp.WebSocketOrderQueryRecords[j].Market),
|
||||
OrderSide: orderSide,
|
||||
OrderType: orderType,
|
||||
OrderDate: orderDate,
|
||||
Price: resp.WebSocketOrderQueryRecords[j].Price,
|
||||
Amount: resp.WebSocketOrderQueryRecords[j].Amount,
|
||||
ExecutedAmount: resp.WebSocketOrderQueryRecords[j].FilledAmount,
|
||||
RemainingAmount: resp.WebSocketOrderQueryRecords[j].Left,
|
||||
Fee: resp.WebSocketOrderQueryRecords[j].DealFee,
|
||||
})
|
||||
}
|
||||
if len(resp.WebSocketOrderQueryRecords) < 100 {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resp, err := g.GetOpenOrders(currPair)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
symbol := currency.NewPairDelimiter(resp.Orders[i].CurrencyPair,
|
||||
g.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
side := order.Side(strings.ToUpper(resp.Orders[i].Type))
|
||||
orderDate := time.Unix(resp.Orders[i].Timestamp, 0)
|
||||
for i := range resp.Orders {
|
||||
if resp.Orders[i].Status != "open" {
|
||||
continue
|
||||
}
|
||||
|
||||
orders = append(orders, order.Detail{
|
||||
ID: resp.Orders[i].OrderNumber,
|
||||
Amount: resp.Orders[i].Amount,
|
||||
Price: resp.Orders[i].Rate,
|
||||
RemainingAmount: resp.Orders[i].FilledAmount,
|
||||
OrderDate: orderDate,
|
||||
OrderSide: side,
|
||||
Exchange: g.Name,
|
||||
CurrencyPair: symbol,
|
||||
Status: order.Status(resp.Orders[i].Status),
|
||||
})
|
||||
symbol := currency.NewPairDelimiter(resp.Orders[i].CurrencyPair,
|
||||
g.GetPairFormat(asset.Spot, false).Delimiter)
|
||||
side := order.Side(strings.ToUpper(resp.Orders[i].Type))
|
||||
orderDate := time.Unix(resp.Orders[i].Timestamp, 0)
|
||||
orders = append(orders, order.Detail{
|
||||
ID: resp.Orders[i].OrderNumber,
|
||||
Amount: resp.Orders[i].Amount,
|
||||
Price: resp.Orders[i].Rate,
|
||||
RemainingAmount: resp.Orders[i].FilledAmount,
|
||||
OrderDate: orderDate,
|
||||
OrderSide: side,
|
||||
Exchange: g.Name,
|
||||
CurrencyPair: symbol,
|
||||
Status: order.Status(resp.Orders[i].Status),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
order.FilterOrdersByTickRange(&orders, req.StartTicks, req.EndTicks)
|
||||
order.FilterOrdersBySide(&orders, req.OrderSide)
|
||||
return orders, nil
|
||||
@@ -577,8 +638,8 @@ func (g *Gateio) GetActiveOrders(req *order.GetOrdersRequest) ([]order.Detail, e
|
||||
// Can Limit response to specific order status
|
||||
func (g *Gateio) GetOrderHistory(req *order.GetOrdersRequest) ([]order.Detail, error) {
|
||||
var trades []TradesResponse
|
||||
for _, currency := range req.Currencies {
|
||||
resp, err := g.GetTradeHistory(currency.String())
|
||||
for i := range req.Currencies {
|
||||
resp, err := g.GetTradeHistory(req.Currencies[i].String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user