API


index.ts

  • devalpha

  • createTrader

    createTrader(settings, strategy)

    Create a trading stream, which uses supplied feeds as sources, and outputs feed events as well as events produced by the supplied strategy.

    Parameters
    • settingsanyAn object containing settings.
    • strategyStrategyA Strategy function.
    ReturnsStream

constants.ts

  • DASHBOARD_EVENTS= "@@devalpha/DASHBOARD_EVENTS"

  • DASHBOARD_FINISHED= "@@devalpha/DASHBOARD_FINISHED"

  • DASHBOARD_INITIALIZE= "@@devalpha/DASHBOARD_INITIALIZE"

  • FINISHED= "@@devalpha/FINISHED"

  • INITIALIZED= "@@devalpha/INITIALIZED"

  • ORDER_CANCEL= "@@devalpha/ORDER_CANCEL"

  • ORDER_CANCELLED= "@@devalpha/ORDER_CANCELLED"

  • ORDER_CREATED= "@@devalpha/ORDER_CREATED"

  • ORDER_FAILED= "@@devalpha/ORDER_FAILED"

  • ORDER_FILLED= "@@devalpha/ORDER_FILLED"

  • ORDER_PLACED= "@@devalpha/ORDER_PLACED"

  • ORDER_REJECTED= "@@devalpha/ORDER_REJECTED"

  • ORDER_REQUESTED= "@@devalpha/ORDER_REQUESTED"

  • SOCKETIO_CONNECT= "connect"

  • SOCKETIO_CONNECTION= "connection"

  • SOCKETIO_DISCONNECT= "disconnect"

  • SOCKETIO_RECONNECT= "reconnect"

  • SOCKETIO_RECONNECT_FAILED= "reconnect_failed"

  • SOCKET_PORT= "4449"


types.ts

  • Context

  • CreatedOrder

  • DevAlphaOptions

  • ExecutedOrder

  • FeedItem

  • Feeds

  • GuardOptions

  • IBar

  • LimitOrder

  • Order

  • PercentageOrder

  • Position

  • QuantityOrder

  • RootState

  • StopOrder

  • Store

  • StreamAction

  • TrailingOrder

  • AutomatedOrder

  • Bar

  • CapitalState

  • Consumer

  • Middleware

  • OrdersState

  • PositionsState

  • RequestedOrder

  • SizedOrder

  • Strategy

  • TimestampState


middleware/createBrokerBacktest.ts

  • createBrokerBacktest

    createBrokerBacktest(commission)

    Creates a broker middleware to be used when running backtests. In contrast to the realtime broker middleware, this middleware both places and fills an order in one cycle. This makes it possible to simulate what would happen if we always were able to perform our transactions at the historical date and time.

    Parameters
    • commissionnumber|FunctionCalculate the commission based on price and quantity
    ReturnsMiddleware

middleware/createBrokerRealtime.ts

  • createBrokerRealtime

    createBrokerRealtime(createClient)

    Creates a broker middleware to be used running backtests. In contrast to the backtest broker middleware, this middleware builds an order, then dispatches the built order for the next round-trip. When the built order arrives back at this middleware, it is executed synchronously.

    Parameters
    • createClientFunctionFactory function for building the client to be used when sending requests to an _actual_ broker.
    ReturnsMiddleware

middleware/createGuard.ts

  • createGuard

    createGuard(options)

    The guard middleware has the capability to alter orders or even prevent them from being requested in the first place.

    Parameters
    • optionsGuardOptionsA options object.
    ReturnsMiddleware

middleware/createStrategy.ts

  • createStrategy

    createStrategy(strategy)

    The strategy middleware supplies the strategy with context and action. The context is a plain object containing the `state()`, an `order()`-function and a `cancel()`-function for cancelling placed orders.

    Parameters
    • strategyStrategyThe strategy provided by the user.
    ReturnsMiddleware

middleware/index.ts


    reducers/capitalReducer.ts

    • capitalReducer

      capitalReducer(state, action)

      Reducer function for managing available and spent capital.

      Parameters
      • stateCapitalState|undefinedCurrent state.
      • actionStreamActionAn action received from the stream.
      ReturnsCapitalState

    reducers/index.ts

    • rootReducer


    reducers/ordersReducer.ts

    • ordersReducer

      ordersReducer(state, action)

      Reducer function for managing available open orders.

      Parameters
      • stateOrdersState|undefinedCurrent state.
      • actionStreamActionAn action received from the stream.
      Returns

    reducers/positionsReducer.ts

    • parseBar

      parseBar(maybeBar)

      Tries to collect properties assembling a chart bar from an object.

      Parameters
      • maybeBaranyA possible bar
      ReturnsBar
    • positionsReducer

      positionsReducer(state, action)

      Reducer function for managing open positions and their total value.

      Parameters
      • statePositionsState|undefinedCurrent state.
      • actionStreamActionAn action received from the stream.
      Returns

    reducers/timestampReducer.ts

    • timestampReducer

      timestampReducer(state, action)

      Reducer function keeping track of the current millisecond unix timestamp.

      Parameters
      • statenumber|undefinedCurrent state.
      • actionStreamActionAn action received from the stream.
      Returnsnumber

    util/consumers.ts

    • createConsumer

    • createConsumerCreator


    util/orders.ts

    • createOrder

    • createOrderCreator


    util/streams.ts

    • createStreamMerged

      createStreamMerged(feeds)

      The createStreamMerged function simply merges all of the streams together, pushing values as they are received.

      Parameters
      • feedsFeedsA Feeds object containing multiple streams.
      ReturnsStream
    • createStreamSorted

      createStreamSorted(feeds)

      The createStreamSorted function is a little more advanced than its sibling createStreamMerged. This function pulls one item at a time from all of the streams and places each item in a Map. Then it compares items and pushes the one with the smallest timestamp. Finally, it pulls a new item and repats it all over again.

      Parameters
      • feedsFeedsA Feeds object containing multiple streams.
      ReturnsStream