This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_rpc_test.go
89 lines (75 loc) · 1.87 KB
/
example_rpc_test.go
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package dydx_test
import (
"context"
"fmt"
"time"
"github.com/davecgh/go-spew/spew"
"github.com/fardream/go-dydx"
)
var _ = "keep"
// An example with subscriptions
func Example() {
const ethAddress = "<eth address>"
client, err := dydx.NewClient(
dydx.NewStarkKey(
"<stark pubkey>",
"<stark pubkey y coordinate>",
"<stark private key>"),
dydx.NewApiKey(
"<api key>",
"<api passphrase>",
"<api secret>"),
ethAddress,
false)
if err != nil {
panic(err)
}
orderbook := make(chan *dydx.OrderbookChannelResponse)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
go func() {
if err := client.SubscribeOrderbook(ctx, "BTC-USD", orderbook); err != nil {
fmt.Printf("sub order error: %#v\n", err)
}
close(orderbook)
}()
for v := range orderbook {
spew.Printf("%#v\n", v)
}
ctx, cancel = context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
trades := make(chan *dydx.TradesChannelResponse)
go func() {
if err := client.SubscribeTrades(ctx, "BTC-USD", trades); err != nil {
fmt.Printf("sub trades error: %v\n", err)
}
close(trades)
}()
for v := range trades {
spew.Printf("%v\n", v)
}
markets := make(chan *dydx.MarketsChannelResponse)
ctx, cancel = context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
go func() {
if err := client.SubscribeMarkets(ctx, markets); err != nil {
fmt.Printf("sub order error: %#v\n", err)
}
close(markets)
}()
for v := range markets {
spew.Printf("%#v\n", v)
}
ctx, cancel = context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
accounts := make(chan *dydx.AccountChannelResponse)
go func() {
if err := client.SubscribeAccount(ctx, 0, accounts); err != nil {
fmt.Printf("sub trades error: %v\n", err)
}
close(accounts)
}()
for v := range accounts {
spew.Printf("%v\n", v)
}
}