Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "context"
- "flag"
- "fmt"
- "log"
- "github.com/etherdev12/go-defi/bclient"
- "github.com/etherdev12/go-defi/config"
- )
- var (
- THRESHOLD = flag.Float64("threshold", 0, "Threshold of ETH Price")
- BALANCE = flag.Float64("balance", 0, "Balance of ETH to Swap")
- )
- func init() {
- flag.Parse()
- }
- func main() {
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
- cfg := &config.Config{
- Blockchain: config.Blockchain{
- ProviderType: "direct",
- RPC: "https://eth.llamarpc.com",
- },
- }
- client, err := cfg.EthClient(ctx)
- if err != nil {
- log.Fatal(err)
- }
- bc, err := bclient.NewClient(ctx, client)
- if err != nil {
- log.Fatal(err)
- }
- // Get price on uniswap
- price, err := bc.EthDaiPrice()
- if err != nil {
- log.Fatal(err)
- }
- fmt.Println(price)
- priceF, _ := price.Float64()
- if priceF > *THRESHOLD && *BALANCE > 0 {
- // Swap ETH into DAI
- fmt.Println("Try to swap", *BALANCE, "ETH into DAI...")
- //
- // Add swap code here
- //
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement