Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete example #247

Open
biancheng347 opened this issue Jan 15, 2024 · 1 comment
Open

Complete example #247

biancheng347 opened this issue Jan 15, 2024 · 1 comment

Comments

@biancheng347
Copy link

biancheng347 commented Jan 15, 2024

After studying sdk and documents for a long time, in v2 rest, I can't figure out create_order(limt, market), cancel_order, get_order, exchange_info, where rsp contains status. Please give a complete case, thank you

@Davi0kProgramsThings
Copy link

Hi @biancheng347.

Setup

package main

import (
    "os"

    "github.com/bitfinexcom/bitfinex-api-go/v2"
)

func main() {
    key := os.Getenv("BFX_API_KEY")
    secret := os.Getenv("BFX_API_SECRET")
    c := bitfinex.NewClient().Credentials(key, secret)
}

Retrieve your active orders

You have 3 ways to retrieve your active orders:

All

data, err := c.Orders.All()

GetBySymbol

data, err := c.Orders.GetBySymbol("tBTCUSD")

GetByOrderId

order, err := c.Orders.GetByOrderId(33950998275)

Note

Remember to check for errors:

if err != nil {
    panic(err)
}

Submit a new order

func (s *OrderService) SubmitOrder(onr *order.NewRequest) (*notification.Notification, error)

First you need to define a NewRequest object:

request := order.NewRequest{
    Symbol: "tBTCUSD",
    CID:    time.Now().Unix() / 1000,
    Amount: 0.02,
    Type:   "EXCHANGE LIMIT",
    Price:  5000,
})

Then you can submit it:

notification, err := c.Orders.SubmitOrder(&request)

Notification

You can use the notification object to access more information about the operation:

order := notification.NotifyInfo.(*order.Order)

if notification.Status == "SUCCESS" {
    fmt.Printf("Successful new order for %v at %v$.", order.Symbol, order.Price)
}

if notification.Status == "ERROR" {
    fmt.Printf("Something went wrong: %v.", notification.Text)
}

Cancel an active order

func (s *OrderService) SubmitCancelOrder(oc *order.CancelRequest) error

You can delete an active order by passing its ID:

err := c.Orders.SubmitCancelOrder(&order.CancelRequest{
    ID: 33950998275
})

You can delete an active order via its CID and CIDDate:

err := c.Orders.SubmitCancelOrder(&order.CancelRequest{
    CID: 1573476747887,
    CIDDate: "2014-11-12"
})

API reference

order.Snapshot

order.Order

order.NewRequest

order.CancelRequest

notification.Notification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants