数据爬取不难,计算复杂
win10保存为bat,ANSI编码- @powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
- #根据时间获取数据
- function Get-Data([datetime]$inputDateTime){
- $d=$inputDateTime.AddDays(-1)
- $utcStr='{0:0000}-{1:00}-{2:00}T16:00:00.000Z' -f $d.Year,$d.Month,$d.Day
- return @('{0:0000}-{1:00}-{2:00} 00:00' -f $inputDateTime.Year,$inputDateTime.Month,$inputDateTime.Day)+(($Script:json.data -match $utcStr)[0] | Select-Object -Skip 1)
- }
- #批量获取前n天数据
- function Get-DataArray([datetime]$beginTime,$last){
- $dataArray=[System.Collections.ArrayList]::new();
- [void]$dataArray.Add((Get-Data -inputDateTime $beginTime))
- for($i=1;$i -lt $last;$i++){
- $inputDateTime=$inputDateTime.AddDays(-1)
- [void]$dataArray.Add((Get-Data -inputDateTime $inputDateTime))
- }
- return $dataArray
- }
- #URL
- $url="https://www.okex.me/v2/spot/instruments/BTC-USDT/candles?granularity=86400&size=1000&t=1592064786686"
- $resp=Invoke-WebRequest -UseBasicParsing -Uri $url
- #获取JSON
- $Script:json=$resp.Content | ConvertFrom-Json
- #输入数据
- $input=(Read-Host "输入年月日(格式:20200614)").Trim()
- $inputDateTime=[System.DateTime]::ParseExact($input,"yyyyMMdd",[cultureinfo]::InstalledUICulture)
- #爬取数据
- #计算MA7
- $MA7=0;
- $datas=Get-DataArray -beginTime $inputDateTime -last 7
- $datas | foreach { $MA7+=$_[4] }
- $MA7=[System.Math]::Round($MA7/7,1)
- #计算MA30
- $MA30=0;
- $datas=Get-DataArray -beginTime $inputDateTime -last 30
- $datas | foreach { $MA30+=$_[4] }
- $MA30=[System.Math]::Round($MA30/30,1)
- 'MA7: '+$MA7
- 'MA30: '+$MA30
- #计算KDJ
- #https://baike.baidu.com/item/KDJ%E6%8C%87%E6%A0%87/6328421?fr=aladdin
复制代码 KDJ没看懂是怎么计算的,明天再试试
链接在这儿,大家可以试试https://baike.baidu.com/item/KDJ%E6%8C%87%E6%A0%87/6328421?fr=aladdin |