Posts

Showing posts from April, 2023

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       ...