Created
          April 28, 2021 10:22 
        
      - 
      
- 
        Save NoCtrlZ1110/3c0c3f3f9728b80e4bd8a37bdd29ee2b to your computer and use it in GitHub Desktop. 
    Check VNDirect Profit One-Click
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | javascript: function makeHttpObject() { | |
| try { | |
| return new XMLHttpRequest(); | |
| } catch (error) {} | |
| try { | |
| return new ActiveXObject('Msxml2.XMLHTTP'); | |
| } catch (error) {} | |
| try { | |
| return new ActiveXObject('Microsoft.XMLHTTP'); | |
| } catch (error) {} | |
| throw new Error('Could not create HTTP request object!'); | |
| } | |
| var id = 'YOUR_ID_HERE'; | |
| var token = | |
| 'YOUR_TOKEN_HERE'; | |
| var numberWithCommas = (x) => { | |
| return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, '.') + ' VNĐ'; | |
| }; | |
| var getProfit = new Promise(function (resolve, reject) { | |
| var request = makeHttpObject(); | |
| request.open( | |
| 'GET', | |
| `https://trade-api.vndirect.com.vn/accounts/v3/${id}/portfolio` | |
| ); | |
| request.setRequestHeader('x-auth-token', token); | |
| request.send(null); | |
| request.onreadystatechange = function () { | |
| if (request.readyState == 4) { | |
| var data = JSON.parse(request.responseText); | |
| resolve(data); | |
| } | |
| }; | |
| }); | |
| getProfit.then((data) => { | |
| let text = `Gain/Loss: ${numberWithCommas(data.profit)} - Percent: ${ | |
| Math.round(data.ratio * 10000) / 100 | |
| }%\n---\n`; | |
| data.stocks.forEach((s) => { | |
| text += `${s.symbol} || Current: ${ | |
| s.currentPrice / 1000 | |
| } || G/L: ${numberWithCommas(s.gainLoss)} || ${ | |
| Math.round(s.gainLossRatio * 10000) / 100 | |
| }%\n`; | |
| }); | |
| alert(text); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment