gmtech-xyz / safe-cex Goto Github PK
View Code? Open in Web Editor NEWAn OpenSource TypeScript library to create rich trading cryptocurrencies interfaces
Home Page: https://tuleep.trade
An OpenSource TypeScript library to create rich trading cryptocurrencies interfaces
Home Page: https://tuleep.trade
[LOG] Loaded 249 Bybit markets
[LOG] Ready to trade on Bybit
[LOG] Loaded Bybit orders
[LOG] Switched to [BTCUSDT:undefined]
async function initializeExchange() {
try {
const exchange = createExchange('bybit', {
key: API_KEY,
secret: API_SECRET,
testnet: false,
// ... other required options
});
// Listen for general logs or errors from the library (if provided)
exchange.on('log', (message, severity) => {
if (severity === 'error') {
console.error(`[ERROR] ${message}`);
} else {
console.log(`[LOG] ${message}`);
}
});
// Start the exchange synchronization
await exchange.start();
// Safe listen to OHLCV updates
try {
// Start listening to OHLCV updates for BTC/USDT with 1-minute intervals
exchange.listenOHLCV({ symbol: "BTCUSDT", timeframe: "1m" }, (ohlcvUpdate) => {
console.log('OHLCV Update:', ohlcvUpdate);
});
} catch (ohlcvError) {
console.error('Error while listening to OHLCV updates:', ohlcvError.message);
}
} catch (error) {
console.error('An error occurred:', error.message);
}
}
initializeExchange()
Hi, e. g. considering we have ETH + USDT balance:
{
"accountAlias": "FzsRXqXqSgoCfWSg",
"asset": "ETH",
"balance": "1.21964998",
"crossWalletBalance": "1.21964998",
"crossUnPnl": "0.00000000",
"availableBalance": "1.25752019",
"maxWithdrawAmount": "1.21964998",
"marginAvailable": true,
"updateTime": 1706132869319
},
{
"accountAlias": "FzsRXqXqSgoCfWSg",
"asset": "USDT",
"balance": "390.25635408",
"crossWalletBalance": "390.25635408",
"crossUnPnl": "6.14934583",
"availableBalance": "2910.76417728",
"maxWithdrawAmount": "390.25635408",
"marginAvailable": true,
"updateTime": 1706127056721
}
Tuleep only picks USDT right now for margin calculation which would show negative used
balance since it's margin.availableBalance - margin.balance
(-2500 in case of example).
In order to fix this, we need to loop over other available assets and increase total + used
by the value of each asset, e. g. taking ETH, we'd bump used by balance * price of ETH = 1.21964998 * 2400 which would make calculation correct.
Before
total | 390.26 USD
free | 2938.65 USD
upnl | 21.52 USD
used | -2548.39 USD
After
total | 3090.48 USD
free | 2936.10 USD
upnl | 19.82 USD
used | 154.38 USD
This is my proposed patch:
Tealstreet@0da55bb
notional calculation is wrong because when u are short and underwater so let's say 10k short and 2k underwater, your notional size is actually 12k not 8k
this.store.updatePosition(position, { entryPrice, contracts, notional: contracts * entryPrice + upnl, unrealizedPnl: upnl, });
here is live example pulling data from balance api and showing calculation
{'symbol': 'FETUSDT',
'unrealizedProfit': '-586.14229725',
'entryPrice': '1.935091870872',
'positionAmt': '-4337',
'notional': '-8978.63573744',
}
entryPricepositionAmt = 8392
notional = entryPricepositionAmt + abs(unrealizedProfit) = 8978
safecex show notional = 7840
Both Binance and ByBit support specifying timestamps to timebox OHLCV data, it would be useful to also be able to do this through safe-cex for fetching historical data.
Happy to attempt to implement this for you
Is it possible to disable bookticker stream or throttle it so will get less often data ? it's getting 3-10mbps on avg it's too much. I was trying to modify code but couldn't figured out.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.