Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From Zero to Forex Trading Bot Hero with Node.j...

From Zero to Forex Trading Bot Hero with Node.js and Typescript

During this talk, you will discover Daniele's journey building a trading bot. From building a basic prototype in Typescript to using functional programming techniques to trade autonomously across multiple foreign exchanges and generate thousands of dollars in revenue.

By the end of the talk you will learn:

- the basics of financial trading platforms from a developer's perspective (APIs/concepts/terminology)
- how you can use the skills you've gained building full stack applications to write trading software
- how static typing and Typescript can speed up your workflow
- how functional programming can help you refine your trading algorithms and verify the correctness of your program

Daniele Polencic

April 10, 2019
Tweet

More Decks by Daniele Polencic

Other Decks in Technology

Transcript

  1. "As part of its normal process, the UTP distributed test

    data and certain third parties improperly propagated the data." - NASDAQ
  2. mvp

  3. mvp

  4. function update(state, message) { switch(message.type) { case 'PRICE_TICK': return {

    ...state, currentPrice: message.price }; default: return state; } } const newState = update(state, message); console.log(newState); // {currentPrice: 1.3508};
  5. Bad ❌ function update(state, message) { switch(message.type) { case 'PRICE_TICK':

    /* SIDE EFFECT! */ updateOrderWithPrice(message.price); return { ...state, currentPrice: message.price }; default: return state; } }
  6. Good function(state, action) { switch(action.type) { case 'PRICE_TICK': return {

    ...state, currentPrice: message.price }; case 'ORDER_UPDATED': return { ...state, openOrder: message.order }; } }
  7. mvp

  8. function(state, message) { switch(message.type) { case 'PRICE_TICK': return [ {...state,

    currentPrice: message.price}, updateOrderWithPrice(message.price) ]; } }
  9. updateOrderWithPrice(message.price) function updateOrderWithPrice(price) { return { commandType: 'UPDATE_ORDER', price };

    } console.log(updateOrderWithPrice(1.2)) // { // price: 1.2, // commandType: 'UPDATE_ORDER' // }
  10. AST const fetch = { commandType: 'FETCH', url: '/any_url' };

    const log = { commandType: 'LOG', value: 'Hello World!' };
  11. interpreter function interpreter(commands) { commands.forEach(command => { switch(command.commandType) { case

    'FETCH': request(command.url); case 'LOG': console.log(command.value); } }); }
  12. unit testing it('should update the order', () => { const

    order = {id: 1, price: 1.12, active: true}; const currentTickPrice = 1.11; expect(updateOrder(order, currentTickPrice)).toEqual(UPDATE); });
  13. it('should update the order'); it('should do nothing'); it('should cancel the

    order'); it('should NOT update the order'); it('should NOT do nothing'); it('should NOT cancel the order');
  14. it('should update the order', () => { const order =

    {id: 1, price: 1.12, active: true}; const currentTickPrice = 1.11; expect(updateOrder(order, currentTickPrice)).toEqual(UPDATE); }); it('should do nothing', () => { const order = {id: 1, price: 1.12, active: true}; const currentTickPrice = 1.12; expect(updateOrder(order, currentTickPrice)).toEqual(DO_NOTHING); }); it('should cancel the order', () => { const order = {id: 1, price: 1.12, active: true}; const currentTickPrice = 1.22; expect(updateOrder(order, currentTickPrice)).toEqual(CANCEL); }); it('should NOT update the order', () => { const order = {id: 1, price: 1.12, active: true}; const currentTickPrice = 1.11; expect(updateOrder(order, currentTickPrice)).toEqual(UPDATE); }); it('should NOT do nothing', () => { const order = {id: 1, price: 1.12, active: true}; const currentTickPrice = 1.12; expect(updateOrder(order, currentTickPrice)).toEqual(DO_NOTHING); }); it('should NOT cancel the order', () => { const order = {id: 1, price: 1.12, active: true}; const currentTickPrice = 1.22; expect(updateOrder(order, currentTickPrice)).toEqual(CANCEL); });
  15. unit testing it('should update the order', () => { const

    order = {id: 1, price: 1.12, active: true}; // CHANGE ME const currentTickPrice = 1.11; // CHANGE ME expect(updateOrder(order, currentTickPrice)).toEqual(UPDATE); });
  16. unit testing test(updateOrder, () => { given({id: 1, price: 1.11,

    active: true}, 1.12).expect(UPDATE); given({id: 1, price: 1.12, active: true}, 1.12).expect(DO_NOTHING); given({id: 1, price: 1.12, active: true}, 1.22).expect(CANCEL); });
  17. unit testing test(updateOrder, () => { given({id: 1, price: 1.11,

    active: true}, 1.12).expect(UPDATE); given({id: 1, price: 1.12, active: true}, 1.12).expect(DO_NOTHING); given({id: 1, price: 1.12, active: true}, 1.22).expect(CANCEL); given({id: 1, price: 1.11, active: false}, 1.12).expect(DO_NOTHING); given({id: 1, price: 1.12, active: false}, 1.12).expect(DO_NOTHING); given({id: 1, price: 1.12, active: false}, 1.22).expect(DO_NOTHING); });
  18. orders interace IOrder = { id: number price: number };

    const order: IOrder = { id: 1, price: 1.12 };
  19. orders with state interace IOrder = { id: number price:

    number active: boolean }; const order: IOrder = { // ERROR! `active` is missing id: 1, price: 1.12 };
  20. const messages = [ {type: 'TICK', price: 1.12}, {type: 'TICK',

    price: 1.13}, {type: 'SUBMITTED', price: 1.13}, {type: 'COMPLETED', id: 1}, ]; const initialState = { openOrders: [] }; const finalState = messages.reduce((state, message) => { return Update(state, message); }); expect(finalState).toMatchSnapshot();
  21. hungry for more? · The Elm Architectureҁ0.18҂effect moduleϮϯ · Effect

    Manager ΄ͭͥΕ · How to structure Elm with multiple models? · Tribeca · Blackbird · Extensible Effects in Node.js, Part 1