123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- // Copyright 2013-2014 Fuzamei tech Ltd. All rights reserved.
- package client
- // 本文件测试client的封装接口
- import (
- "log"
- "testing"
- "time"
- )
- var client *Client
- func newClient(t *testing.T) {
- newServer(t)
- if client == nil {
- c, err := NewClient("localhost:19526", "localhost:19527", "localhost:8080", "./testdata")
- if err != nil {
- t.Fatal(err)
- }
- client = c
- }
- }
- func TestClientGetHistory(t *testing.T) {
- newClient(t)
- time.Sleep(time.Minute * 2) // 让server运行一段时间, 拥有测试的数据
- insIds := []string{"easyforex_EURUSD", "oanda_EURUSD"} // lmax, easyforex and oanda EURUSD
- for _, insId := range insIds {
- ticks, err := client.GetTickHistory(insId, 5, TimeNow)
- if err != nil {
- t.Fatal(err)
- }
- if len(ticks) != 5 {
- t.Error("len(ticks) != 5", len(ticks))
- }
- }
- for _, insId := range insIds {
- candles, err := client.GetCandleHistory(insId, M1, 2, TimeNow)
- if err != nil {
- t.Fatal(err)
- }
- if len(candles) != 2 {
- t.Error("len(candles) != 2", len(candles))
- }
- }
- }
- func TestClientSubMarket(t *testing.T) {
- newClient(t)
- insIds := []string{"easyforex_EURUSD", "oanda_EURUSD"} // lmax, easyforex and oanda EURUSD
- for _, insId := range insIds {
- insId := insId
- client.SubMarket(insId)
- client.GetIns(insId).OnMarket().Attach(func(v interface{}) error {
- m, ok := v.(*Market)
- if !ok {
- t.Fatal("v.(*Market) is NOT ok")
- }
- if m.InsId != insId {
- t.Fatal("m.InsId != insId", m.InsId, insId)
- }
- log.Println("@@@:Market:", insId, m)
- return nil
- })
- }
- time.Sleep(time.Minute)
- }
|