Created
May 29, 2019 19:11
-
-
Save djflux/b5fdd4d3bf5028aa1adb7cfbfdd9b50c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as GTT from 'gdax-trading-toolkit'; | |
import { GDAXFeed, GDAXFeedConfig } from 'gdax-trading-toolkit/build/src/exchanges'; | |
import { LiveBookConfig, LiveOrderbook, SkippedMessageEvent, TradeMessage, LevelMessage } from "gdax-trading-toolkit/build/src/core"; | |
import { Ticker } from "gdax-trading-toolkit/build/src/exchanges/PublicExchangeAPI"; | |
import { CumulativePriceLevel } from "gdax-trading-toolkit/build/src/lib"; | |
const logger = GTT.utils.ConsoleLoggerFactory({ level: 'debug' }); | |
const product = 'BTC-USD'; | |
const [base, quote] = product.split('-'); | |
const options: GDAXFeedConfig = { | |
logger: logger, | |
auth: { | |
key: process.env.COINBASE_PRO_KEY, | |
secret: process.env.COINBASE_PRO_SECRET, | |
passphrase: process.env.COINBASE_PRO_PASSPHRASE | |
}, | |
channels: null, | |
wsUrl: process.env.COINBASE_PRO_WS_URL || 'wss://ws-feed-public.sandbox.pro.coinbase.com', | |
apiUrl: process.env.COINBASE_PRO_API_URL || 'https://api-public.sandbox.pro.coinbase.com' | |
}; | |
GTT.Factories.GDAX.getSubscribedFeeds(options, [product]).then((feed: GDAXFeed) => { | |
const config: LiveBookConfig = { | |
product: product, | |
logger: logger | |
}; | |
const book = new LiveOrderbook(config); | |
book.on('LiveOrderbook.ticker', (ticker: Ticker) => { | |
logger.log('info', JSON.stringify(ticker)); | |
}) | |
book.on('LiveOrderbook.trade', (trade: TradeMessage) => { | |
logger.log('warn', JSON.stringify(trade)); | |
}) | |
book.on('LiveOrderbook.update', (msg: LevelMessage) => { | |
logger.log('info', JSON.stringify(msg)); | |
}) | |
book.on('error', (err) => { | |
logger.log('error', 'LiveOrderbook error: ', err); | |
feed.pipe(book); | |
}) | |
book.on('data', () => {}); | |
feed.pipe(book); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment