Rhino.fi
Search
K

Examples

Trading Client

We can use @rhino.fi/client-js to make our own trading client, which makes it easy to place buy or sell orders.

Trading

Using the rhino.fi client library we can connect to our account and make trades using key credentials:
const HDWalletProvider = require('truffle-hdwallet-provider')
const Web3 = require('web3')
const RhinofiClientFactory = require('@rhino.fi/client-js');
async function client () {
const providerUrl = '// Infura or similar provider url //';
const ethPrivKey = '// Your private key //';
const starkPrivateKey = '// Your stark private key //';
const provider = new HDWalletProvider(ethPrivKey, providerUrl);
const web3 = new Web3(provider);
const price = 200
const amount = '0.05'
// order buy params
const buy = {
symbol: "ETH:USDT",
amount,
price,
starkPrivateKey
}
// order sell params
const sell = {
symbol: "ETH:USDT",
amount: `-${amount}`,
price,
starkPrivateKey
}
const rhinofiConfig = {
api: 'https://api.rhino.fi',
wallet: {
type: 'tradingKey',
meta: {
starkPrivateKey
}
}
}
const rhinofi = await RhinofiClientFactory(web3, rhinofiConfig);
// Buy order placing
const rBuyOrder = await rhinofi.submitOrder(buy)
console.info('buy order receipt', JSON.stringify(rBuyOrder))
// Sell order placing
const rSellOrder = await rhinofi.submitOrder(sell)
console.info('sell order receipt', JSON.stringify(rSellOrder))
}
If you decide you want to cancel the order no matter buy or sell, use the returned reference rBuyOrder or rSellOrder to cancel it:
// Order canceling
const rBuyOrder = await rhinofi.submitOrder(buy)
await rhinofi.cancelOrder({ orderId: rBuyOrder._id })

Rebalancing funds

It is possible to easily track your balance using rhino.fi client.

Balance/Deposit/Withdrawals

The client api exposes convenient deposit/withdraw tracking functionality. getBalance Alaways returns latest balance data, but you can use getDeposits to see all deposit history and getWithdrawals to see all pending withdrawals.
const HDWalletProvider = require('truffle-hdwallet-provider')
const Web3 = require('web3')
const RhinofiClientFactory = require('@rhino.fi/client-js');
async function balance () {
const providerUrl = '// Infura or similar provider url //';
const ethPrivKey = '// Your private key //';
const starkPrivateKey = '// Your stark private key //';
const provider = new HDWalletProvider(ethPrivKey, providerUrl);
const web3 = new Web3(provider);
const rhinofiConfig = {
api: 'https://api.rhino.fi',
wallet: {
type: 'tradingKey',
meta: {
starkPrivateKey
}
}
}
const rhinofi = await RhinofiClientFactory(web3, rhinofiConfig);
// balance
const balances = await rhinofi.getBalance()
console.info('balances', balances)
// deposits
const deposits = await rhinofi.getDeposits()
console.info('deposits', deposits)
// withdrawals
const withdrawls = await rhinofi.getWithdrawals()
console.info('withdrawls', withdrawls)
}

Internal Transfers

Internal transfers allow transfering amounts of your rhino.fi token balance to other users of the protocol.

Transfer

Following example shows how to make an internal transfer using rhino.fi client library:
const HDWalletProvider = require('truffle-hdwallet-provider')
const Web3 = require('web3')
const RhinofiClientFactory = require('@rhino.fi/client-js');
async function transfer () {
const providerUrl = '// Infura or similar provider url //';
const ethPrivKey = '// Your private key //';
const starkPrivateKey = '// Your stark private key //';
const token = 'ETH';
const recipientEthAddress = '0x0000000000000000000000000000000000000001'
const amount = '0.005'
const provider = new HDWalletProvider(ethPrivKey, providerUrl);
const web3 = new Web3(provider);
const rhinofiConfig = {
api: 'https://api.rhino.fi',
wallet: {
type: 'tradingKey',
meta: {
starkPrivateKey
}
}
}
const rhinofi = await RhinofiClientFactory(web3, rhinofiConfig);
await rhinofi.transfer({ recipientEthAddress, token, amount })
}