Comments (3)
I did some maths and wrote a function a long time ago. It supports both inverse and usdt perpetual.
/**
* Calculate order quantity
* @param inverse true = Inverse Perpetual, false = USDT Perpetual
* @param balance Free balance (Margin asset)
* @param side true = long, false = short
* @param price Entry price
* @param leverage Leverage
* @param takerFee Taker fee
* @returns
*/
const orderQty = (inverse: boolean, balance: number, side: boolean, price: number, leverage: number, takerFee: number) => {
return inverse ?
balance * price * leverage / (1 + takerFee * (2 * leverage + (side ? 1 : -1))) :
balance / (price * ((1 - takerFee * (side ? 1 : -1)) / leverage + 2 * takerFee));
}
In your case
// BTC at price 44,089.50 with 50x leverage, 50 USDT free balance, 0.06% taker fee
console.log(orderQty(false, 50, true, 44089.5, 50, 0.0006)); // LONG qty 0.05352354453516336
console.log(orderQty(false, 50, false, 44089.5, 50, 0.0006)); // SHORT qty 0.053462986121584066
// SHIB at price 0.030810 with 50x leverage, 50 USDT free balance, 0.06% taker fee
console.log(orderQty(false, 50, true, 0.03081, 50, 0.0006)); // LONG qty 76592.86974304073
console.log(orderQty(false, 50, false, 0.03081, 50, 0.0006)); // SHORT qty 76506.20988664657
You should round down the qty before calling the api. Good Luck.
from bybit-api.
First of all, amazing library.
I'm creating a conditional order but don't know how do I calculate quantity. Is it based on leveraged amount or original?
for example
I have balance of 50 USDT and want to use 100% per trade with following conditions.
BTC at price 44,089.50 with 50x leverage. SHIB at price 0.030810 with 50x leverage.
How do I calculate the qty parameter?
I have the same problem here, did you figure it out?
from bybit-api.
I'm struggling to understand the API.
Why do you need to know the qty?
shouldn't you be able to put the amount you want to trade, the leverage, and the market order? Boom... done?
or am I simplifying things?
from bybit-api.
Related Issues (20)
- Web Crypto API HOT 6
- nextPageCursor in getWithdrawl records. HOT 1
- 'createType' type is missing from AccountOrderV5 Response HOT 1
- client.getPositionInfo HOT 1
- got Uncaught (in promise) TypeError: (0 , crypto_1.createHmac) is not a function HOT 2
- fundingRate missing in ticker delta events HOT 2
- RSA authentication
- Get Server Time and Typings HOT 1
- failed to subscribe HOT 2
- Demo Trading on Testnet HOT 4
- Is there a V5 method: Get Long Short Ratio ? HOT 3
- Demo Trading Api Key Error HOT 2
- Error when config axios request HOT 1
- Add support for the new Websocket API
- Adding missing endpoints and functionalities HOT 2
- Problem connecting to api.bybit.com HOT 5
- React App with WebSocket HOT 1
- Typescript documentation link leads to 404 HOT 1
- position idx not match position mode HOT 1
- (kline.1.BTCUSDT) failed to subscribe. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bybit-api.