#
How to use the API
#
Public API
The following API is accessible to anyone without authentication
#
Instruments:
curl "https://paper.nekuti.com:8080/Instrument"
wscat -c wss://paper.nekuti.com:8080/realtime?instruments
#
Public order book:
wscat -c wss://paper.nekuti.com:8080/realtime?subscribe=orderBookL2:BTCUSD
#
Private API
For API calls that concern user data, the request must be authenticated with API keys
#
Request your API Keys
- Navigate to https://paper.nekuti.com
- Click Login to authenticate. If you log in for the first time, it will automatically create a pre-funded account.
- Once authenticated, you can create a pair of API keys for your account by clicking Create API Key
- Save the API Key and the API Secret on your computer, you won’t be able to retrieve them later (but you can always create new pairs as many times as needed)
#
Create an Authorization Header
We assign 2 keys to the account:
- The API Key is passed on each API request to identify the user
- The API Secret is kept on the client and only used to generate a signature which is then passed along with the API Key. Never send your API Secret in the request!
The following function demonstrates how to generate an Authorization header. Save this function into a script and source the script to be able to call the function directly.
function nekuti_header() {
API_KEY="hikCYW0Bf-bu31a28yzZlM_70ncA-XSIsF2XAi3Vr9rtFqXmPkeSKeNuFcwl9nxR-BjlnsZdXphQqECaxjBK9A=="
API_SECRET="BjFcm9ldLGyNV9qLzA_76mwQAflIwoKf_kKjzMFcydn6TYE4FnKs9GLGvCM0hzhgVG4-VT6HyqQkE2aOeAleAw=="
TIMESTAMP=$(date +%s%3N)
SIGNATURE=$(echo -n $API_SECRET$TIMESTAMP | sha256sum)
TOKEN="API.$API_KEY.$TIMESTAMP.$SIGNATURE"
echo "Authorization: Bearer $TOKEN"
}
Now you just need to pass the output of this function as header on REST API calls or WebSocket calls. See examples below.
#
Account Balances
curl -X GET "https://paper.nekuti.com:8080/UserAccount/Balances" -H "$(nekuti_header)"
wscat -c "wss://paper.nekuti.com:8080/private?useraccount" -H "$(nekuti_header)"
#
Account Positions
curl -X GET "https://paper.nekuti.com:8080/UserAccount/Positions" -H "$(nekuti_header)"
wscat -c "wss://paper.nekuti.com:8080/private?positions" -H "$(nekuti_header)"
#
Chaining WebSocket feeds
The same websocket can be used to subscribe to multiple feeds as follows
wscat -c "wss://paper.nekuti.com:8080/private?positions&useraccount" -H "$(nekuti_header)"
#
Order
#
New
curl -X POST "https://paper.nekuti.com:8080/Order?symbol=BTC_USDT&orderQty=-10000&price=60170&timeInForce=GoodTillCancel&execInst=" -H "$(nekuti_header)"
#
List
curl -X GET "https://paper.nekuti.com:8080/Order" -H "$(nekuti_header)"
#
Amend
curl -X PUT "https://paper.nekuti.com:8080/Order?orderID=cf5ea95b-826a-28ff-0fa1-acdeb48a2faa&price=61000" -H "$(nekuti_header)"
#
Cancel
curl -X DELETE "https://paper.nekuti.com:8080/Order?orderID=cf5ea95b-826a-28ff-0fa1-acdeb48a2faa" -H "$(nekuti_header)"
#
System administration
This section is intended for administrators of the engine. Those APIs are not exposed to the user gateway. Replace the admin websocket endpoint (adminServer) with your local endpoint
#
Executions
wscat -c "ws://[adminServer]/realtime?executions"
#
Liquidations
wscat -c "ws://[adminServer]/realtime?liquidations"
#
Message Cache
We support caching past executions and other types of messages and syncing the feed from an arbitrary message index in the past.
- The admin user must first create a message store, this only need to be done once. The engine will start caching any new message from that point forward.
curl -X PUT "http://[adminServer]:8181/MessageStore?storeId=a7046c04-ef01-44da-b136-402790054934"
- In order to keep memory usage under control, the user needs to make sure that the message store is purged regularly. The following request tells the message store to drop all messages up to the index given as argument (included).
curl -X DELETE "http://[adminServer]/MessageStore/Purge?storeId=a7046c04-ef01-44da-b136-402790054934&messageIndex=4215568
- The administrator might want to monitor the size of the cache at any point in time. The following command lists all the message stores and their current depth.
curl -X GET "http://[adminServer]/MessageStore"
- In order to sync the joined message feed from an arbitrary message index in the past, first open a websocket connection with the realtime server, and subscribe to any supported feed as follows:
wscat -c "ws://[adminServer]/joined?funding&executions&liquidations&lastSeen=a7046c04-ef01-44da-b136-402790054934:4215568"
- If for any reason the administrator doesn't need the message store and doesn't want to maintain it, the follow command can be used to delete an existing message store. Note that all messages currently cached will be lost and it won't be possible to sync with this store going forwards
curl -X DELETE "http://[adminServer]/MessageStore?storeId=a7046c04-ef01-44da-b136-402790054934"