gateio/gateapi-go

Test Mode does not work consistently with live mode

Opened this issue · 2 comments

consider the following:

type GateIO struct {
	api *gateapi.APIClient
}

func NewGateIO(testMode bool) *GateIO {
	cfg := gateapi.NewConfiguration()

	client := gateapi.NewAPIClient(cfg)
	if testMode {
		log.Println("running in test mode")
		client.ChangeBasePath("https://fx-api-testnet.gateio.ws/api/v4")
	}

	return &GateIO{api: client}
}

and

func (g *GateIO) CheckSupport(ctx context.Context, coin string) (bool, error) {
	cur, _, err := g.api.SpotApi.GetCurrency(ctx, coin)
	if err != nil {
		return false, fmt.Errorf("failed to check support for currency: %w", err)
	}

	return !cur.TradeDisabled, nil
}

Usage:


ctx := context.Background()

	gate := exchange.NewGateIO(false)

	supported, err := gate.CheckSupport(ctx, "DOGE")
	if err != nil {
		log.Fatal(err)
	}

	log.Println("supported:", supported)

prints out supported: true

Now I will turn on test mode and run the same code:

ctx := context.Background()

	gate := exchange.NewGateIO(true)

	supported, err := gate.CheckSupport(ctx, "DOGE")
	if err != nil {
		log.Fatal(err)
	}

	log.Println("supported:", supported)

I receive:

failed to check support for currency: label: MISSING_REQUIRED_HEADER, message: Missing required header: Timestamp

I would expect the test mode to be looser than the Live API,but it seems it is more restrictive.

Spot trading doesn't have test net. When you access fx
-api-test, you are trying to access futures only test net, which will treat any unknown requests as authentication required.

Thanks for the reply. I guess I would change my bug report to the response being unclear then. I would expect to receive a 404 if I am trying to hit a URL that does not exist, not a 401.

I also think it would be worth updating the readme to make this point clearer.