Skip to content

Commit

Permalink
docs(client): change code examples to use trades dataset (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
javier authored Dec 9, 2024
1 parent 9c27421 commit 2eca1ef
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 111 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package main

import (
"context"
"fmt"
"log"
"time"

Expand All @@ -43,19 +42,27 @@ func main() {
}
// Make sure to close the sender on exit to release resources.
defer sender.Close(ctx)

// Send a few ILP messages.
err = sender.
Table("trades").
Symbol("symbol", "ETH-USD").
Symbol("side", "sell").
Float64Column("price", 2615.54).
Float64Column("amount", 0.00044).
AtNow(ctx) // timestamp will be set at the server side

tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
if err != nil {
log.Fatal(err)
}

// You can pass a timestamp, rather than using the AtNow call
err = sender.
Table("trades_go").
Symbol("pair", "USDGBP").
Symbol("type", "buy").
Float64Column("traded_price", 0.83).
Float64Column("limit_price", 0.84).
Int64Column("qty", 100).
Table("trades").
Symbol("symbol", "BTC-USD").
Symbol("side", "sell").
Float64Column("price", 39269.98).
Float64Column("amount", 0.001).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -85,7 +92,7 @@ func main() {
}
```

To connect via TCP, set the configuration string to:
HTTP is the recommended transport to use. To connect via TCP, set the configuration string to:
```go
// ...
sender, err := qdb.LineSenderFromConf(ctx, "tcp::addr=localhost:9009;")
Expand Down
22 changes: 10 additions & 12 deletions examples/from-conf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ func main() {
log.Fatal(err)
}
err = sender.
Table("trades_go").
Symbol("pair", "USDGBP").
Symbol("type", "buy").
Float64Column("traded_price", 0.83).
Float64Column("limit_price", 0.84).
Int64Column("qty", 100).
Table("trades").
Symbol("symbol", "ETH-USD").
Symbol("side", "sell").
Float64Column("price", 2615.54).
Float64Column("amount", 0.00044).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand All @@ -44,12 +43,11 @@ func main() {
log.Fatal(err)
}
err = sender.
Table("trades_go").
Symbol("pair", "GBPJPY").
Symbol("type", "sell").
Float64Column("traded_price", 135.97).
Float64Column("limit_price", 0.84).
Int64Column("qty", 400).
Table("trades").
Symbol("symbol", "BTC-USD").
Symbol("side", "sell").
Float64Column("price", 39269.98).
Float64Column("amount", 0.001).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand Down
22 changes: 10 additions & 12 deletions examples/http/auth-and-tls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ func main() {
log.Fatal(err)
}
err = sender.
Table("trades_go").
Symbol("pair", "USDGBP").
Symbol("type", "buy").
Float64Column("traded_price", 0.83).
Float64Column("limit_price", 0.84).
Int64Column("qty", 100).
Table("trades").
Symbol("symbol", "ETH-USD").
Symbol("side", "sell").
Float64Column("price", 2615.54).
Float64Column("amount", 0.00044).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand All @@ -52,12 +51,11 @@ func main() {
log.Fatal(err)
}
err = sender.
Table("trades_go").
Symbol("pair", "GBPJPY").
Symbol("type", "sell").
Float64Column("traded_price", 135.97).
Float64Column("limit_price", 0.84).
Int64Column("qty", 400).
Table("trades").
Symbol("symbol", "BTC-USD").
Symbol("side", "sell").
Float64Column("price", 39269.98).
Float64Column("amount", 0.001).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand Down
29 changes: 14 additions & 15 deletions examples/http/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"context"
qdb "github.com/questdb/go-questdb-client/v3"
"log"
"time"

qdb "github.com/questdb/go-questdb-client/v3"
)

func main() {
Expand All @@ -14,8 +15,8 @@ func main() {
qdb.WithHttp(),
qdb.WithAddress("localhost:9000"),
qdb.WithBasicAuth(
"testUser1", // username
"testPassword1", // password
"admin", // username
"quest", // password
),
)
if err != nil {
Expand All @@ -35,12 +36,11 @@ func main() {
log.Fatal(err)
}
err = sender.
Table("trades_go").
Symbol("pair", "USDGBP").
Symbol("type", "buy").
Float64Column("traded_price", 0.83).
Float64Column("limit_price", 0.84).
Int64Column("qty", 100).
Table("trades").
Symbol("symbol", "ETH-USD").
Symbol("side", "sell").
Float64Column("price", 2615.54).
Float64Column("amount", 0.00044).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand All @@ -51,12 +51,11 @@ func main() {
log.Fatal(err)
}
err = sender.
Table("trades_go").
Symbol("pair", "GBPJPY").
Symbol("type", "sell").
Float64Column("traded_price", 135.97).
Float64Column("limit_price", 0.84).
Int64Column("qty", 400).
Table("trades").
Symbol("symbol", "BTC-USD").
Symbol("side", "sell").
Float64Column("price", 39269.98).
Float64Column("amount", 0.001).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand Down
22 changes: 10 additions & 12 deletions examples/http/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ func main() {
log.Fatal(err)
}
err = sender.
Table("trades_go").
Symbol("pair", "USDGBP").
Symbol("type", "buy").
Float64Column("traded_price", 0.83).
Float64Column("limit_price", 0.84).
Int64Column("qty", 100).
Table("trades").
Symbol("symbol", "ETH-USD").
Symbol("side", "sell").
Float64Column("price", 2615.54).
Float64Column("amount", 0.00044).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand All @@ -45,12 +44,11 @@ func main() {
log.Fatal(err)
}
err = sender.
Table("trades_go").
Symbol("pair", "GBPJPY").
Symbol("type", "sell").
Float64Column("traded_price", 135.97).
Float64Column("limit_price", 0.84).
Int64Column("qty", 400).
Table("trades").
Symbol("symbol", "BTC-USD").
Symbol("side", "sell").
Float64Column("price", 39269.98).
Float64Column("amount", 0.001).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
Expand Down
32 changes: 15 additions & 17 deletions examples/tcp/auth-and-tls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
sender, err := qdb.NewLineSender(
ctx,
qdb.WithTcp(),
qdb.WithAddress("localhost:9009"),
qdb.WithAuth(
"testUser1", // token name here
"admin", // token name here
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48", // token here
),
qdb.WithTls(),
Expand All @@ -29,32 +27,32 @@ func main() {
defer sender.Close(ctx)

// Send a few ILP messages.
bday, err := time.Parse(dateOnly, "1856-07-10")
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
if err != nil {
log.Fatal(err)
}
err = sender.
Table("inventors_go").
Symbol("born", "Austrian Empire").
TimestampColumn("birthdate", bday). // Epoch in micros.
Int64Column("id", 0).
StringColumn("name", "Nicola Tesla").
At(ctx, time.Now()) // Epoch in nanos.
Table("trades").
Symbol("symbol", "ETH-USD").
Symbol("side", "sell").
Float64Column("price", 2615.54).
Float64Column("amount", 0.00044).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
}

bday, err = time.Parse(dateOnly, "1847-02-11")
tradedTs, err = time.Parse(time.RFC3339, "2022-08-06T15:04:06.987654Z")
if err != nil {
log.Fatal(err)
}
err = sender.
Table("inventors_go").
Symbol("born", "USA").
TimestampColumn("birthdate", bday).
Int64Column("id", 1).
StringColumn("name", "Thomas Alva Edison").
AtNow(ctx)
Table("trades").
Symbol("symbol", "BTC-USD").
Symbol("side", "sell").
Float64Column("price", 39269.98).
Float64Column("amount", 0.001).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
}
Expand Down
32 changes: 15 additions & 17 deletions examples/tcp/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import (
qdb "github.com/questdb/go-questdb-client/v3"
)

const dateOnly = "2006-01-02"

func main() {
ctx := context.TODO()
sender, err := qdb.NewLineSender(
ctx,
qdb.WithTcp(),
qdb.WithAddress("localhost:9009"),
qdb.WithAuth(
"testUser1", // token name here
"admin", // token name here
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48", // token here
),
)
Expand All @@ -28,32 +26,32 @@ func main() {
defer sender.Close(ctx)

// Send a few ILP messages.
bday, err := time.Parse(dateOnly, "1856-07-10")
tradedTs, err := time.Parse(time.RFC3339, "2022-08-06T15:04:05.123456Z")
if err != nil {
log.Fatal(err)
}
err = sender.
Table("inventors_go").
Symbol("born", "Austrian Empire").
TimestampColumn("birthdate", bday). // Epoch in micros.
Int64Column("id", 0).
StringColumn("name", "Nicola Tesla").
At(ctx, time.Now()) // Epoch in nanos.
Table("trades").
Symbol("symbol", "ETH-USD").
Symbol("side", "sell").
Float64Column("price", 2615.54).
Float64Column("amount", 0.00044).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
}

bday, err = time.Parse(dateOnly, "1847-02-11")
tradedTs, err = time.Parse(time.RFC3339, "2022-08-06T15:04:06.987654Z")
if err != nil {
log.Fatal(err)
}
err = sender.
Table("inventors_go").
Symbol("born", "USA").
TimestampColumn("birthdate", bday).
Int64Column("id", 1).
StringColumn("name", "Thomas Alva Edison").
AtNow(ctx)
Table("trades").
Symbol("symbol", "BTC-USD").
Symbol("side", "sell").
Float64Column("price", 39269.98).
Float64Column("amount", 0.001).
At(ctx, tradedTs)
if err != nil {
log.Fatal(err)
}
Expand Down
Loading

0 comments on commit 2eca1ef

Please sign in to comment.