Coder Social home page Coder Social logo

gmtech-xyz / safe-cex Goto Github PK

View Code? Open in Web Editor NEW
77.0 8.0 21.0 795 KB

An OpenSource TypeScript library to create rich trading cryptocurrencies interfaces

Home Page: https://tuleep.trade

TypeScript 100.00%
api binance bitcoin bybit cryptocurrency ethereum exchange nodejs react rest

safe-cex's People

Contributors

aalwayslucky avatar iam4x avatar lleewwiiss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

safe-cex's Issues

timeframe undefined

[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()

incorrect unified margin calculation on binance + fix

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 for short wrong calculation

this.store.updatePosition(position, {

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 = entryPrice
positionAmt + abs(unrealizedProfit) = 8978
safecex show notional = 7840

Disable !bookTickers stream

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.