UNPKG

act-client

Version:
189 lines (144 loc) 5.55 kB
const expect = require('chai').expect const wrapper = require('../wrapper.js') var varStreaming var ti describe("ACT API REST TESTING", function() { it('Get Authentication token', async function(){ try { wrapper.setUserPassword("demo", "demo") wrapper.setUrl("http://dockerfx.adhara.io:81") //wrapper.setUrl("http://actfx.adhara.io:81") const token = await wrapper.getAuthentication() expect(token).not.to.be.undefined } catch(err){ expect(token).not.to.be.undefined } }) it('Get Trading Interface', async function() { try { ti = await wrapper.getInterface(null) expect(ti).not.to.be.undefined } catch (err){ expect(ti).not.to.be.undefined } }) it('Get Account', async function() { try { const account = await wrapper.getAccount(null) expect(account).not.to.be.undefined } catch (err){ expect(account).not.to.be.undefined } }) it('Get Price Polling', async function() { try { const price = await wrapper.getPricePolling("EUR/USD", null, null, null, null) expect(price).not.to.be.undefined } catch (err){ expect(price).not.to.be.undefined } }) it('Get Price Streaming', async function() { try{ await wrapper.getPriceStreaming("EUR/USD", null, null, null, null, checkStreaming) expect(varStreaming).not.to.be.undefined varStreaming = undefined } catch (err){ expect(varStreaming).not.to.be.undefined } }) it('Set Market Order', async function() { try{ const order = await wrapper.setOrder('EUR/USD', ti.getInterfaceResponse.tinterface[0].name, 100000, "sell", "market", "fill or kill", null, null, null, null, null, null) expect(order).not.to.be.undefined } catch (err){ expect(order).not.to.be.undefined } }) it('Get Order Polling', async function() { try{ const orders = await wrapper.getOrderPolling(null, null, null, null, null ) expect(orders).not.to.be.undefined } catch (err){ expect(orders).not.to.be.undefined } }) it('Get Order Streaming', async function() { try{ await wrapper.getOrderStreaming(null, null, null, null, checkStreaming) expect(varStreaming).not.to.be.undefined varStreaming = undefined } catch (err){ expect(varStreaming).not.to.be.undefined } }) it('Modify Limit Order', async function() { try{ const priceResponse = await wrapper.getPricePolling("EUR/USD", null, null, null, null) price = priceResponse.getPriceResponse await wrapper.setOrder('EUR/USD', ti.getInterfaceResponse.tinterface[0].name, 100000, "buy", "limit", "good till cancel", price.tick[0].price - 0.00060, null, null, null, null, null) const pendingOrders = await wrapper.getOrderPolling(null, null, ["pending"], null) const numberPendingOrders = pendingOrders.getOrderResponse.order.length const lastPendingOrders = pendingOrders.getOrderResponse.order[ numberPendingOrders - 1] const order = await wrapper.modifyOrder(lastPendingOrders.fixid, price.tick[0].price - 0.00040, 200000, null) expect(order).not.to.be.undefined } catch (err){ expect(order).not.to.be.undefined } }) it('Cancel Limit Order', async function() { try{ const priceResponse = await wrapper.getPricePolling("EUR/USD", null, null, null, null) price = priceResponse.getPriceResponse await wrapper.setOrder('EUR/USD', ti.getInterfaceResponse.tinterface[0].name, 100000, "buy", "limit", "good till cancel", price.tick[0].price - 0.00060, null, null, null, null, null) const pendingOrders = await wrapper.getOrderPolling(null, null, ["pending"], null) const numberPendingOrders = pendingOrders.getOrderResponse.order.length const lastPendingOrders = pendingOrders.getOrderResponse.order[ numberPendingOrders - 1] const order = wrapper.cancelOrder(lastPendingOrders.fixid, null) expect(order).not.to.be.undefined } catch (err){ expect(order).not.to.be.undefined } }) it('Get Positions Polling', async function() { try{ const positions = await wrapper.getPositionPolling(null, null, null, null, null) expect(positions).not.to.be.undefined } catch (err){ expect(positions).not.to.be.undefined } }) it('Get Positions Streaming', async function() { try{ await wrapper.getPositionStreaming(null, null, null, null, checkStreaming) expect(varStreaming).not.to.be.undefined varStreaming = undefined } catch (err){ expect(varStreaming).not.to.be.undefined } }) it('Get Historical Prices', async function() { try{ const historicalPrices = await wrapper.getHistoricalPrices (["EUR/USD"], null, "s1", "ask", 2, null) expect(historicalPrices).not.to.be.undefined } catch (err){ expect(historicalPrices).not.to.be.undefined } }) it('Get Indicators Streaming', async function() { try{ await wrapper.getIndicatorStreaming(["EUR/USD"], null, "APO", 5, 3, checkStreaming) expect(varStreaming).not.to.be.undefined varStreaming = undefined } catch (err){ expect(varStreaming).not.to.be.undefined } }) }) function checkStreaming(response, myEmitter){ varStreaming = response myEmitter.emit('endStreaming'); }