自动读取虚拟币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 ...
随机推荐
- FDDI即光纤分布式数据接口
光纤分布式数据接口它是于80年代中期发展起来一项局域网技术,它提供的高速数据通信能力要高于当时的以太网(10Mbps)和令牌网(4或16Mbps)的能力.FDDI标准由ANSI X3T9.5标准委员会 ...
- Leaflet API翻译
转自: http://jsrookie.iteye.com/blog/2318972(上) http://jsrookie.iteye.com/blog/2318973(下) L.Map API各种类 ...
- ORA-00001: unique constraint (...) violated并不一定是数据冲突
原文链接:http://blog.163.com/jet_it_life/blog/static/205097083201301410303931/ 收到一位测试人员RAISE的JIRA,说在某张表上 ...
- Mac 安装 Jenkins
Mac 安装 Jenkins 有两种方法 方法一: 从官方下载最新版本:http://mirrors.jenkins-ci.org/osx/latest 点击安装. 方法二(推荐): 使用 homeb ...
- linux 设置中文版man手册
作为CentOS 新手,看懂英文man固然重要,不过配置好中文man也可以让自己更快速地学习!1. 下载中文man包源码的网址:https://src.fedoraproject.org/repo/p ...
- /usr/bin/ld: cannot find -lncurses是咋回事?
你的系統是32位的還是64位的? 如果是32位的就用:sudo apt-get install libncurses5-dev 如果是64位的,就用:sudo apt-get install lib3 ...
- [原]openstack-kilo--issue(十三)Unauthorized: The request you have made requires authentication. (HTTP 401) (Request
在运行nova-list 的时候发现报错401:如下面 ========>>>>>>>>> 正常显示 [root@controller ~]# n ...
- Maven传递依赖的坑:父pom中dependencyManagement版本优先级高于传递依赖版本
一.由来 之前同事问了个问题,就是当前工程为spring boot项目,假设版本号为2.0.3 这个项目中依赖了一个spring boot项目依赖(先别管为啥有这么奇葩的依赖,这个版本是1.5.9). ...
- Orleans学习总结(三)--持久化篇
经过上篇Orleans学习总结(二)--创建工程的介绍,我们的工程已经跑起来了,下面我们来介绍下持久化相关. 关于持久化的文档地址在这http://dotnet.github.io/orleans/D ...
- day_5.22 py
#!/usr/bin/env/python #-*-coding:utf-8-*- ''' 私有化 __相当于prevate 外部不能直接调用,只能通过set get方法用 property ''' ...