ctrader

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2025 License: MIT Imports: 16 Imported by: 0

README

cTrader Go SDK

This repository contains a Go SDK to consume cTrader OpenAPI.

Requirements

  • Go 1.22 or higher.

Execute the tests directly with Go:

go test -tags integration -race ./...

Or you can execute using Earthly:

earthly --secret CTRADER_CLIENT_ID="$CTRADER_CLIENT_ID"
--secret CTRADER_SECRET="$CTRADER_SECRET"
--secret CTRADER_ACCOUNT_ID="$CTRADER_ACCOUNT_ID"
--secret CTRADER_TOKEN="$CTRADER_TOKEN"
+go-test


## FAQ
### How to register an application?
Follow [this](https://help.ctrader.com/open-api/creating-new-app/#register-your-application) instructions.

## How to get an access ID and secret?
The easiest way is to use the
[playground](https://help.ctrader.com/open-api/account-authentication/#using-the-playground).

### How can I upgrade cTrader OpenAPI protobuf files?
- Open the [Earthfile](https://github.com/fxnity/ctrader/blob/main/Earthfile.md) and edit the 
`+compile-proto` target.
- Execute the target `earthly +compile-proto`.
- Sync the dependencies `go mod tidy`.
- Ensure the package still compiles `go build ./...`.
- Open a pull request.

## Documentation
- [Protobuf](./docs/protobuf.md)
- [Testing](./docs/testing.md)

## Acknowledgments
* [ty2/ctrader-go](https://github.com/ty2/ctrader-go)
* [MariaLetta/free-gophers-pack](https://github.com/MariaLetta/free-gophers-pack)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command[A, B proto.Message](ctx context.Context, c *Client, req A) (B, error)

Command is a helper function used to send a request and receive a response.

nolint ireturn

Types

type Client

type Client struct {
	ApplicationClientID string
	ApplicationSecret   string
	HandlerEvent        func(proto.Message)
	Deadline            time.Duration
	Logger              *slog.Logger
	Live                bool
	// contains filtered or unexported fields
}

func (*Client) AccountAuthorize added in v1.0.2

func (c *Client) AccountAuthorize(accessToken string, CtidTraderAccountId int64) error

func (*Client) AccountList added in v1.0.2

func (c *Client) AccountList(accessToken string) ([]*openapi.ProtoOACtidTraderAccount, error)

func (*Client) RefreshAccessToken added in v1.0.3

func (c *Client) RefreshAccessToken(refreshToken string) (string, error)

func (*Client) Start

func (c *Client) Start() error

func (*Client) Stop

func (c *Client) Stop() error

func (*Client) SubscribeSpots added in v1.0.2

func (c *Client) SubscribeSpots(CtidTraderAccountId int64, symbols []int64, withTimeStamps bool) error

func (*Client) SymbolsList added in v1.0.2

func (c *Client) SymbolsList(CtidTraderAccountId int64) ([]*openapi.ProtoOALightSymbol, error)

type ProtoOAError

type ProtoOAError struct {
	ErrorCode               string
	Description             string
	MaintenanceEndTimestamp int64
}

func (ProtoOAError) Error

func (e ProtoOAError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL