package response import ( "fmt" "testing" "encoding/xml" ) func TestOrderBookEvent(t *testing.T) { eventData := "4001|141bc6fee7a|20@1.34889;300@1.34888;210@1.34887;240@1.34886;670@1.34885|20@1.34892;90@1.34893;382.5@1.34894;530@1.34895;230@1.34896|1.35608;141b8c4b080|1.35713|1.34798|1.34889|1.34892|1.3489" event := NewOrderBookEvent(eventData) if event.InstrumentId != 4001 { t.Errorf("OrderBookEvent.InstrumentId Error") } data, err := event.Encode() if err != nil { t.Error(err) } if string(data) != "" + eventData + ""{ t.Errorf(string(data)) } } func TestInstrument(t *testing.T) { data := "
OK
4001EUR/USD2010-07-09T13:09:00-4151020America/New_York1USD100000.10.10999990.00180.000010CURRENCYEUR/USD500000.2500.2500.000.000.00360EUR10000.00MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAY2true
" insts := NewInstruments(data) ins := insts.Data[0] if ins.Id != 4001 { t.Errorf("Id Error") } if ins.Name != "EUR/USD" { t.Errorf("Name Error") } if ins.Symbol != "EUR/USD" { t.Errorf("Symbol Error") } if ins.Isin != "" { t.Errorf("Isin Error") } if ins.AssetClass != "CURRENCY" { t.Errorf("Symbol Error") } if ins.StartTime == nil { t.Error("StartTime Error") } if ins.OpenOffset != -415 { t.Errorf("Open Error") } if ins.CloseOffset != 1020 { t.Errorf("Close Error") } if ins.TimeZone != "America/New_York" { t.Errorf("Time Error") } if ins.TradingDays[2] != "WEDNESDAY" { t.Errorf("TeadingDays Error") } if ins.PriceIncrement != 0.00001 { t.Errorf("PriceIncrement Error") } if ins.OrderQuantityIncrement != 0.1 { t.Errorf("QuantityIncrement Error") } if ins.VolatilityBandPercentage != 2 { t.Errorf("VolatilityBandPercentage Error") } if ins.Currency != "USD" { t.Errorf("Current Error") } if ins.UnitPrice != 10000 { t.Errorf("UPrice Error") } if ins.UnitOfMeasure != "EUR" { t.Errorf("UnitOfMeasure Error") } if ins.ContractSize != 10000 { t.Errorf("ContractSize Error") } if ins.MinimumCommission != 0 { t.Errorf("MinCommission Error") } if ins.AggressiveCommissionRate != 0.25 { t.Errorf("aggressiveCommissionRate Error") } if ins.PassiveCommissionRate != 0.25 { t.Errorf("passiveCommissionRate Error") } if ins.DailyInterestRateBasis != 360 { t.Errorf("MinCommission Error") } if ins.LongSwapPoints != 0 { t.Errorf("MinCommission Error") } if ins.ShortSwapPoints != 0 { t.Errorf("MinCommission Error") } if ins.MarginRate != 0.01 { t.Errorf("Margin Error") } if ins.MaximumPosition != 50000 { t.Errorf("TeadingDays Error") } fmt.Println(ins.Name) } func TestRejectedEvent(t *testing.T) { data := "133434388540011235DUPLICATE_ORDER" event := NewInstructionRejectedEvent(data) if event.AccountId != 1334343885 { t.Errorf("RejectedEvent.AccountId Error") } if event.InstrumentId != 4001 { t.Errorf("RejectedEvent.InstrumentId Error") } if event.InstructionId != "1235" { t.Errorf("RejectedEvent.InstructionId Error") } if event.Reason != "DUPLICATE_ORDER" { t.Errorf("RejectedEvent.Reason Error") } } func TestAccountEvent(t *testing.T) { data := "13343438859998.031817951.936867951.93686-1237.21777808.87718USD9998.03181true" event := NewAccountStateEvent(data) if event.AccountId != 1334343885 { t.Errorf("AccountId Error:", event.AccountId) return } if event.Wallets[0].Balance != 9998.03181 { t.Errorf("Account.Wallets[0].balance Error", event.Wallets[0].Balance) return } data2, err := xml.Marshal(event) if err != nil { t.Error(err) return } if string(data2) != data { t.Errorf(string(data2)) return } } func TestOrderEventExecution(t *testing.T) { data := "ImmediateOrCancel72144778695791576577214477869579157657AAIm0gAAAAAP779F1086402984001-1000-908.5-1.217019227e+07-91.52013-11-11T11:53:56STOP_COMPOUND_MARKET-908.5-1.217019227e+07-1.217019227e+07304.254811.338255171136231.33964-201.33963-2601.33962-3201.33961-801.3396-1801.33913-47.91.33875-0.31.33825-0.3-91.5" ord, ex := NewOrderEvent(data) if ord == nil { t.Errorf("OrderExecution Error order nil") } if ex == nil { t.Errorf("OrderExecution Error Execution nil") } if ex.InstrumentId != 4001 { t.Errorf("OrderExecution Error Execution.Order.InstrumentId") } if ex.Quantity != -1000 { t.Errorf("OrderExecution Error Execution.Quantity:", ex.Quantity) } data2, err := xml.Marshal(ex) if err != nil { t.Error(err) return } if string(data2) != data { t.Errorf(string(data2)) return } } func TestOrderEvent(t *testing.T) { data := "ImmediateOrCancel72856354403324584997285635440332458499AAIm0gAAAAAEAVVR133434388540011113395.702013-06-19T08:07:45STOP_COMPOUND_MARKET113395.713395.70.334891.33957" event, ex := NewOrderEvent(data) if ex != nil { t.Errorf("OrderEvent Error Execution:", ex) } if event.InstructionId != "7285635440332458499" { t.Errorf("OrderEvent.InstructionId Error", event.InstructionId) } if event.Quantity != 1 { t.Errorf("OrderEvent.Quantity Error", event.Quantity) } if event.LimitPrice != 0 { t.Errorf("OrderEvent.LimitPrice Error", event.LimitPrice) } if event.StopReferencePrice != 1.33957 { t.Errorf("OrderEvent.StopReferencePrice Error", event.StopReferencePrice) } if event.StopProfitOffset != 0 { t.Errorf("OrderEvent.StopProfitOffset Error", event.StopProfitOffset) } if OrderType(event.OrderType) != "MARKET" { t.Errorf("OrderEvent.OrderType Error", event.OrderType) } data2, err := xml.Marshal(event) if err != nil { t.Error(err) return } if string(data2) != data { t.Errorf(string(data2)) return } } func TestPositionEvent(t *testing.T) { data := "13343438854001-1834.96500566795.366795.3" event := NewPositionEvent(data) fmt.Println(event) if event.AccountId != 1334343885 { t.Errorf("PositionEvent. Error", event.AccountId) } if event.Valuation != -1834.965 { t.Errorf("PositionEvent.Valuation Error", event.Valuation) } if event.OpenCost != 66795.3 { t.Errorf("PositionEvent.OpenCose Error", event.OpenCost) } } func TestHistoricEvent(t *testing.T) { data := "1https://testapi.LMAXtrader.com/marketdata/orderbook/4001/2011/05/2011-05-10-21-00-00-000-4001-bid-ask-tick-depth1.csv.gzhttps://testapi.LMAXtrader.com/marketdata/orderbook/4001/2011/05/2011-05-11-21-00-00-000-4001-bid-ask-tick-depth1.csv.gz" event := NewHistoricMarketData(data) fmt.Println(event.InstructionId) fmt.Println(event.Urls[0]) if len(event.Urls) != 2 { t.Errorf("HistoricMarketData.urls Error") } } func TestAccountDetail(t *testing.T) { data := "
OK
niniwzwUSD108640298STANDARD_TRADERCFD_DEMOUKen_GBfalse108640298null king wang4instrument_preferencesquantity-1004370.1tradingqtyInc-RATE10qtyInc-INDEX10qtyInc-EQUITY10qtyInc-CURRENCY10qtyInc-COMMODITY10qtyInc-SYSTEM_EXCHANGE_RATE10oneClickClosefalseoneClickTradingfalseladderOnQuickTicketfalsequickTicketSweepControlsfalsecontingentOrdersOnQuickTicketfalseactiveOrderTypeMARKETquickTicketTooltipstruenotificationsPanelShowntrueindividualPositionsPanelShowntrue
" event := NewAccountDetails(data) data2, err := xml.Marshal(event) if err != nil { t.Error(err) return } if string(data2) != data { t.Error("TestAccountDetail error", string(data2)) } } func TestOrders(t *testing.T) { data := "ImmediateOrCancel72136124895007045267213612489500704526AAIm0gAAAAAEelMb133434388540011113130.102013-06-25T11:17:06STOP_COMPOUND_MARKET113130.113130.10.328251.313011448872301.313011ImmediateOrCancel72136124895007045267213612489500704526AAIm0gAAAAAEelMb133434388540011113130.102013-06-25T11:17:06STOP_COMPOUND_MARKET113130.113130.10.328251.313011448872301.313011false-1" orders := &Orders{} err := xml.Unmarshal([]byte(data), orders) if err != nil { t.Error(err) return } //fmt.Println(orders.Data[0], orders.Data[1]) data2, err := xml.Marshal(orders) if err != nil { t.Error(err) return } if string(data2) != data { t.Error("TestOrders error", string(data2)) } }