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() }