Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@joemccann/robinhood-api

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@joemccann/robinhood-api - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

109

bin/index.js
#! /usr/local/bin/node
const fs = require('fs')
const path = require('path')
const { login, quote } = require('../src')
const fetch = require('node-fetch')
const args = process.argv.slice(2)
const symbols = []
const sleep = (ms = 1000) => {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
const buildPairsFile = async () => {

@@ -31,34 +37,85 @@ const file = await fs

let token = null
let instrument = null
const pairs = JSON.parse(file)
try {
const { data } = await login()
token = data.access_token
} catch (e) {
console.error(e)
}
const proms = []
const pairs = JSON.parse(file)
const combined = {}
const send = async (pair) => {
if (i % 5) await sleep(3000)
if (i > 50) return { data: null }
const { symbol } = pair
const URL = 'https://rh-api-instrument-from-symbol.azurewebsites.net/api/' +
`instrument?symbol=${symbol}`
for (const pair of pairs) {
const { symbol: ticker } = pair
const params = {
token,
ticker
}
let json = null
let resp = null
try {
console.log(`>>> Fetching ${symbol}`)
resp = await fetch(URL)
if (!resp) {
console.log('$$$$ NO RESPONSE $$$$')
console.log(URL)
return {
err: new Error('WTF')
}
}
try {
const { data } = await quote(params)
instrument = data.instrument.split('/')[4]
combined[ticker] = instrument
const { status = 999 } = resp
if (status > 399) {
console.log('>>>>>>>>>>')
console.dir(resp.status)
return {
err: new Error(`Response not ok: ${resp.statusText} | ${resp.status}`)
}
}
json = await resp.json()
} catch (e) {
console.error(e)
if (!resp) {
console.log('$$$$ NO RESPONSE EXCEPTION $$$$')
console.log(URL)
return {
err: new Error('WTF')
}
}
if (resp.status === 404) return { statusCode: 404 }
console.error(e.message)
return { err: e }
}
return { data: { instrument: json.body, symbol } }
}
let i = 0
for (const pair of pairs) {
proms.push(send(pair), i++)
}
const result = []
try {
//
// Flatten the results as one array
//
(await Promise.all(proms)).map(r => {
//
// In the case r is undefined or null
//
if (r) {
const { data = null } = r
if (data) {
console.dir(data)
result.push(data)
}
}
})
} catch (err) {
console.error(err)
return { err }
}
/// ///////////////////
await fs
.writeFileSync(path
.resolve(__dirname, './combined.json'), JSON.stringify(combined), 'utf-8')
.resolve(__dirname, './result.json'), JSON.stringify(result), 'utf-8')
}

@@ -71,3 +128,7 @@

}
// await fetchInstrumentForSymbol()
try {
await fetchInstrumentForSymbol()
} catch (e) {
console.error(e)
}
process.exit(0)

@@ -74,0 +135,0 @@ }

{
"name": "@joemccann/robinhood-api",
"version": "1.2.0",
"version": "1.3.0",
"description": "📈 Unofficial node.js package for the Robinhood.com API.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -18,3 +18,3 @@ # Robinhood API

```sh
USER=XXX
U=XXX
PASS=YYY

@@ -21,0 +21,0 @@ QR=ZZZ # From 2FA from Robinhood

@@ -30,3 +30,3 @@ const fetch = require('node-fetch')

if (resp.status > 399) {
throw new Error(`Response not ok: ${resp.statusText} | ${resp.status}`)
throw new Error(resp.statusText)
}

@@ -36,4 +36,3 @@

} catch (e) {
if (resp.status === 404) return { statusCode: 404 }
console.error(e.message)
if (resp.status === 404) return { data: e.message, statusCode: 404 }
throw e

@@ -40,0 +39,0 @@ }

@@ -19,3 +19,3 @@ require('dotenv').config()

let token = null
const instrumentUUID = null
let instrumentUUID = null

@@ -37,4 +37,2 @@ test('PASS: login - default', async t => {

/*
test('PASS: quote', async t => {

@@ -62,2 +60,21 @@ const sym = 'AAPL'

test('FAIL: quote', async t => {
const sym = 'CTST'
const params = {
token,
symbol: sym
}
try {
const { data, statusCode = 999 } = await quote(params)
t.ok(data)
t.equals(data, 'Not Found')
t.equals(statusCode, 404)
} catch (e) {
console.error(e)
}
t.end()
})
/*
test('PASS: instrument', async t => {

@@ -64,0 +81,0 @@ const sym = 'AAPL'

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc