123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package lmaxapi
- import (
- "tickserver/api/lmaxapi/response"
- "net/http"
- )
- type Callback func(err error)
- type OrderCallback func(string, error)
- type UrlCallback func(resp *http.Response, err error)
- type SearchInstrumentCallback func([]*response.Instrument, bool, error)
- type HeartbeatCallback func(string, error)
- type CompletedOrderCallback func([]*response.CompletedOrder, string, error)
- type ActivityCallback func([]*response.Activity, bool, error)
- type AccountStatementCallback func([]*response.AccountStatement, bool, error)
- type OrderTransactionCallback func([]*response.OrderTransaction, bool, error)
- func (this *Session) asynCallback(callback Callback, f func() error) error {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return nil
- }
- return f()
- }
- func (this *Session) asynUrlCallback(callback UrlCallback, f func() (*http.Response, error)) (*http.Response, error) {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return nil, nil
- }
- return f()
- }
- func (this *Session) asynSearchInstrumentCallback(callback SearchInstrumentCallback, f func() ([]*response.Instrument, bool, error)) ([]*response.Instrument, bool, error) {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return nil, false, nil
- }
- return f()
- }
- func (this *Session) asynGetCompletedOrder(callback CompletedOrderCallback, f func() ([]*response.CompletedOrder, string, error)) ([]*response.CompletedOrder, string, error) {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return nil, "", nil
- }
- return f()
- }
- func (this *Session) asynGetAccountStatement(callback AccountStatementCallback, f func() ([]*response.AccountStatement, bool, error)) ([]*response.AccountStatement, bool, error) {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return nil, false, nil
- }
- return f()
- }
- func (this *Session) asynGetOrderTransaction(callback OrderTransactionCallback, f func() ([]*response.OrderTransaction, bool, error)) ([]*response.OrderTransaction, bool, error) {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return nil, false, nil
- }
- return f()
- }
- func (this *Session) asynGetActivity(callback ActivityCallback, f func() ([]*response.Activity, bool, error)) ([]*response.Activity, bool, error) {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return nil, false, nil
- }
- return f()
- }
- func (this *Session) asynOrderCallback(callback OrderCallback, f func() (string, error)) (string, error) {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return "", nil
- }
- return f()
- }
- func (this *Session) asynHeartbeatCallback(callback HeartbeatCallback, f func() (string, error)) (string, error) {
- if callback != nil {
- this.asynCallWait.Add(1)
- go func() {
- callback(f())
- this.asynCallWait.Done()
- }()
- return "", nil
- }
- return f()
- }
- func (this *Session) Wait() {
- this.asynCallWait.Wait()
- }
|