Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
vmpartner committed Apr 11, 2018
1 parent a910c06 commit 15f0fed
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
17 changes: 16 additions & 1 deletion config/config.go
Expand Up @@ -3,13 +3,28 @@ package config
import (
"os"
"encoding/json"
"gitlab.com/vitams/bitmex/tools"
"github.com/vmpartner/bitmex/tools"
)

type Config struct {
Host string
Key string
Secret string
DB struct {
Host string
Login string
Password string
Name string
}
Neural struct {
Iterations int
Predict float64
}
Strategy struct {
Profit float64
StopLose float64
Quantity float32
}
}

type MasterConfig struct {
Expand Down
17 changes: 17 additions & 0 deletions database/database.go
@@ -0,0 +1,17 @@
package database

import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"github.com/vmpartner/bitmex/tools"
)

func Connect(login string, password string, host string, name string, ) *gorm.DB {
dbLink := fmt.Sprintf("%s:%s@tcp(%s)/%s?parseTime=true", login, password, host, name)
db, err := gorm.Open("mysql", dbLink)
tools.CheckErr(err)
db.Exec(`SET NAMES UTF8`)

return db
}
13 changes: 13 additions & 0 deletions database/database_test.go
@@ -0,0 +1,13 @@
package database

import (
"testing"
)

func TestConnectMaster(t *testing.T) {

}

func TestConnectDev(t *testing.T) {

}
25 changes: 25 additions & 0 deletions tools/tools.go
@@ -1,7 +1,32 @@
package tools

import (
"os"
"encoding/gob"
)

func CheckErr(err error) {
if err != nil {
panic(err)
}
}

func WriteGob(filePath string, object interface{}) error {
file, err := os.Create(filePath)
if err == nil {
encoder := gob.NewEncoder(file)
encoder.Encode(object)
}
file.Close()
return err
}

func ReadGob(filePath string, object interface{}) error {
file, err := os.Open(filePath)
if err == nil {
decoder := gob.NewDecoder(file)
err = decoder.Decode(object)
}
file.Close()
return err
}

0 comments on commit 15f0fed

Please sign in to comment.