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

     1  package main
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  
     7  	"github.com/bitfinexcom/bitfinex-api-go/v2/rest"
     8  	"github.com/davecgh/go-spew/spew"
     9  )
    10  
    11  // Set BFX_API_KEY and BFX_API_SECRET:
    12  //
    13  // export BFX_API_KEY=<your-api-key>
    14  // export BFX_API_SECRET=<your-api-secret>
    15  //
    16  // you can obtain it from https://www.bitfinex.com/api
    17  //
    18  // Below you can see different variations of using CancelOrderMulti function
    19  
    20  func main() {
    21  	key := os.Getenv("BFX_API_KEY")
    22  	secret := os.Getenv("BFX_API_SECRET")
    23  
    24  	c := rest.
    25  		NewClient().
    26  		Credentials(key, secret)
    27  
    28  	cancelAllOrders(c)
    29  	cancelByOrderIDs(c)
    30  	cancelByGroupOrderIDs(c)
    31  	cancelByClientOrderID(c)
    32  	cancelOrderMix(c)
    33  }
    34  
    35  func cancelAllOrders(c *rest.Client) {
    36  	args := rest.CancelOrderMultiRequest{All: 1}
    37  	resp, err := c.Orders.CancelOrderMulti(args)
    38  	if err != nil {
    39  		log.Fatalf("cancelAllOrders error: %s", err)
    40  	}
    41  
    42  	spew.Dump(resp)
    43  }
    44  
    45  func cancelByOrderIDs(c *rest.Client) {
    46  	args := rest.CancelOrderMultiRequest{OrderIDs: rest.OrderIDs{1189452509, 1189452510, 1189452511}}
    47  	resp, err := c.Orders.CancelOrderMulti(args)
    48  	if err != nil {
    49  		log.Fatalf("cancelByOrderIDs error: %s", err)
    50  	}
    51  
    52  	spew.Dump(resp)
    53  }
    54  
    55  func cancelByGroupOrderIDs(c *rest.Client) {
    56  	args := rest.CancelOrderMultiRequest{GroupOrderIDs: rest.GroupOrderIDs{888, 777}}
    57  	resp, err := c.Orders.CancelOrderMulti(args)
    58  	if err != nil {
    59  		log.Fatalf("cancelByGroupIDs error: %s", err)
    60  	}
    61  
    62  	spew.Dump(resp)
    63  }
    64  
    65  func cancelByClientOrderID(c *rest.Client) {
    66  	args := rest.CancelOrderMultiRequest{
    67  		ClientOrderIDs: rest.ClientOrderIDs{
    68  			{123, "2020-06-24"},
    69  			{321, "2020-06-24"},
    70  		},
    71  	}
    72  
    73  	resp, err := c.Orders.CancelOrderMulti(args)
    74  	if err != nil {
    75  		log.Fatalf("cancelByClientOrderID error: %s", err)
    76  	}
    77  
    78  	spew.Dump(resp)
    79  }
    80  
    81  func cancelOrderMix(c *rest.Client) {
    82  	args := rest.CancelOrderMultiRequest{
    83  		OrderIDs:      rest.OrderIDs{1189452432, 1189452435},
    84  		GroupOrderIDs: rest.GroupOrderIDs{888},
    85  		ClientOrderIDs: rest.ClientOrderIDs{
    86  			{321, "2020-06-24"},
    87  		},
    88  	}
    89  
    90  	resp, err := c.Orders.CancelOrderMulti(args)
    91  	if err != nil {
    92  		log.Fatalf("cancelOrderMix error: %s", err)
    93  	}
    94  
    95  	spew.Dump(resp)
    96  }