github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/examples/v2/rest-pulse/main.go (about)

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  	"time"
     7  
     8  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/common"
     9  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/pulse"
    10  	"github.com/bitfinexcom/bitfinex-api-go/v2/rest"
    11  	"github.com/davecgh/go-spew/spew"
    12  )
    13  
    14  // Set BFX_API_KEY and BFX_API_SECRET:
    15  //
    16  // export BFX_API_KEY=<your-api-key>
    17  // export BFX_API_SECRET=<your-api-secret>
    18  //
    19  // you can obtain it from https://www.bitfinex.com/api
    20  
    21  func main() {
    22  	key := os.Getenv("BFX_API_KEY")
    23  	secret := os.Getenv("BFX_API_SECRET")
    24  
    25  	c := rest.
    26  		NewClient().
    27  		Credentials(key, secret)
    28  
    29  	pulseProfile(c)
    30  	publicPulseHistory(c)
    31  	addPulse(c)
    32  	addComment(c)
    33  	pulseHistory(c)
    34  	deletePulse(c)
    35  }
    36  
    37  func pulseProfile(c *rest.Client) {
    38  	nn := rest.Nickname("Bitfinex")
    39  	resp, err := c.Pulse.PublicPulseProfile(nn)
    40  	if err != nil {
    41  		log.Fatalf("PublicPulseProfile: %s", err)
    42  	}
    43  
    44  	spew.Dump(resp)
    45  }
    46  
    47  func publicPulseHistory(c *rest.Client) {
    48  	now := time.Now()
    49  	millis := now.UnixNano() / 1000000
    50  	from := common.Mts(millis)
    51  
    52  	pulseHist, err := c.Pulse.PublicPulseHistory(2, from)
    53  	if err != nil {
    54  		log.Fatalf("PublicPulseHistory: %s", err)
    55  	}
    56  
    57  	spew.Dump(pulseHist)
    58  }
    59  
    60  func addPulse(c *rest.Client) {
    61  	payload := &pulse.Pulse{
    62  		Title:   "GO GO GO GO GO GO TITLE",
    63  		Content: "GO GO GO GO GO GO Content",
    64  	}
    65  
    66  	resp, err := c.Pulse.AddPulse(payload)
    67  	if err != nil {
    68  		log.Fatalf("AddPulse: %s", err)
    69  	}
    70  
    71  	spew.Dump(resp)
    72  }
    73  
    74  func addComment(c *rest.Client) {
    75  	pulse1 := &pulse.Pulse{
    76  		Title:   "TITLE TO BE COMMENTED ON",
    77  		Content: "CONTENT TO BE COMMENTED ON",
    78  	}
    79  
    80  	p1, err := c.Pulse.AddPulse(pulse1)
    81  	if err != nil {
    82  		log.Fatalf("addComment:AddPulse: %s", err)
    83  	}
    84  
    85  	spew.Dump(p1)
    86  
    87  	pulse2 := &pulse.Pulse{
    88  		Title:   "TITLE THAT HOLDS COMMENT",
    89  		Content: "CONTENT THAT HOLDS COMMENT",
    90  		Parent:  p1.ID,
    91  	}
    92  
    93  	p2, err := c.Pulse.AddComment(pulse2)
    94  	if err != nil {
    95  		log.Fatalf("addComment:AddComment: %s", err)
    96  	}
    97  
    98  	spew.Dump(p2)
    99  }
   100  
   101  func pulseHistory(c *rest.Client) {
   102  	pulseHist, err := c.Pulse.PulseHistory()
   103  	if err != nil {
   104  		log.Fatalf("PulseHistory: %s", err)
   105  	}
   106  
   107  	spew.Dump(pulseHist)
   108  }
   109  
   110  func deletePulse(c *rest.Client) {
   111  	payload := &pulse.Pulse{
   112  		Title:   "TITLE TO BE DELETED",
   113  		Content: "CONTENT TO BE DELETED",
   114  	}
   115  
   116  	p, err := c.Pulse.AddPulse(payload)
   117  	if err != nil {
   118  		log.Fatalf("deletePulse:AddPulse: %s", err)
   119  	}
   120  
   121  	spew.Dump(p)
   122  
   123  	d, err := c.Pulse.DeletePulse(p.ID)
   124  	if err != nil {
   125  		log.Fatalf("deletePulse:DeletePulse: %s", err)
   126  	}
   127  
   128  	spew.Dump(d)
   129  }