graphql-ccxt
v0.6.0
Published
wake up bears π» ride bulls π
Downloads
8
Maintainers
Readme
graphql-ccxt
wake up bears π» ride bulls π
You can read the graphql-ccxt GraphQL schema source here.
Features
- Joins together GraphQL and CCXT: can fetch prices, read balance, open orders, etc. on multiple exchanges at once.
- No dependencies other than graphql and ccxt (by the way, installed as peer deps).
- It's isomorphic! It works on a server as usual (see demo below), but also in a browser (see examples/browser/ folder).
- Last but not least, it can be used to increase your income π°π°π°
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:
- graphql
- ccxt
For instance with npm launch
npm install graphql ccxt graphql-ccxt
Demo
- Get this repository code.
- Install deps:
npm install
- Launch the demo:
npm start
Then point your browser to http://localhost:4000/graphql
Take a look to examples/graphql/ folder. It contains both queries and mutations, among others:
- fetch Bitcoin price
- fetch multiple prices, Bitcoin and Ethereum
- fetch your balance
- fetch your balance, only Bitcoin and Ethereum
- create an order
- create orders on multiple exchanges
- fetch available timeframes
- fetch available timeframes for multiple exchanges
- fetch ohlcv candlesticks
- fetch ohlcv candlesticks for multiple exchanges
Access private API
Optionally, before launching the demo server, set the following environment variables accordingly:
BINANCE_APIKEY
BINANCE_APISECRET
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 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
})
// Add few public clients on other exchanges.
await context.addClient({ exchange: 'coinbase' })
await context.addClient({ exchange: 'bitfinex' })
await context.addClient({ exchange: 'bittrex' })
await context.addClient({ exchange: 'kraken' })
await context.addClient({ exchange: 'binance', label: 'Public Binance' })
// 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.info(
'Running a graphql-ccxt server at http://localhost:4000/graphql'
)
})
}
startDemo()