main.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package main
  2. import "tickserver/api/fix"
  3. import "fmt"
  4. import "os"
  5. import "time"
  6. func main() {
  7. path := os.Getenv("GOPATH") + "/bin/data/trade.cfg"
  8. fmt.Println(path)
  9. ss , err := fix.NewSessionSettings(path)
  10. if err != nil {
  11. panic(err)
  12. }
  13. app := fix.NewOrderApp()
  14. wait := make(chan int)
  15. go func() {
  16. app.WaitReady()
  17. req := &fix.OrderRequest{}
  18. req.BookID = "4001"
  19. req.ClOrdID = app.GetTC().ClOrdID()
  20. req.Side = fix.Side_SELL
  21. req.OrderType = fix.OrdType_LIMIT
  22. req.Qty = 1.0
  23. req.Price = 1.3174
  24. req.TimeInForce = fix.TimeInForce_GOOD_TILL_CANCEL
  25. app.SendOrder(req, func (event interface{}) {
  26. switch event.(type) {
  27. case *fix.OrderStatus : {
  28. data := event.(*fix.OrderStatus)
  29. fmt.Println("send", data)
  30. }
  31. }
  32. })
  33. time.Sleep(10 * time.Second)
  34. app.CancleOrder(req.ClOrdID, 0.5, func (event interface{}) {
  35. switch event.(type) {
  36. case *fix.OrderStatus : {
  37. data := event.(*fix.OrderStatus)
  38. fmt.Println("cancle", data)
  39. }
  40. }
  41. })
  42. wait <- 1
  43. }()
  44. trade, err := fix.NewAppTradeClient(app, ss)
  45. if err != nil {
  46. panic(err)
  47. }
  48. fmt.Println("run start")
  49. trade.Start()
  50. trade.Run()
  51. <-wait
  52. fmt.Println("run end")
  53. trade.Stop()
  54. trade.Free()
  55. fmt.Println("stop")
  56. }