-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
70 lines (58 loc) · 1.35 KB
/
main.go
File metadata and controls
70 lines (58 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"log"
"net/url"
"time"
"github.com/gorilla/websocket"
)
// Results レスポンス用構造体
/*
Asks 売り板情報
Lastprice 現在の終値
Trades 全ユーザの取引履歴
Bids 買い板情報
Currencypair 通貨ペア
Timestamp タイムスタンプ
*/
type Results struct {
Asks []interface{} `json:"asks"`
Lastprice Lastprice `json:"last_price"`
Trades []interface{} `json:"trades"`
Bids []interface{} `json:"bids"`
Currencypair string `json:"currency_pair"`
Timestamp string `json:"timestamp"`
}
// Lastprice Lastpriceレスポンス用構造体
/*
Action ask(売り) or bid(買い)
Price 取引価格
*/
type Lastprice struct {
Action string `json:"action"`
Price float64 `json:"price"`
}
func main() {
// 取得する通過ペア
currencypairs := "btc_jpy"
u := &url.URL{
Scheme: "wss",
Host: "ws.zaif.jp",
Path: "stream",
RawQuery: "currency_pair=" + currencypairs,
}
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
defer c.Close()
for {
result := new(Results)
if err := c.ReadJSON(&result); err != nil {
log.Fatal(err)
}
// 必要な結果をレスポンスを指定する
fmt.Println(result.Lastprice)
time.Sleep(5 * time.Second)
}
}