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:
constHDWalletProvider=require('truffle-hdwallet-provider')constWeb3=require('web3')constRhinofiClientFactory=require('@rhino.fi/client-js');asyncfunctionclient () {constproviderUrl='// Infura or similar provider url //';constethPrivKey='// Your private key //';conststarkPrivateKey='// Your stark private key //';constprovider=newHDWalletProvider(ethPrivKey, providerUrl);constweb3=newWeb3(provider);constprice=200constamount='0.05'// order buy paramsconstbuy= { symbol:"ETH:USDT", amount, price, starkPrivateKey }// order sell paramsconstsell= { symbol:"ETH:USDT", amount:`-${amount}`, price, starkPrivateKey }constrhinofiConfig= { api:'https://api.rhino.fi', wallet: { type:'tradingKey', meta: { starkPrivateKey } } }constrhinofi=awaitRhinofiClientFactory(web3, rhinofiConfig);// Buy order placingconstrBuyOrder=awaitrhinofi.submitOrder(buy)console.info('buy order receipt',JSON.stringify(rBuyOrder))// Sell order placingconstrSellOrder=awaitrhinofi.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 cancelingconstrBuyOrder=awaitrhinofi.submitOrder(buy)awaitrhinofi.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.
constHDWalletProvider=require('truffle-hdwallet-provider')constWeb3=require('web3')constRhinofiClientFactory=require('@rhino.fi/client-js');asyncfunctionbalance () {constproviderUrl='// Infura or similar provider url //';constethPrivKey='// Your private key //';conststarkPrivateKey='// Your stark private key //';constprovider=newHDWalletProvider(ethPrivKey, providerUrl);constweb3=newWeb3(provider);constrhinofiConfig= { api:'https://api.rhino.fi', wallet: { type:'tradingKey', meta: { starkPrivateKey } } }constrhinofi=awaitRhinofiClientFactory(web3, rhinofiConfig);// balanceconstbalances=awaitrhinofi.getBalance()console.info('balances', balances)// depositsconstdeposits=awaitrhinofi.getDeposits()console.info('deposits', deposits)// withdrawalsconstwithdrawls=awaitrhinofi.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:
constHDWalletProvider=require('truffle-hdwallet-provider')constWeb3=require('web3')constRhinofiClientFactory=require('@rhino.fi/client-js');asyncfunctiontransfer () {constproviderUrl='// Infura or similar provider url //';constethPrivKey='// Your private key //';conststarkPrivateKey='// Your stark private key //';consttoken='ETH';constrecipientEthAddress='0x0000000000000000000000000000000000000001'constamount='0.005'constprovider=newHDWalletProvider(ethPrivKey, providerUrl);constweb3=newWeb3(provider);constrhinofiConfig= { api:'https://api.rhino.fi', wallet: { type:'tradingKey', meta: { starkPrivateKey } } }constrhinofi=awaitRhinofiClientFactory(web3, rhinofiConfig);awaitrhinofi.transfer({ recipientEthAddress, token, amount })}