A versatile unofficial ts-lib & node-repl-cli to operate against the Kraken Crypto Exchange
About β’ TLDR β’ Installation β’ Resources β’ Upcoming
ts-kraken is a highly-typed Typescript Library to operate against the Kraken Crypto Exchange REST and WebSocket APIs
It also features an interactive node REPL-cli to operate via command-shell π€
Quickest way to test it out! π
npx ts-kraken
- .help
- .setkeys
- .showkeys
- .get PublicEndpoint params? jqFilter? -table?
.get Ticker pair=XBTUSD .XXBTZUSD|.c[0]|{BTC_PRICE:.}
.get AssetPairs . as $base|keys|map($base[.])|map({pair:.wsname,decimals:.pair_decimals,min:.ordermin}) -table
- .post PrivateEndpoint params? jqFilter? -table?
.post OpenOrders .open as $open|.open|keys|map($open[.].descr) -table
- .find pair orderMatchFilter? maxOffset=1000 jqFilter?
.find ADAETH descr[type]=buy 500 .descr.order
- .pubsub PublicChannel params? jqFilter? -table?
.pubsub ticker pair[]=XBT/USD .[1].c[0]
.pubsub ticker pair[]=XBT/USD&pair[]=ETH/USD . as $base|{pair:.[3],price:$base[1].c[0]}
- .privsub PrivateChannel params? jqFilter? -table?
.privsub openOrders .[0]|map(. as $order|keys[0]|$order[.])
- .unsub ChannelName
.unsub ohlc
- .unsuball
Recommended if planning to use regularly
git clone https://github.com/yeikiu/ts-kraken && cd ts-kraken && npm i
You can create a
.env
file like the following under project's root directory to reuse the keys:
touch .env
# .env's file content holding your API key/secret
KRAKEN_API_KEY=yourApiKey
KRAKEN_API_SECRET=yourApiSecret
npm run kraken-repl
Get IDE code-suggestions for any REST or WS request you need
cd dependant/project/path && npm i ts-kraken
import { publicRESTRequest, privateRESTRequest, getOpenOrdersStream } from 'ts-kraken'
const apiKeys = {
/*
Alternatively you can define your keys under a .env file
or simply set them into process.env as KRAKEN_API_KEY and KRAKEN_API_SECRET
*/
apiKey: 'yourApiKey',
apiSecret: 'yourApiSecret'
}
const testTsKraken = async () => {
const allTradingPairs = await publicRESTRequest({ url: 'AssetPairs' })
console.log(`Total trading pairs: ${Object.keys(allTradingPairs).length}`)
const ethTradingPairInfo = await publicRESTRequest({ url: 'AssetPairs', params: { pair: 'ETHEUR' }})
console.log({ ethTradingPairInfo })
// Fetch balance from a different account injecting keys in runtime
const currentBalances = await privateRESTRequest({ url: 'Balance' }, apiKeys)
console.log({ currentBalances })
// Notice we are not passing an `apiKeys` param in the next private method, process.env ones will be used by default
const { openOrders$ } = await getOpenOrdersStream()
openOrders$.subscribe(openOrdersSnapshot => {
// Output all open orders any time an order status updates
console.log({ openOrdersSnapshot })
})
}
testTsKraken()
While working on your project, if it depends on
ts-kraken
you can invoke the repl in the shell directly with:
npx kraken-repl
- Option to record all requests and incoming streams to json files
- Wrapper-REPL-Command prompting user for request params (with pre-flight validations) for each endpoint/subscription
- Optional flag to save any repl-command output to a file