123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- // Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved.
- package tick
- // 本文件实现配置文件的管理
- import (
- "encoding/json"
- "io/ioutil"
- "log"
- "os"
- "path/filepath"
- )
- type DsConf struct {
- BrokerId string
- User string
- PassWord string
- Url string
- Url2 string
- SaveDir string
- SaveDir1 string
- Run bool
- Download bool
- CfgFile string
- SymbolsFile string
- Symbols string
- }
- type DBConf struct {
- DBDriver string // mysql, sqlite
- DSN string // dsn = fmt.Sprintf("root:fzm@1001@/%s?charset=%s", dbName, "utf8")
- DBName string // fzmdb
- }
- type ServerConf struct {
- DBConf
- DsMap map[string]*DsConf // 数据源配置
- DataDir string // 数据保存地址
- HttpAddr string // Rpc 监听地址 ":19528"
- }
- func WriteConf(fname string, conf *ServerConf) error {
- b, err := json.MarshalIndent(conf, "", " ")
- if err != nil {
- return err
- }
- ioutil.WriteFile(fname, b, os.ModePerm)
- return nil
- }
- func ReadConf(fname string) (*ServerConf, error) {
- f, err := os.Open(fname)
- if err != nil {
- return nil, err
- }
- defer f.Close()
- dec := json.NewDecoder(f)
- conf := &ServerConf{}
- err = dec.Decode(conf)
- if err != nil {
- return nil, err
- }
- return conf, nil
- }
- var DefaultServerConf = makeDefaultServerConf()
- func makeDefaultServerConf() *ServerConf {
- dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
- if err != nil {
- log.Fatal(err)
- }
- dataDir := filepath.Join(dir, "fzmnew")
- lmaxConf := &DsConf{
- User: "wave3366",
- PassWord: "Tg417395",
- Url: "https://trade.lmaxtrader.com",
- SaveDir: filepath.Join(dataDir, Lmax),
- Run: true,
- Download: true,
- }
- oandaConf := &DsConf{
- SaveDir: filepath.Join(dataDir, Oanda),
- Run: true,
- Download: true,
- }
- easyForexConf := &DsConf{
- SaveDir: filepath.Join(dataDir, EasyForex),
- Run: true,
- Download: true,
- }
- ctpConf := &DsConf{
- BrokerId: "66666",
- User: "1011000",
- PassWord: "317496",
- Url: "tcp://ctp1-front5.citicsf.com:41205",
- Url2: "tcp://ctp1-md5.citicsf.com:41213",
- SaveDir: filepath.Join(dataDir, Ctp),
- Run: true,
- Download: true,
- }
- fixConf := &DsConf{
- User: "20410767",
- PassWord: "491823",
- SaveDir: filepath.Join(dataDir, Fix),
- CfgFile: "fix-mk.cfg",
- SymbolsFile: "fix-symbols.json",
- Run: true,
- Download: true,
- }
- saxoConf := &DsConf{
- User: "",
- PassWord: "",
- SaveDir: filepath.Join(dataDir, Saxo),
- CfgFile: "saxo-mk.cfg",
- SymbolsFile: "saxo-symbols.csv",
- Run: true,
- Download: true,
- }
- dzhConf := &DsConf{
- Url: "115.29.238.128:19526",
- SaveDir: filepath.Join(dataDir, Dzh),
- Run: true,
- Download: true,
- }
- sinaConf := &DsConf{
- SaveDir: filepath.Join(dataDir, Sina),
- Run: true,
- Download: true,
- }
- sinaFutureConf := &DsConf{
- SaveDir: filepath.Join(dataDir, SinaFuture),
- Run: true,
- Download: true,
- }
- m := map[string]*DsConf{
- Lmax: lmaxConf,
- Oanda: oandaConf,
- EasyForex: easyForexConf,
- Ctp: ctpConf,
- Fix: fixConf,
- Dzh: dzhConf,
- Saxo: saxoConf,
- Sina: sinaConf,
- SinaFuture: sinaFutureConf,
- }
- dbConf := DBConf{
- DBDriver: "mysql", // mysql
- DSN: "root:kingweb@tcp(localhost:3306)/tick_server?charset=utf8", // root:fzm@1001@/fzmdb?charset=utf8"
- DBName: "fzmnewdb", //
- }
- return &ServerConf{
- DBConf: dbConf,
- DsMap: m,
- DataDir: dataDir,
- HttpAddr: ":2107",
- }
- }
|