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

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  
     7  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/order"
     8  	"github.com/bitfinexcom/bitfinex-api-go/v2/rest"
     9  	"github.com/davecgh/go-spew/spew"
    10  )
    11  
    12  // Set BFX_API_KEY and BFX_API_SECRET:
    13  //
    14  // export BFX_API_KEY=<your-api-key>
    15  // export BFX_API_SECRET=<your-api-secret>
    16  //
    17  // you can obtain it from https://www.bitfinex.com/api
    18  //
    19  // Below you can see different variations of using Order Multi ops
    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  	cancelOrdersMultiOp(c)
    30  	cancelOrderMultiOp(c)
    31  	orderNewMultiOp(c)
    32  	orderUpdateMultiOp(c)
    33  	orderMultiOp(c)
    34  }
    35  
    36  func cancelOrdersMultiOp(c *rest.Client) {
    37  	resp, err := c.Orders.CancelOrdersMultiOp(rest.OrderIDs{1189452506, 1189452507})
    38  	if err != nil {
    39  		log.Fatalf("CancelOrdersMultiOp error: %s", err)
    40  	}
    41  
    42  	spew.Dump(resp)
    43  }
    44  
    45  func cancelOrderMultiOp(c *rest.Client) {
    46  	resp, err := c.Orders.CancelOrderMultiOp(1189502586)
    47  	if err != nil {
    48  		log.Fatalf("CancelOrderMultiOp error: %s", err)
    49  	}
    50  
    51  	spew.Dump(resp)
    52  }
    53  
    54  func orderNewMultiOp(c *rest.Client) {
    55  	o := order.NewRequest{
    56  		CID:    119,
    57  		GID:    118,
    58  		Type:   "EXCHANGE LIMIT",
    59  		Symbol: "tBTCUSD",
    60  		Price:  12,
    61  		Amount: 0.002,
    62  	}
    63  
    64  	resp, err := c.Orders.OrderNewMultiOp(o)
    65  	if err != nil {
    66  		log.Fatalf("OrderNewMultiOp error: %s", err)
    67  	}
    68  
    69  	spew.Dump(resp)
    70  }
    71  
    72  func orderUpdateMultiOp(c *rest.Client) {
    73  	o := order.UpdateRequest{
    74  		ID:     1189503586,
    75  		Price:  12,
    76  		Amount: 0.002,
    77  	}
    78  
    79  	resp, err := c.Orders.OrderUpdateMultiOp(o)
    80  	if err != nil {
    81  		log.Fatalf("OrderUpdateMultiOp error: %s", err)
    82  	}
    83  
    84  	spew.Dump(resp)
    85  }
    86  
    87  func orderMultiOp(c *rest.Client) {
    88  	pld := rest.OrderOps{
    89  		{
    90  			"on",
    91  			order.NewRequest{
    92  				CID:    987,
    93  				GID:    876,
    94  				Type:   "EXCHANGE LIMIT",
    95  				Symbol: "tBTCUSD",
    96  				Price:  13,
    97  				Amount: 0.001,
    98  			},
    99  		},
   100  		{
   101  			"oc",
   102  			map[string]int{"id": 1189502587},
   103  		},
   104  		{
   105  			"oc_multi",
   106  			map[string][]int{"id": rest.OrderIDs{1189502588, 1189503341}},
   107  		},
   108  		{
   109  			"ou",
   110  			order.UpdateRequest{
   111  				ID:     1189503342,
   112  				Price:  15,
   113  				Amount: 0.002,
   114  			},
   115  		},
   116  	}
   117  
   118  	resp, err := c.Orders.OrderMultiOp(pld)
   119  	if err != nil {
   120  		log.Fatalf("OrderMultiOp error: %s", err)
   121  	}
   122  
   123  	spew.Dump(resp)
   124  }