Last active
April 24, 2022 20:25
-
-
Save BryantAvey/59cc5b676c28056365ce0cca215f3d5d to your computer and use it in GitHub Desktop.
TD Ameritrade API with Neo4j: Cypher to Load Instrument nodes with fundamental data
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 instrument and fundamental | |
CALL apoc.periodic.iterate("UNWIND ['MSFT','SPY','TSLA','AAPL','QQQ','NFLX','NVDA'] AS Symbol RETURN Symbol" | |
,"CALL apoc.load.jsonParams('https://api.tdameritrade.com/v1/instruments?apikey='+ 'YOUR_CONSUMER_KEY_GOES_HERE' +'&symbol=' + Symbol + '&projection=fundamental',{Authorization:'$token[0].access_token' },null) | |
YIELD value | |
UNWIND value[Symbol] AS instrument | |
UNWIND instrument.fundamental as fundamental | |
MERGE (i:Instrument {symbol:instrument.symbol}) | |
SET | |
i.cusip=instrument.cusip, | |
i.description=instrument.description, | |
i.exchange=instrument.exchange, | |
i.assetType=instrument.assetType, | |
// Fundamental Data | |
i.dividendDate=fundamental.dividendDate, | |
i.quickRatio=fundamental.quickRatio, | |
i.operatingMarginTTM=fundamental.operatingMarginTTM, | |
i.operatingMarginMRQ=fundamental.operatingMarginMRQ, | |
i.revChangeYear=fundamental.revChangeYear, | |
i.dividendYield=fundamental.dividendYield, | |
i.high52=fundamental.high52, | |
i.bookValuePerShare=fundamental.bookValuePerShare, | |
i.peRatio=fundamental.peRatio, | |
i.pegRatio=fundamental.pegRatio, | |
i.epsChangePercentTTM=fundamental.epsChangePercentTTM, | |
i.epsChange=fundamental.epsChange, | |
i.shortIntToFloat=fundamental.shortIntToFloat, | |
i.totalDebtToEquity=fundamental.totalDebtToEquity, | |
i.vol10DayAvg=fundamental.vol10DayAvg, | |
i.low52=fundamental.low52, | |
i.divGrowthRate3Year=fundamental.divGrowthRate3Year, | |
i.dividendPayAmount=fundamental.dividendPayAmount, | |
i.prRatio=fundamental.prRatio, | |
i.dividendPayDate=fundamental.dividendPayDate, | |
i.vol1DayAvg=fundamental.vol1DayAvg, | |
i.currentRatio=fundamental.currentRatio, | |
i.epsTTM=fundamental.epsTTM, | |
i.sharesOutstanding=fundamental.sharesOutstanding, | |
i.beta=fundamental.beta, | |
i.pbRatio=fundamental.pbRatio, | |
i.marketCapFloat=fundamental.marketCapFloat, | |
i.marketCap=fundamental.marketCap, | |
i.netProfitMarginMRQ=fundamental.netProfitMarginMRQ, | |
i.ltDebtToEquity=fundamental.ltDebtToEquity, | |
i.revChangeTTM=fundamental.revChangeTTM, | |
i.netProfitMarginTTM=fundamental.netProfitMarginTTM, | |
i.returnOnAssets=fundamental.returnOnAssets, | |
i.dividendAmount=fundamental.dividendAmount, | |
i.returnOnInvestment=fundamental.returnOnInvestment, | |
i.vol3MonthAvg=fundamental.vol3MonthAvg, | |
i.revChangeIn=fundamental.revChangeIn, | |
i.epsChangeYear=fundamental.epsChangeYear, | |
i.pcfRatio=fundamental.pcfRatio, | |
i.totalDebtToCapital=fundamental.totalDebtToCapital, | |
i.interestCoverage=fundamental.interestCoverage, | |
i.returnOnEquity=fundamental.returnOnEquity, | |
i.grossMarginTTM=fundamental.grossMarginTTM, | |
i.shortIntDayToCover=fundamental.shortIntDayToCover, | |
i.grossMarginMRQ=fundamental.grossMarginMRQ | |
;" | |
,{batchSize:10000, parallel:true}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment