Posts

connect websocket to binance api and store t he true value in the db

  const WebSocket = require( 'ws' ); const bitcoindata = require( '../model/bitcoindata.model' ); function connectToBinanceWebSocket() {    // Connect to Binance's WebSocket API for the BTC/USDT trading pair    const socket = new WebSocket( 'wss://stream.binance.com:9443/ws/btcusdt@kline_1m' );    // Handle messages received from the WebSocket   socket.on( 'message' , (data) => {      const message = JSON.parse(data);      if (message.e === 'kline' ) {        const candle = message.k;       console.log( `[${new Date(candle.t).toLocaleTimeString()}] Open: ${candle.o}, High: ${candle.h}, Low: ${candle.l}, Close: ${candle.c}` );        if (candle.x == true ) {         console.log({candle})         bitcoindata.crea...

php dynamic search build query

Image
<?php   $hostName = "localhost" ;   $userName = "root" ;   $password = "" ;   $dbName = "pobpaper" ;   $conn = new mysqli ( $hostName , $userName , $password , $dbName );   if ( ! $conn ){     echo "DB is not connected" ;  }   $jt = $_GET [ "jt" ];   $jc = $_GET [ "jc" ];   $myArr = [];   if ( $jt != NULL ){     $new = explode ( " " , $jt );     echo $new [ 0 ];     $c = count ( $new );     echo $c ;     if ( $c == 1 ){         if ( $new [ 0 ] == 'remote' ){             array_push ( $myArr ,( object )[ "st" => 'jobtype' , 'jtid' => '1' ]);         }         else {             array_push ( $myArr ,( object )[ "st" => 'jobtype' , 'jtid' => '2' ]);         }     }     else ...

push notification with service worker

 (works only on chrome)   < script >     // Check if the browser supports service workers     function urlBase64ToUint8Array ( base64String ) {       const padding = '=' . repeat (( 4 - base64String . length % 4 ) % 4 );       const base64 = ( base64String + padding )         . replace ( /-/ g , '+' )         . replace ( /_/ g , '/' );           const rawData = window . atob ( base64 );       const outputArray = new Uint8Array ( rawData . length );           for ( let i = 0 ; i < rawData . length ; ++ i ) {         outputArray [ i ] = rawData . charCodeAt ( i );       }       return outputArray ;     }     if ( 'serviceWorker' in navigator ) {       // Register the service worker       ...

calculate rsi

Image
  const newFunction = async () => {       // https://stackoverflow.com/questions/70452789/node-js-find-the-same-rsi-as-tradingview       // https://gist.github.com/jmoz/1f93b264650376131ed65875782df386       // https://stackoverflow.com/questions/50203625/calculate-rsi-based-on-kraken-ohlc       // topdown1.count({}, function( err, count){           //  console.log( "Number of data in db :", count );           // topdown1.find(async (err,items)=>{                 // if(err){                   //      console.log(err)                 // }                 // else{                     const ticker = await exchange . fetchTicker ( '...

How to fetch last one minute volume of BTC in CCXT Nodejs.

Image
  const exchange = new ccxt . binance (); async   function   getLastOneMinuteVolume () {     try {       const binance = new ccxt . binance ();       const symbol = "BTC/USDT" ;     //   const symbol = "USDT";       const ohlcv = await binance . fetchOHLCV ( symbol , "1m" );         console . log ( ohlcv [ ohlcv . length - 1 ])       const lastCandle = ohlcv [ ohlcv . length - 1 ];       const volume = lastCandle [ 5 ];     //   console.log(lastCandle[5])       console . log ( "Last one minute volume:" , volume );     } catch ( error ) {       console . error ( error );     }   }   //   getLastOneMinuteVolume();   setInterval ( getLastOneMinuteVolume , 1000 ) first data in array is volume in USDT , last is volume in BTC , second is price.

nodejs program to fetch bitcoin price and send message in telegram when bitcoin price is dropped by 0.5% or increase by 0.5%

 same  as the last blogspot just some function is added const express = require ( 'express' ); const app = express (); const ccxt = require ( 'ccxt' ) const http = require ( 'http' ); const server = http . createServer ( app ); const { Server } = require ( "socket.io" ); const { Console } = require ( 'console' ); const { BroadcastChannel } = require ( 'worker_threads' ); const io = new Server ( server ); const TelegramBot = require ( 'node-telegram-bot-api' ); const bot = new TelegramBot ( 'your telegram token' , { polling : true }); app . use ( express . static ( 'public' )); app . use ( express . urlencoded ({ extended : false })) app . use ( express . json ()); app . get ( '/sa' , ( req , res ) => {   res . send ( "sd" ); }); io . on ( 'connection' , async ( fun ) => {     i = 1 ;     s = 2000 ;     console . log ( 'started' )   ...

Node JS program to fetch bitcoin price and showing it in real time using socker.io

Image
 File structure -  package install -  Server.js  const express = require ( 'express' ); const app = express (); const ccxt = require ( 'ccxt' ) const http = require ( 'http' ); const server = http . createServer ( app ); const { Server } = require ( "socket.io" ); const { Console } = require ( 'console' ); const { BroadcastChannel } = require ( 'worker_threads' ); const io = new Server ( server ); app . use ( express . static ( 'public' )); app . use ( express . urlencoded ({ extended : false })) app . use ( express . json ()); app . get ( '/sa' , ( req , res ) => {   res . send ( "sd" ); }); io . on ( 'connection' , async ( fun ) => {     i = 1 ;     s = 2000 ;     console . log ( 'started' )       console . log ( fun . id )       const exchange = new ccxt . binance ()       // Load the markets       let   real = 1 ...