graphql-ccxt

wake up bears 🐻 ride bulls πŸ‚

You can read the graphql-ccxt GraphQL schema source here.

Features

Credits

Tons of kudos to creators of GraphQL and CCXT. Coders that designed and implemented both projects are so smart and passionate, they are a great example of the power of open source.

Installation

Install this package and add the following peer dependencies:

For instance with npm launch

npm install graphql ccxt graphql-ccxt

Demo

  1. Get this repository code.
  2. Install deps: npm install
  3. Launch the demo: npm start

Then point your browser to http://localhost:4000/graphql

query

Take a look to examples/graphql/ folder. It contains both queries and mutations, among others:

Access private API

Optionally, before launching the demo server, set the following environment variables accordingly:

Demo source code

The demo server is implemented by the following code.

const express = require('express')
const { graphqlHTTP } = require('express-graphql')
const { buildSchema } = require('graphql')
const {
  GraphqlCcxtContext,
  graphqlCcxtRoot,
  graphqlCcxtSchemaSource
} = require('graphql-ccxt')

async function startDemo() {
  // 1. Create GraphQL context. It holds your exchange clients.
  ////
  const context = new GraphqlCcxtContext()
  // Add a public client on Coinbase exchange.
  await context.addClient({
    exchange: 'coinbase'
  })
  // Add another client on Binance exchange.
  // It will be private if environment variables are defined, otherwise it will be public.
  await context.addClient({
    exchange: 'binance',
    apiKey: process.env.BINANCE_APIKEY,
    secret: process.env.BINANCE_APISECRET
  })

  // 2. Build GraphQL schema.
  ////
  const schema = buildSchema(graphqlCcxtSchemaSource)

  // 3. Launch express-graphql server.
  ////
  express()
    .use(
      '/graphql',
      graphqlHTTP({
        schema,
        rootValue: graphqlCcxtRoot,
        context,
        graphiql: {
          defaultQuery: '{ clients { exchange } }'
        }
      })
    )
    .listen(4000, () => {
      console.log(
        'Running a graphql-ccxt server at http://localhost:4000/graphql'
      )
    })
}

startDemo()

License

MIT