main.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package main
  2. import "tickserver/api/fix"
  3. import "fmt"
  4. import "time"
  5. func main() {
  6. path := "E:/svn/gofix/src/fix/test/SessionCfg.cfg"
  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. fmt.Println("begin---------------")
  18. req := &fix.OrderRequest{}
  19. req.BookID = "510050"
  20. req.ClOrdID = app.GetTC().ClOrdID()
  21. req.Side = fix.Side_BUY
  22. req.OrderType = fix.OrdType_LIMIT
  23. req.Qty = 100
  24. req.Price = 1.650
  25. req.HandInst = '1'
  26. req.Account = "20410767"
  27. req.SecurityType = "CS"
  28. req.SecurityExchange = "XSHG"
  29. req.Currency = "CNY"
  30. app.SendOrder(req, func (event interface{}) {
  31. fmt.Println("send ok---------------")
  32. switch event.(type) {
  33. case *fix.OrderStatus : {
  34. data := event.(*fix.OrderStatus)
  35. fmt.Println("send", data)
  36. }
  37. }
  38. })
  39. time.Sleep(10 * time.Second)
  40. fmt.Println("+9999999")
  41. app.CancleOrder(req.ClOrdID, 100, func (event interface{}) {
  42. fmt.Println("888888888888888888888888")
  43. switch event.(type) {
  44. case *fix.OrderStatus : {
  45. data := event.(*fix.OrderStatus)
  46. fmt.Println("cancle", data)
  47. }
  48. }
  49. })
  50. wait <- 1
  51. }()
  52. trade, err := fix.NewAppTradeClient(app, ss)
  53. if err != nil {
  54. panic(err)
  55. }
  56. fmt.Println("run start")
  57. trade.Start()
  58. trade.Run()
  59. <-wait
  60. fmt.Println("run end")
  61. trade.Stop()
  62. trade.Free()
  63. fmt.Println("stop")
  64. /*
  65. path := "E:/svn/gofix/src/fix/test/SessionCfg.cfg"
  66. fmt.Println(path)
  67. ss , err := fix.NewSessionSettings(path)
  68. if err != nil {
  69. panic(err)
  70. }
  71. sourdatach := make(chan *fix.TickFull)
  72. //fix.InitBroadcast(sourdatach)
  73. app := fix.NewMarketInfoApp(sourdatach)
  74. trade, err := fix.NewAppTradeClient(app, ss)
  75. if err != nil {
  76. panic(err)
  77. }
  78. fmt.Println("run start")
  79. trade.Start()
  80. trade.Run()
  81. fmt.Println("run end")
  82. trade.Stop()
  83. trade.Free()
  84. fmt.Println("stop")
  85. */
  86. /*
  87. path := "E:/svn/gofix/src/fix/test/SessionCfg.cfg"
  88. ss , err := fix.NewSessionSettings(path)
  89. if err != nil {
  90. panic(err)
  91. }
  92. app := &fix.AppBase{}
  93. trade, err := fix.NewAppTradeClient(app, ss)
  94. if err != nil {
  95. panic(err)
  96. }
  97. trade.Start()
  98. fmt.Println("run start")
  99. trade.Run()
  100. fmt.Println("run end")
  101. trade.Stop()
  102. trade.Free()
  103. fmt.Println("stop")
  104. */
  105. }