Last active
April 24, 2022 20:24
-
-
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
This file contains 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
//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