123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- // Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved.
- package market
- // 本文件测试martket相关函数
- import (
- // "compress/gzip"
- "io"
- "log"
- // "market/lmax"
- "os"
- "testing"
- )
- func TestReadCtpCandleFile(t *testing.T) {
- fname := "candle2.M1"
- r, err := os.Open(fname)
- if err != nil {
- t.Fatal(err)
- }
- defer r.Close()
- for {
- c, err := ReadCandleBinary(r)
- if err != nil {
- if err != io.EOF {
- t.Fatal(err)
- }
- break
- }
- log.Println(c, getTime(c.Timestamp))
- // candles = append(candles, *c)
- }
- }
- func TestReadCandleFile(t *testing.T) {
- // use gzip compress
- fname := "candle.M1"
- // r, err := os.Open(fname)
- // if err != nil {
- // t.Fatal(err)
- // }
- // defer r.Close()
- // fname = "testdata/candle.M1.zip"
- // w, err := os.Create(fname)
- // if err != nil {
- // t.Fatal(err)
- // }
- // defer w.Close()
- // zw := gzip.NewWriter(w)
- // _, err = io.Copy(zw, r)
- // if err != nil {
- // t.Fatal(err)
- // }
- // // zw.Flush()
- // zw.Close()
- testReadCandleFile(fname, t)
- }
- func testReadCandleFile(fname string, t *testing.T) {
- candles, err := readCandleFile(fname)
- log.Println("@@@@@@@:", len(candles))
- if err != nil {
- t.Fatal(err)
- }
- log.Println("@@@@@@:", len(candles))
- for _, c := range candles {
- log.Println(getTime(c.Timestamp), c)
- }
- }
- func TestToH1(t *testing.T) {
- fnames := []string{
- // "testdata/2014-07-01-21-00-00-000-4001-ask-minute-aggregation.M1",
- "testdata/2014-07-02-21-00-00-000-4001-ask-minute-aggregation.M1",
- // "testdata/2014-07-03-21-00-00-000-4001-ask-minute-aggregation.M1",
- }
- h1file := "testdata/candle.H1"
- for _, fname := range fnames {
- candles, err := readCandleFile(fname)
- if err != nil {
- t.Fatal(err)
- }
- r := &CandleBuf{candles: candles}
- buf, err := convPeriod(r, H1)
- if err != nil {
- log.Fatal(err)
- }
- candles, err = readCandleFile(h1file)
- if err != nil {
- log.Println(err)
- }
- candles = append(candles, buf...)
- w, err := os.Create(h1file)
- if err != nil {
- t.Fatal(err)
- }
- err = zipCBuf(w, candles)
- if err != nil {
- t.Fatal(err)
- }
- w.Close()
- }
- candles, err := readCandleFile(h1file)
- if err != nil {
- t.Fatal(err)
- }
- for _, c := range candles {
- log.Println(getTime(c.Timestamp))
- }
- }
|