Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
philsong committed May 25, 2015
1 parent 106f8f4 commit 1c309b2
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 51 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ Weibo:http://weibo.com/bocaicfa

Update:

2013/4/23:EMA、MACD等各种指标和其他策略,在市场深度不够时,已然失效。。。业界其他程序员即使基于robot写了策略,也极少开源,原因就是一旦公开策略,使用人数变多,该策略就失效。即日起本人也不再公开发布新的策略,改变开发方向为专注于该开源框架的完善,然后提供回测和策略接口甚至提供策略交易市场,让用户方便自己实现自己的策略并可回测,及交流。有任何建议及合作都可互相探讨。
2014/4/23: EMA、MACD等各种指标和其他策略,在市场深度不够时,已然失效。。。业界其他程序员即使基于robot写了策略,也极少开源,原因就是一旦公开策略,使用人数变多,该策略就失效。即日起本人也不再公开发布新的策略,改变开发方向为专注于该开源框架的完善,然后提供回测和策略接口甚至提供策略交易市场,让用户方便自己实现自己的策略并可回测,及交流。有任何建议及合作都可互相探讨。

2015/5/25: 项目已内部转化为公司买卖币及搬砖模块, 搁置。


## 使用指南:
Expand Down
2 changes: 1 addition & 1 deletion conf/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

"hb_base_url": "https://www.huobi.com/",
"hb_api_url": "https://api.huobi.com/api.php",
"hb_kline_url": "https://market.huobi.com/market/huobi.php?a=kline&period=%03d&r=%f",
"hb_kline_url": "http://api.huobi.com/staticmarket/btc_kline_%03d_json.js",
"hb_trade_detail": "http://market.huobi.com/staticmarket/detail.html?jsoncallback=jQuery%s_%d&_=%d",

"ok_base_url":"https://www.okcoin.cn/",
Expand Down
27 changes: 26 additions & 1 deletion conf/option.json
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
{"MACDbuyThreshold":"0.005","MACDsellThreshold":"-0.005","basePrice":"3827","buyThreshold":"0.0003","datacenter":"huobi","disable_backtesting":"0","discipleMode":"0","discipleValue":"0.0","enable_email":"0","enable_trading":"0","fluctuation":"1","longEMA":"21","sellThreshold":"-0.0002","shortEMA":"10","signalPeriod":"9","slippage":"0.1","stoploss":"1","strategy":"EMA","symbol":"btc_cny","tick_interval":"15","to_email":"xxxxx@qq.com","totalHour":"20","tradeAmount":"0.01","tradecenter":"huobi"}
{
"MACDbuyThreshold": "0.005",
"MACDsellThreshold": "-0.005",
"basePrice": "3827",
"buyThreshold": "0.0003",
"datacenter": "huobi",
"disable_backtesting": "0",
"discipleMode": "0",
"discipleValue": "0.0",
"enable_email": "0",
"enable_trading": "0",
"fluctuation": "1",
"longEMA": "21",
"sellThreshold": "-0.0002",
"shortEMA": "10",
"signalPeriod": "9",
"slippage": "0.1",
"stoploss": "1",
"strategy": "EMA",
"symbol": "btc_cny",
"tick_interval": "15",
"to_email": "xxxxx@qq.com",
"totalHour": "20",
"tradeAmount": "0.01",
"tradecenter": "huobi"
}
35 changes: 0 additions & 35 deletions conf/secret.sample

This file was deleted.

6 changes: 5 additions & 1 deletion conf/simulate.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{"BTC":"0","CNY":"24833.741095158035","LTC":"0"}
{
"BTC": "0",
"CNY": "24833.741095158035",
"LTC": "0"
}
13 changes: 12 additions & 1 deletion conf/trade.json
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
{"buyamount":"0.1","buyinterval":"11","buyprice":"100","buytimes":"11","maxbuyamountratio":"11","maxsellamountratio":"10","sellamount":"0.1","sellinterval":"10","sellprice":"75","selltimes":"10"}
{
"buyamount": "0.1",
"buyinterval": "11",
"buyprice": "100",
"buytimes": "11",
"maxbuyamountratio": "11",
"maxsellamountratio": "10",
"sellamount": "0.1",
"sellinterval": "10",
"sellprice": "75",
"selltimes": "10"
}
6 changes: 6 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// btcrobot project doc.go

/*
btcrobot document
*/
package main
14 changes: 6 additions & 8 deletions src/btcrobot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
package main

import (
. "config"
"config"
"fmt"
"io/ioutil"
"math/rand"
"monitor"
"os"
"path/filepath"
"runtime"
// "runtime"
"strconv"
"time"
"webui"
Expand All @@ -49,29 +50,26 @@ func main() {
}

func printBanner() {
version := "V0.43"
version := "V0.5"
fmt.Println("[ ---------------------------------------------------------->>> ")
fmt.Println(" BTC/LTC自动化算法交易引擎", version)
fmt.Println(" btcrobot is a Bitcoin, Litecoin and Altcoin trading bot written in golang")
fmt.Println(" it features multiple trading methods using technical analysis.")
fmt.Println(" ")
fmt.Println(" Disclaimer: USE AT YOUR OWN RISK! ")
fmt.Println(" 声明: 软件可能存在缺陷及逻辑漏洞等,请仔细测试,认证评估,风险自负!")
fmt.Println(" ")
fmt.Println(" *@请在浏览器中打开 http://127.0.0.1:9090 配置相关参数")
fmt.Println(" *@警告:API key和密码存放在conf/secret.json文件内,共享给他人前请务必删除,注意账号安全!!")
fmt.Println(" <<<----------------------------------------------------------] ")
}

// 保存PID
func SavePid() {
pidFile := Config["pid"]
pidFile := config.Config["pid"]
if pidFile == "" {
pidFile = "pid/btcrobot.pid"
}

if !filepath.IsAbs(Config["pid"]) {
pidFile = ROOT + "/" + pidFile
if !filepath.IsAbs(config.Config["pid"]) {
pidFile = config.ROOT + "/" + pidFile
}

// 保存pid
Expand Down
3 changes: 1 addition & 2 deletions src/huobi/marketapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"io"
"io/ioutil"
"logger"
"math/rand"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -58,7 +57,7 @@ func (w *Huobi) AnalyzeKLinePeroid(symbol string, peroid int) (ret bool, records
return
}

req, err := http.NewRequest("GET", fmt.Sprintf(Config["hb_kline_url"], peroid, rand.Float64()), nil)
req, err := http.NewRequest("GET", fmt.Sprintf(Config["hb_kline_url"], peroid), nil)
if err != nil {
logger.Fatal(err)
return
Expand Down
3 changes: 3 additions & 0 deletions src/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
)

func marketAPI() (marketAPI MarketAPI) {
logger.Infof(Option["datacenter"])
if Option["datacenter"] == "huobi" {
marketAPI = huobi.NewHuobi()
} else if Option["datacenter"] == "okcoin" {
Expand All @@ -44,6 +45,7 @@ func marketAPI() (marketAPI MarketAPI) {
marketAPI = Bittrex.Manager()
} else {
logger.Fatalln("Please config the market center...")
panic(-1)
}
return
}
Expand All @@ -63,6 +65,7 @@ func tradeAPI() (tradeAPI TradeAPI) {
tradeAPI = simulate.NewSimulate()
} else {
logger.Fatalln("Please config the exchange center...")
panic(0)
}
return
}
Expand Down
8 changes: 8 additions & 0 deletions src/strategy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,21 @@ func Tick(tradeAPI TradeAPI, records []Record) bool {
return false
}

logger.Infoln("strategyName", strategyName)

if strategyName != "OPENORDER" {
length = len(records)
if length == 0 {
logger.Errorln("warning:detect exception data", len(records))
return false
}

fmt.Println(length, records)
if length < 2 {
logger.Errorln("warning:detect exception data", len(records))
return false
}

if Option["tick_interval"] != "1" {
// check exception data in trade center
if CheckException(records[length-2], records[length-1]) == false {
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/getpkg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi
OLDGOPATH="$GOPATH"
export GOPATH=`pwd`

go get -u github.com/philsong/martini
go get -u github.com/go-martini/martini
go get -u github.com/codegangsta/martini-contrib/auth
go get -u github.com/philsong/goleveldb/leveldb
go get -u github.com/bitly/go-simplejson
Expand Down

0 comments on commit 1c309b2

Please sign in to comment.