github.com/vmpartner/bitmex@v1.1.0/README.md (about)

     1  # Bitmex API
     2  Packages for work with bitmex rest and websocket API on golang.  
     3  Target of this packages make easy access to bitmex API including testnet platform.  
     4  
     5  Packages covered tests.  
     6  
     7  In rest package implemented basic must have methods, you can easy add needed method by extending rest package. Autocomplete working based on swagger bitmex package. Please contribute if you will add new methods.
     8  
     9  
    10  ## Usage
    11  Please see full example in main.go
    12  
    13  ####  REST
    14  ```
    15  // Load config
    16  cfg := config.LoadConfig("config.json")
    17  ctx := rest.MakeContext(cfg.Key, cfg.Secret, cfg.Host)
    18  
    19  // Get wallet
    20  w, response, err := rest.GetWallet(ctx)
    21  tools.CheckErr(err)
    22  fmt.Printf("Status: %v, wallet amount: %v\n", response.StatusCode, w.Amount)
    23  
    24  // Place order
    25  params := map[string]interface{}{
    26      "side":     "Buy",
    27      "symbol":   "XBTUSD",
    28      "ordType":  "Limit",
    29      "orderQty": 1,
    30      "price":    9000,
    31      "clOrdID":  "MyUniqID_123",
    32      "execInst": "ParticipateDoNotInitiate",
    33  }
    34  order, response, err := rest.NewOrder(app.Context, params)
    35  tools.CheckErr(err)
    36  fmt.Printf("Order: %+v, Response: %+v\n", order, response)
    37  ```
    38  
    39  #### Websocket
    40  ```
    41  // Load config
    42  cfg := config.LoadConfig("config.json")
    43  
    44  // Connect to WS
    45  conn := websocket.Connect(cfg.Host)
    46  defer conn.Close()
    47  
    48  // Listen read WS
    49  chReadFromWS := make(chan []byte, 100)
    50  go websocket.ReadFromWSToChannel(conn, chReadFromWS)
    51  
    52  // Listen write WS
    53  chWriteToWS := make(chan interface{}, 100)
    54  go websocket.WriteFromChannelToWS(conn, chWriteToWS)
    55  
    56  // Authorize
    57  chWriteToWS <- websocket.GetAuthMessage(cfg.Key, cfg.Secret)
    58  
    59  // Listen
    60  go func() {
    61      for {
    62          message := <-chReadFromWS
    63          res, err := bitmex.DecodeMessage(message)
    64          tools.CheckErr(err)
    65  
    66          // Business logic
    67          switch res.Table {
    68          case "orderBookL2":
    69              if res.Action == "partial" {
    70                  // Update table
    71              } else {
    72                  // Update row
    73              }
    74          case "order":
    75              if res.Action == "partial" {
    76                  // Update table
    77              } else {
    78                  // Update row
    79              }
    80          case "position":
    81              if res.Action == "partial" {
    82                  // Update table
    83              } else {
    84                  // Update row
    85              }
    86          }
    87      }
    88  }()
    89  
    90  ```
    91  
    92  ## Example
    93  Example of usage look in main.go
    94  
    95  ## More
    96  I spent a lot of time implementing this packages and will be glad of any support. Thank you!
    97  ```
    98  eth: 0x3e9b92625c49Bfd41CCa371D1e4A1f0d4c25B6fC
    99  btc: 35XDoFSA8QeM26EnCyhQPTMBZm4S1DvncE
   100  ```
   101  Those who will donated more $50 i will send my working private code bot based on neural analyze.