Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BryantAvey/08d6db9861bf0f4a0899eb316a551888 to your computer and use it in GitHub Desktop.
Save BryantAvey/08d6db9861bf0f4a0899eb316a551888 to your computer and use it in GitHub Desktop.
TD Ameritrade API with Neo4j: Cypher to load daily price history for each Instrument node
//Load Daily Price History for every Instrument
CALL apoc.periodic.iterate("MATCH (i:Instrument) RETURN i.symbol as Symbol"
, "CALL apoc.load.jsonParams('https://api.tdameritrade.com/v1/marketdata/'+ Symbol + '/pricehistory?apikey=' + 'YOUR_CONSUMER_KEY_GOES_HERE' + '&frequencyType=daily&periodType=year&frequency=1&endDate=' + timestamp() + '&startDate=' + dateTime('2022-04-01').epochMillis , {Authorization:" + '\''+$token[0].access_token+'\'' + "} ,null)
YIELD value
UNWIND value.candles AS cndl
FOREACH (candle in cndl | MERGE (s:Price {ticker: value.symbol,timestamp: datetime.fromepochmillis(candle.datetime) })
ON CREATE SET
s.open = candle.open,
s.close = candle.close,
s.volume = candle.volume,
s.high = candle.high,
s.low = candle.low,
s.timestamp = Date(datetime.fromepochmillis(candle.datetime))
)"
,{batchSize:10000, parallel:false})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment