Home / Market / go-etoro

go-etoro

Unofficial Go clients for the eToro public API, generated from the specs eToro publishes. The root package `etoro` (`github.com/psyb0t/go-etoro`) is an oapi-codegen REST client for `https://public-api.etoro.com` with a typed `...WithResponse` method per endpoint (balances, market data, instruments, rates, candles, feeds, portfolios, transfers, posts). The `etorows` package (`github.com/psyb0t/go-etoro/ws`) is a typed WebSocket client for `wss://ws.etoro.com/ws` that authenticates, subscribes to

skill★ 00 dlclawhubMIT-0Install in CosmosUpstream Source

Documentation & Preview

go-etoro: setup and reference

This module is unofficial and not affiliated with eToro.

Requirements

Install

go get github.com/psyb0t/go-etoro
go get github.com/google/uuid

github.com/google/uuid is for the per-request XRequestId values. The WebSocket transport, github.com/psyb0t/gen-asyncapi/asyncapirt/gorillaws, comes in with the module's own dependency on github.com/psyb0t/gen-asyncapi; run go mod tidy after the first import.

| Import path | Package | Server | |---|---|---| | github.com/psyb0t/go-etoro | etoro | https://public-api.etoro.com | | github.com/psyb0t/go-etoro/ws | etorows | wss://ws.etoro.com/ws (etorows.ServerEtoroURL) |

REST client

Reading a response

| Field or method | Holds | |---|---| | JSON200, JSON400, ... | The decoded body for that status, nil for any other status | | Headers200, Headers429 | Declared response headers: RateLimitLimit, RateLimitRemaining, RateLimitReset, and RetryAfter on 429 | | Body | The raw body bytes | | StatusCode(), Status() | The HTTP status | | HTTPResponse | The underlying *http.Response |

The method's error is non-nil only when the request could not be sent or the body could not be read or decoded. Check StatusCode() for API errors.

WebSocket client

Handler methods (embed etorows.UnimplementedHandler to skip the ones you do not need):

| Method | Payload | |---|---| | HandleOperationResponse | OperationResponse, the answer to an Authenticate, Subscribe or Unsubscribe | | HandleInstrumentRateMessage | InstrumentRateEnvelope | | HandleInstrumentCandleMessage | InstrumentCandleEnvelope | | HandleInstrumentMarketStatusMessage | InstrumentMarketStatusEnvelope | | HandleOrderUpdateMessage | OrderUpdateEnvelope, for both order update types | | HandlePositionOpenedMessage, HandlePositionClosedMessage | PositionOpenedEnvelope, PositionClosedEnvelope | | HandleUnknownMessage | The raw frame and why it matched nothing |

Each push envelope has Messages; each item has a Topic, a Type and a JSON-encoded content string. item.ContentValue() decodes and validates it. InstrumentRate values (Ask, Bid, LastExecution) are *string because eToro sends them as JSON strings.

Errors

| Error | When | |---|---| | asyncapirt.ErrUnknownMessage | Passed to HandleUnknownMessage for a frame whose type the spec does not list. Run keeps going unless the handler returns an error. | | A validation error | An envelope you send, or a frame you receive, does not match eToro's schema. | | context.Canceled, context.DeadlineExceeded | Run stopped because the context ended (wrapped). |

Use errors.Is to match them.