Files
gocryptotrader/docs/EXCHANGE_API.md
Ryan O'Hara-Reid 08e015a125 exchanges/wrappers: Refactor fetch orderbook/ticker/account info funcs (#1440)
* acrost: Pull thread, examine

* fix tests

* linter

* fix_linter

* revert rm ctx param to limit breakages when merging usptream

* linter fix

* Add in priority update grouping so that tests pass

* Update cmd/exchange_wrapper_standards/exchange_wrapper_standards_test.go

Co-authored-by: Scott <gloriousCode@users.noreply.github.com>

* glorious nits

* fixed spelling

* whoopsie

* aanother whoops

* glorious: NITTERS!

* glorious: further nitters

* srry linter gods

* glorious: nits continued

* sub test p ara lel

* drop main t.Parallel

* fix whoops

* wrappertests: use context with cancel (test)

* linter: fix

* ensure primary execution

* kucoin test fix

* revert standards test changes and bypass non critical errors

* rm single override

* wrap exported error for accounts

* thrasher: nits ch name

* gk: nits

* gk: nits FetchTickerCached -> GetCachedTicker

* gk: nits rn FetchOrderbookCached -> GetCachedOrderbook

* gk: nits rn FetchAccountInfoCached -> GetCachedAccountInfo

* linter: fix

* gk: nits

* thrasher: nitters 1

* thrasher: nitters tmpls

* gk: nitter

---------

Co-authored-by: shazbert <ryan.oharareid@thrasher.io>
Co-authored-by: Scott <gloriousCode@users.noreply.github.com>
2025-02-19 10:47:10 +11:00

4.1 KiB

GoCryptoTrader Unified API

Build Status Software License GoDoc Coverage Status Go Report Card

A cryptocurrency trading bot supporting multiple exchanges written in Golang.

Please note that this bot is under development and is not ready for production!

Community

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

Unified API

GoCryptoTrader supports a unified API for dealing with exchanges. Each exchange has its own wrapper file which maps the exchanges own RESTful endpoints into a standardised way for bot and standalone application usage.

A full breakdown of all the supported wrapper funcs can be found here. Please note that these change on a regular basis as GoCryptoTrader is undergoing rapid development.

Each exchange supports public API endpoints which don't require any authentication (fetching ticker, orderbook, trade data) and also private API endpoints (which require authentication). Some examples include submitting, cancelling and fetching open orders). To use the authenticated API endpoints, you'll need to set your API credentials in either the config.json file or when you initialise an exchange in your application, and also have the appropriate key permissions set for the exchange. Each exchange has a credentials validator which ensures that the API credentials supplied meet the requirements to make an authenticated request.

Public API Ticker Example

    var b bitstamp.Bitstamp
    b.SetDefaults()
    ticker, err := b.GetCachedTicker(context.Background(), currency.NewPair(currency.BTC, currency.USD), asset.Spot)
    if err != nil {
        // Handle error
    }
    fmt.Println(ticker.Last)

Private API Submit Order Example

    var b bitstamp.Bitstamp
    b.SetDefaults()

    // Set default keys 
    b.API.SetKey("your_key") 
    b.API.SetSecret("your_secret") 
    b.API.SetClientID("your_clientid")
    b.API.SetPEMKey("your_PEM_key")
    b.API.SetSubAccount("your_specific_subaccount")

    // Set client/strategy/subsystem specific credentials that will override
    // default credentials.
    // Make a standard context and add credentials to it by using exchange 
    // package helper function DeployCredentialsToContext
    ctx := context.Background() 
    ctx = exchange.DeployCredentialsToContext(ctx, &exchange.Credentials{
        Key:        "your_key",
        Secret:     "your_secret",
        ClientID:   "your_clientid",
        PEMKey:     "your_PEM_key",
        SubAccount: "your_specific_subaccount",
    })


    o := &order.Submit{
        Exchange:  b.Name, // or method GetName() if exchange.IBotInterface
        Pair:      currency.NewPair(currency.BTC, currency.USD),
        Side:      order.Sell,
        Type:      order.Limit,
        Price:     1000000,
        Amount:    0.1,
        AssetType: asset.Spot,
    }

    // Context will be intercepted when sending an authenticated HTTP request. 
    resp, err := b.SubmitOrder(ctx, o)
    if err != nil {
        // Handle error
    }
    fmt.Println(resp.OrderID)