自动读取虚拟币ETC行情并语音提醒的小工具(mac OSX)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL; public class Price { //默认配置无需修改
public static String API_DOMAIN = "http://api.chbtc.com";
public static String WIN_STR = "你发财了,你发财了,你发财了,你发财了,你发财了,你发财了";
public static String LOSE_STR = "要赔哭了,要赔哭了,要赔哭了,要赔哭了,要赔哭了,要赔哭了";
public static String CUR_PRICE_STR = "当前价格";
public static String PRICE_UP_STR = "上涨突破";
public static String PRICE_DOWN_STR = "下跌突破";
public static String YUAN_STR = "元";
public static String[] bollNotice = new String[]{"b o l l跌破最低值", "b o l l处于低位", "b o l l处于高位", "b o l l突破最高值",};
public static String[] bollName = new String[]{"最低","低","高","最高"};
public static String BTC = "btc_cny";
public static String LTC = "ltc_cny";
public static String ETC = "etc_cny";
public static String ETH = "eth_cny"; //程序动态使用数值
public static int reawrd = 0;
public static float etcPrice = 0;
public static int lastPriceInt = 0;
public static float mb = 0;
public static float up = 0;
public static float dn = 0; public static int state = 0; //用户配置数值
public static float coinCount = 742.103f;//持币数量
public static float sourceMoney = 33200;//总成本
public static float max_price = 5000;//超过此价格,提醒发财
public static float min_price = 0;//跌破此价格,提醒赔哭
public static int sleepTime = 5000;//查询刷新间隔,建议不要太快,单位毫秒 public static void main(String[] args) {
if (args != null) {
if (args.length >= 2) {
min_price = Float.valueOf(args[0]);
max_price = Float.valueOf(args[1]);
} else if (args.length == 1) {
max_price = Float.valueOf(args[0]);
}
} try {
while (true) {
testTicker(BTC);
testTicker(LTC);
getKline();
testTicker(ETC);
testTicker(ETH);
reawrd = (int) (coinCount * etcPrice - sourceMoney); //价格提醒
if (max_price != 0 && etcPrice > max_price) say(WIN_STR);
else if (min_price != 0 && etcPrice < min_price) say(LOSE_STR); //boll提醒
int lastState = state;
if (etcPrice < dn) {
state = 0;
} else if (etcPrice > dn && etcPrice < mb) {
state = 1;
} else if (etcPrice > mb && etcPrice < up) {
state = 2;
} else if (etcPrice > up) {
state = 3;
} System.out.println("boll " + bollName[state]); if (state != lastState) {
say(bollNotice[state]);
}
Thread.sleep(sleepTime); }
} catch (Exception e) {
e.printStackTrace();
}
} /**
* 获取行情
*/
public static void testTicker(String currency) {
try {
// String currency = "btc_cny";
// 请求地址
String url = API_DOMAIN + "/data/v1/ticker?currency=" + currency;
// 请求测试
String callback = get(url, "UTF-8");
int start = callback.indexOf("\"buy\":\"");
int end = callback.indexOf("\",\"high\""); System.out.print(currency.substring(0, 3) + " " + callback.substring(start + 7, end) + "\t");
// System.out.print(currency.substring(0, 3) + " " + callback.substring(start + 7, end) + "\t" + ", mb " + mb + ", up " + up + " , dn " + dn); if (currency.equals(ETC)) {
float curPrice = Float.valueOf(callback.substring(start + 7, end));
if (lastPriceInt == 0) {
say(CUR_PRICE_STR + curPrice + YUAN_STR);
lastPriceInt = (int) curPrice;
} else if ((int) curPrice > lastPriceInt) {
say(CUR_PRICE_STR + PRICE_UP_STR + curPrice + YUAN_STR);
lastPriceInt = (int) curPrice;
} else if ((int) curPrice < lastPriceInt) {
say(CUR_PRICE_STR + PRICE_DOWN_STR + curPrice + YUAN_STR);
lastPriceInt = (int) curPrice;
}
etcPrice = curPrice;
}
} catch (Exception ex) {
ex.printStackTrace();
}
} /**
* @param urlAll :请求接口
* @param charset :字符编码
* @return 返回json结果
*/
public static String get(String urlAll, String charset) {
BufferedReader reader = null;
String result = null;
StringBuffer sbf = new StringBuffer();
String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";// 模拟浏览器
try {
URL url = new URL(urlAll);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(30000);
connection.setConnectTimeout(30000);
connection.setRequestProperty("User-agent", userAgent);
connection.connect();
InputStream is = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, charset));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sbf.append(strRead);
sbf.append("\r\n");
}
reader.close();
result = sbf.toString(); } catch (Exception e) {
e.printStackTrace();
}
return result;
} public static void say(String content) {
try {
//执行命令
Runtime.getRuntime().exec("say \"" + content + "\"");
} catch (IOException e) {
e.printStackTrace();
}
} public static void countBOLL(float[] cs) {
int n = 20;
int k = 2;
float endSum = 0;
for (int i = 0; i < cs.length; i++) {
endSum += cs[i];
}
float ma = endSum / n; float mdSum = 0;
for (int i = 0; i < cs.length; i++) {
mdSum += (cs[i] - ma) * (cs[i] - ma);
}
float md = (float) Math.sqrt(mdSum / n); float mb = (endSum - cs[n - 1]) / (n - 1);
float up = mb + k * md;
float dn = mb - k * md; Price.mb = mb;
Price.up = up;
Price.dn = dn; // System.out.println("up " + up + " ,mb" + mb + " ,dn " + dn);
} public static void getKline() {
try {
String currency = "btc_cny";
// 请求地址
String url = "http://api.chbtc.com/data/v1/kline?currency=etc_cny&type=5min&size=20";
// 请求测试
String callback = get(url, "UTF-8");
String[] split = callback.split(",");
int offsex = 0;
int index = 0;
float cs[] = new float[20];
for (int i = 0; i < split.length; i++) {
if (i == 0) {
offsex += 4;
} else {
offsex += 6;
}
if (offsex < split.length) {
cs[index] = Float.valueOf(split[offsex]);
index++;
} }
countBOLL(cs);
} catch (Exception ex) {
ex.printStackTrace();
}
} }
使用chbtn的API,整数价格变化自动语音提醒,可以自行配置价格语音提醒。
使用时直接
javac Price.java
java Price

更多say命令的使用方式请搜索 mac命令行唱歌
自动读取虚拟币ETC行情并语音提醒的小工具(mac OSX)的更多相关文章
- 快速读取csv平面文件,并导入数据库,简单小工具
using DataToDeal; using LumenWorks.Framework.IO.Csv; using Microsoft.Win32; using System; using Syst ...
- 语音转文字小工具开发Python
# -*- coding: utf- -*- import requests import re import os import time from aip import AipSpeech fro ...
- Java生鲜电商平台-电商虚拟币的充值与消费思考
Java生鲜电商平台-电商虚拟币的充值与消费思考 项目背景 最近由于项目业务原因,需要为系统设计虚拟币的充值及消费功能.公司内已经有成熟的支付网关服务,所以重点变成了如何设计项目内虚拟币的充值流程,让 ...
- 程序员的自我救赎---12.2.3: 虚拟币交易平台(区块链) 下 【C#与以太坊通讯】
<前言> (一) Winner2.0 框架基础分析 (二)PLSQL报表系统 (三)SSO单点登录 (四) 短信中心与消息中心 (五)钱包系统 (六)GPU支付中心 (七)权限系统 (八) ...
- 【PHP】算法进阶,获取给定值的最优组合:虚拟币抵扣问题解决方案
商城里边.虚拟币抵扣问题解决方案 虚拟币抵扣规则,按照以下规则执行: 1.如果一个订单包含多款商品,且均支持虚拟币抵扣时: 优先按照最大化使用虚拟币进行全额抵扣原则进行抵扣,若抵扣后用户虚拟币账号 ...
- Android自动读取短信验证码
Android自动读取短信验证码 extends:http://www.cnblogs.com/jiayaguang/p/4366384.html,http://blog.csdn.net/yung ...
- iOS:自动读取图片插件KSImageNamed-Xcode-master的使用
gitHub链接:https://github.com/ksuther/KSImageNamed-Xcode KSImageNamed-Xcode是一个Xcode插件,可以帮助开发者在Xcode中 ...
- 对于exacoin虚拟币以及其他虚拟币乱象的思考
今天晚上12点正,我帮两个朋友购买exacoin虚拟币,当然我也购买,为了购买我做了充分的准备,包括使用多个浏览器和准备良好的***代理,并转如足量BTC以支持购买,但是通过三天晚上的奋战,让我感觉这 ...
- React会自动把虚拟DOM数组展开
React会自动把虚拟DOM数组展开,放在父级虚拟DOM中,这个特性还是我同事帮我解决一个问题的时候,偶然发现的. 如何将一个数据数组转换为一个虚拟DOM的数组,需要使用map,如下: const n ...
随机推荐
- oracle 回收表空间的数据文件大小
查看表空间的使用情况: " "used MB",b.bytes "free MB", ,) "percent_used" from ...
- sql操作总结
SQL 语句的多表查询方式例如:按照 department_id 查询 employees(员工表)和 departments(部门表)的信息.方式一(通用型):SELECT ... FROM ... ...
- yum只下载软件不安装的两种方法
1 通过yum自带一个工具:yumdownloader rpm -qa |grep yum-utils yum -y install yum-utils* rpm -ql yum-utils 安装好后 ...
- js中如何把字符串转化为对象、数组示例代码
很明显是一个对象,但如何把文本转为对象呢.使用eval();注意一定要加括号,否则会转换失败 把文本转化为对象 var test='{ colkey: "col", colsinf ...
- Java知多少(9) import及Java类的搜索路径
如果你希望使用Java包中的类,就必须先使用import语句导入. import语句与C语言中的 #include 有些类似,语法为: import package1[.package2…].c ...
- 教程:SpagoBI开源商业智能之XML Template 图表模板
SpagoBI offers a variety of widgets' examples realized with the Highcharts library, that can be divi ...
- Ubuntu下安装hbase
1.在清华镜像站点下载hbase的安装文件,选择的是stable的版本,版本号是hbase-1.2.5/ 2.解压放在/usr/local的目录下 3.修改权限 sudo chown -R hduse ...
- Turning off “Language Service Disabled” error message in VS2017
We are getting the following "Error" message in our MVC web application in Visual studio 2 ...
- iOS - UIAlertController三种显示提示框代码
UIAlertView在IOS 8以上版本已经过时了,官方推荐我们使用UIAlertController代替UIAlertView.UIActionSheet 1、UIAlertController显 ...
- Win 10 计算机管理失效(Windows找不到文件“C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\Computer Management.lnk)
Windows找不到文件“C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\Computer Mana ...