Skip to content

Commit 2eca1ef

Browse files
authored
docs(client): change code examples to use trades dataset (#44)
1 parent 9c27421 commit 2eca1ef

File tree

9 files changed

+105
-111
lines changed

9 files changed

+105
-111
lines changed

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ package main
2727

2828
import (
2929
"context"
30-
"fmt"
3130
"log"
3231
"time"
3332

@@ -43,19 +42,27 @@ func main() {
4342
}
4443
// Make sure to close the sender on exit to release resources.
4544
defer sender.Close(ctx)
46-
4745
// Send a few ILP messages.
46+
err = sender.
47+
Table("trades").
48+
Symbol("symbol", "ETH-USD").
49+
Symbol("side", "sell").
50+
Float64Column("price", 2615.54).
51+
Float64Column("amount", 0.00044).
52+
AtNow(ctx) // timestamp will be set at the server side
53+
4854
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
4955
if err != nil {
5056
log.Fatal(err)
5157
}
58+
59+
// You can pass a timestamp, rather than using the AtNow call
5260
err = sender.
53-
Table("trades_go").
54-
Symbol("pair", "USDGBP").
55-
Symbol("type", "buy").
56-
Float64Column("traded_price", 0.83).
57-
Float64Column("limit_price", 0.84).
58-
Int64Column("qty", 100).
61+
Table("trades").
62+
Symbol("symbol", "BTC-USD").
63+
Symbol("side", "sell").
64+
Float64Column("price", 39269.98).
65+
Float64Column("amount", 0.001).
5966
At(ctx, tradedTs)
6067
if err != nil {
6168
log.Fatal(err)
@@ -85,7 +92,7 @@ func main() {
8592
}
8693
```
8794

88-
To connect via TCP, set the configuration string to:
95+
HTTP is the recommended transport to use. To connect via TCP, set the configuration string to:
8996
```go
9097
// ...
9198
sender, err := qdb.LineSenderFromConf(ctx, "tcp::addr=localhost:9009;")

examples/from-conf/main.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ func main() {
2828
log.Fatal(err)
2929
}
3030
err = sender.
31-
Table("trades_go").
32-
Symbol("pair", "USDGBP").
33-
Symbol("type", "buy").
34-
Float64Column("traded_price", 0.83).
35-
Float64Column("limit_price", 0.84).
36-
Int64Column("qty", 100).
31+
Table("trades").
32+
Symbol("symbol", "ETH-USD").
33+
Symbol("side", "sell").
34+
Float64Column("price", 2615.54).
35+
Float64Column("amount", 0.00044).
3736
At(ctx, tradedTs)
3837
if err != nil {
3938
log.Fatal(err)
@@ -44,12 +43,11 @@ func main() {
4443
log.Fatal(err)
4544
}
4645
err = sender.
47-
Table("trades_go").
48-
Symbol("pair", "GBPJPY").
49-
Symbol("type", "sell").
50-
Float64Column("traded_price", 135.97).
51-
Float64Column("limit_price", 0.84).
52-
Int64Column("qty", 400).
46+
Table("trades").
47+
Symbol("symbol", "BTC-USD").
48+
Symbol("side", "sell").
49+
Float64Column("price", 39269.98).
50+
Float64Column("amount", 0.001).
5351
At(ctx, tradedTs)
5452
if err != nil {
5553
log.Fatal(err)

examples/http/auth-and-tls/main.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ func main() {
3636
log.Fatal(err)
3737
}
3838
err = sender.
39-
Table("trades_go").
40-
Symbol("pair", "USDGBP").
41-
Symbol("type", "buy").
42-
Float64Column("traded_price", 0.83).
43-
Float64Column("limit_price", 0.84).
44-
Int64Column("qty", 100).
39+
Table("trades").
40+
Symbol("symbol", "ETH-USD").
41+
Symbol("side", "sell").
42+
Float64Column("price", 2615.54).
43+
Float64Column("amount", 0.00044).
4544
At(ctx, tradedTs)
4645
if err != nil {
4746
log.Fatal(err)
@@ -52,12 +51,11 @@ func main() {
5251
log.Fatal(err)
5352
}
5453
err = sender.
55-
Table("trades_go").
56-
Symbol("pair", "GBPJPY").
57-
Symbol("type", "sell").
58-
Float64Column("traded_price", 135.97).
59-
Float64Column("limit_price", 0.84).
60-
Int64Column("qty", 400).
54+
Table("trades").
55+
Symbol("symbol", "BTC-USD").
56+
Symbol("side", "sell").
57+
Float64Column("price", 39269.98).
58+
Float64Column("amount", 0.001).
6159
At(ctx, tradedTs)
6260
if err != nil {
6361
log.Fatal(err)

examples/http/auth/main.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package main
22

33
import (
44
"context"
5-
qdb "github.com/questdb/go-questdb-client/v3"
65
"log"
76
"time"
7+
8+
qdb "github.com/questdb/go-questdb-client/v3"
89
)
910

1011
func main() {
@@ -14,8 +15,8 @@ func main() {
1415
qdb.WithHttp(),
1516
qdb.WithAddress("localhost:9000"),
1617
qdb.WithBasicAuth(
17-
"testUser1", // username
18-
"testPassword1", // password
18+
"admin", // username
19+
"quest", // password
1920
),
2021
)
2122
if err != nil {
@@ -35,12 +36,11 @@ func main() {
3536
log.Fatal(err)
3637
}
3738
err = sender.
38-
Table("trades_go").
39-
Symbol("pair", "USDGBP").
40-
Symbol("type", "buy").
41-
Float64Column("traded_price", 0.83).
42-
Float64Column("limit_price", 0.84).
43-
Int64Column("qty", 100).
39+
Table("trades").
40+
Symbol("symbol", "ETH-USD").
41+
Symbol("side", "sell").
42+
Float64Column("price", 2615.54).
43+
Float64Column("amount", 0.00044).
4444
At(ctx, tradedTs)
4545
if err != nil {
4646
log.Fatal(err)
@@ -51,12 +51,11 @@ func main() {
5151
log.Fatal(err)
5252
}
5353
err = sender.
54-
Table("trades_go").
55-
Symbol("pair", "GBPJPY").
56-
Symbol("type", "sell").
57-
Float64Column("traded_price", 135.97).
58-
Float64Column("limit_price", 0.84).
59-
Int64Column("qty", 400).
54+
Table("trades").
55+
Symbol("symbol", "BTC-USD").
56+
Symbol("side", "sell").
57+
Float64Column("price", 39269.98).
58+
Float64Column("amount", 0.001).
6059
At(ctx, tradedTs)
6160
if err != nil {
6261
log.Fatal(err)

examples/http/basic/main.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ func main() {
2929
log.Fatal(err)
3030
}
3131
err = sender.
32-
Table("trades_go").
33-
Symbol("pair", "USDGBP").
34-
Symbol("type", "buy").
35-
Float64Column("traded_price", 0.83).
36-
Float64Column("limit_price", 0.84).
37-
Int64Column("qty", 100).
32+
Table("trades").
33+
Symbol("symbol", "ETH-USD").
34+
Symbol("side", "sell").
35+
Float64Column("price", 2615.54).
36+
Float64Column("amount", 0.00044).
3837
At(ctx, tradedTs)
3938
if err != nil {
4039
log.Fatal(err)
@@ -45,12 +44,11 @@ func main() {
4544
log.Fatal(err)
4645
}
4746
err = sender.
48-
Table("trades_go").
49-
Symbol("pair", "GBPJPY").
50-
Symbol("type", "sell").
51-
Float64Column("traded_price", 135.97).
52-
Float64Column("limit_price", 0.84).
53-
Int64Column("qty", 400).
47+
Table("trades").
48+
Symbol("symbol", "BTC-USD").
49+
Symbol("side", "sell").
50+
Float64Column("price", 39269.98).
51+
Float64Column("amount", 0.001).
5452
At(ctx, tradedTs)
5553
if err != nil {
5654
log.Fatal(err)

examples/tcp/auth-and-tls/main.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ import (
88
qdb "github.com/questdb/go-questdb-client/v3"
99
)
1010

11-
const dateOnly = "2006-01-02"
12-
1311
func main() {
1412
ctx := context.TODO()
1513
sender, err := qdb.NewLineSender(
1614
ctx,
1715
qdb.WithTcp(),
1816
qdb.WithAddress("localhost:9009"),
1917
qdb.WithAuth(
20-
"testUser1", // token name here
18+
"admin", // token name here
2119
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48", // token here
2220
),
2321
qdb.WithTls(),
@@ -29,32 +27,32 @@ func main() {
2927
defer sender.Close(ctx)
3028

3129
// Send a few ILP messages.
32-
bday, err := time.Parse(dateOnly, "1856-07-10")
30+
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
3331
if err != nil {
3432
log.Fatal(err)
3533
}
3634
err = sender.
37-
Table("inventors_go").
38-
Symbol("born", "Austrian Empire").
39-
TimestampColumn("birthdate", bday). // Epoch in micros.
40-
Int64Column("id", 0).
41-
StringColumn("name", "Nicola Tesla").
42-
At(ctx, time.Now()) // Epoch in nanos.
35+
Table("trades").
36+
Symbol("symbol", "ETH-USD").
37+
Symbol("side", "sell").
38+
Float64Column("price", 2615.54).
39+
Float64Column("amount", 0.00044).
40+
At(ctx, tradedTs)
4341
if err != nil {
4442
log.Fatal(err)
4543
}
4644

47-
bday, err = time.Parse(dateOnly, "1847-02-11")
45+
tradedTs, err = time.Parse(time.RFC3339, "2022-08-06T15:04:06.987654Z")
4846
if err != nil {
4947
log.Fatal(err)
5048
}
5149
err = sender.
52-
Table("inventors_go").
53-
Symbol("born", "USA").
54-
TimestampColumn("birthdate", bday).
55-
Int64Column("id", 1).
56-
StringColumn("name", "Thomas Alva Edison").
57-
AtNow(ctx)
50+
Table("trades").
51+
Symbol("symbol", "BTC-USD").
52+
Symbol("side", "sell").
53+
Float64Column("price", 39269.98).
54+
Float64Column("amount", 0.001).
55+
At(ctx, tradedTs)
5856
if err != nil {
5957
log.Fatal(err)
6058
}

examples/tcp/auth/main.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ import (
88
qdb "github.com/questdb/go-questdb-client/v3"
99
)
1010

11-
const dateOnly = "2006-01-02"
12-
1311
func main() {
1412
ctx := context.TODO()
1513
sender, err := qdb.NewLineSender(
1614
ctx,
1715
qdb.WithTcp(),
1816
qdb.WithAddress("localhost:9009"),
1917
qdb.WithAuth(
20-
"testUser1", // token name here
18+
"admin", // token name here
2119
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48", // token here
2220
),
2321
)
@@ -28,32 +26,32 @@ func main() {
2826
defer sender.Close(ctx)
2927

3028
// Send a few ILP messages.
31-
bday, err := time.Parse(dateOnly, "1856-07-10")
29+
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
3230
if err != nil {
3331
log.Fatal(err)
3432
}
3533
err = sender.
36-
Table("inventors_go").
37-
Symbol("born", "Austrian Empire").
38-
TimestampColumn("birthdate", bday). // Epoch in micros.
39-
Int64Column("id", 0).
40-
StringColumn("name", "Nicola Tesla").
41-
At(ctx, time.Now()) // Epoch in nanos.
34+
Table("trades").
35+
Symbol("symbol", "ETH-USD").
36+
Symbol("side", "sell").
37+
Float64Column("price", 2615.54).
38+
Float64Column("amount", 0.00044).
39+
At(ctx, tradedTs)
4240
if err != nil {
4341
log.Fatal(err)
4442
}
4543

46-
bday, err = time.Parse(dateOnly, "1847-02-11")
44+
tradedTs, err = time.Parse(time.RFC3339, "2022-08-06T15:04:06.987654Z")
4745
if err != nil {
4846
log.Fatal(err)
4947
}
5048
err = sender.
51-
Table("inventors_go").
52-
Symbol("born", "USA").
53-
TimestampColumn("birthdate", bday).
54-
Int64Column("id", 1).
55-
StringColumn("name", "Thomas Alva Edison").
56-
AtNow(ctx)
49+
Table("trades").
50+
Symbol("symbol", "BTC-USD").
51+
Symbol("side", "sell").
52+
Float64Column("price", 39269.98).
53+
Float64Column("amount", 0.001).
54+
At(ctx, tradedTs)
5755
if err != nil {
5856
log.Fatal(err)
5957
}

0 commit comments

Comments
 (0)