https://github.com/fibo/graphql-ccxt
wake up bears 🐻 ride bulls 🐂
https://github.com/fibo/graphql-ccxt
Last synced: 11 months ago
JSON representation
wake up bears 🐻 ride bulls 🐂
- Host: GitHub
- URL: https://github.com/fibo/graphql-ccxt
- Owner: fibo
- License: mit
- Created: 2021-03-23T21:08:28.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-11-16T16:36:14.000Z (over 4 years ago)
- Last Synced: 2025-08-27T05:24:46.943Z (11 months ago)
- Language: JavaScript
- Size: 1.3 MB
- Stars: 19
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graphql-ccxt
> wake up bears 🐻 ride bulls 🐂
You can read the [graphql-ccxt GraphQL schema source here](https://github.com/fibo/graphql-ccxt/blob/main/src/graphql/schema.graphql).
## Features
- Joins together [GraphQL] and [CCXT]: can fetch prices, read balance, open orders, etc.
- No dependencies other than [graphql](https://www.npmjs.com/package/graphql) and [ccxt](https://www.npmjs.com/package/ccxt) (by the way, installed as peer deps).
- 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](https://www.npmjs.com/) launch
```bash
npm install graphql ccxt graphql-ccxt
```
## Demo
0. Get [this repository](https://github.com/fibo/graphql-ccxt) code.
1. Install deps: `npm install`
2. Launch the demo: `npm start`
Then point your browser to http://localhost:4000/graphql

Take a look to [examples/](https://github.com/fibo/graphql-ccxt/tree/main/examples/) folder.
It contains both _queries_ and _mutations_, among others:
- [fetch Bitcoin price](https://github.com/fibo/graphql-ccxt/blob/main/examples/ticker_01.graphql)
- [fetch multiple prices, Bitcoin and Ethereum](https://github.com/fibo/graphql-ccxt/blob/main/examples/tickers_01.graphql)
- [fetch your balance](https://github.com/fibo/graphql-ccxt/blob/main/examples/balance_01.graphql)
- [fetch your balance, only Bitcoin and Ethereum](https://github.com/fibo/graphql-ccxt/blob/main/examples/balance_02.graphql)
- [create an order](https://github.com/fibo/graphql-ccxt/blob/main/examples/createOrder_01.graphql)
- [fetch available timeframes](https://github.com/fibo/graphql-ccxt/blob/main/examples/timeframes_01.graphql)
- [fetch OHLCV candlesticks](https://github.com/fibo/graphql-ccxt/blob/main/examples/candles_01.graphql)
### 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.
```javascript
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 few public clients on some exchanges.
await context.addClient({ exchange: 'binance' })
await context.addClient({ exchange: 'coinbase' })
await context.addClient({ exchange: 'bitfinex' })
await context.addClient({ exchange: 'bittrex' })
await context.addClient({ exchange: 'kraken' })
// Add another Binance client, provide a `label` to disambiguate it.
// It will be private if environment variables are defined,
// otherwise it will be public.
await context.addClient({
exchange: 'binance',
label: 'My 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.info(
'Running a graphql-ccxt server at http://localhost:4000/graphql'
)
})
}
startDemo()
```
## License
[MIT](http://g14n.info/mit-license)
[graphql]: https://graphql.org
[ccxt]: http://ccxt.trade