gruelbox/orko

Script Engine: Access to Order Book

AwooOOoo opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
Allow the script engine to expose access to the orderbook data as seen in the orders window

Describe the solution you'd like
Expose 'orders' object such as;

{
  open: {
    { type: 'SELL', orderState: 'onExchange', limit: '0.65', trigger: '0.65', amount: '100', filled: '0.0'},
    { type: 'SELL', orderState: 'onExchange', limit: '0.75', trigger: '0.75', amount: '100', filled: '0.0'}
  },
  history: [
    { created: '8/16/2020 10:00:00 AM', price: '0.55', amount: '100', fee: '5.5', feeCcy: 'EUR' },
    { created: '8/16/2020 10:05:00 AM', price: '0.45', amount: '100', fee: '4.5', feeCcy: 'EUR' }
  ] 
}

Describe alternatives you've considered
I haven't yet had a chance to look at your internal data structures to see what correct enumerations for different states are; such as is 'SELL' always capitalized, what are the enumeration states for 'orderState' etc?

Assign this to me, I'll work on it after I finish cleaning up adding balance support (#983).

Some examples for the new support;

Open Orders

var count = 0;

function start() {
  var subscription = events.setOpenOrders(
    function(event) {
      notifications.info("*** OPEN ORDERS: " + event.openOrders());
      
      if (count++ >= 1) {
        control.done()
      }
    },
    parameters.selectedCoin
  );
  
  return RUNNING
}

function stop() {
  events.clear(subscription);  // Stop the subscription
}

Example Response:

Open orders:
[order=LimitOrder [limitPrice=360, Order [type=ASK, originalAmount=10, cumulativeAmount=0, averagePrice=0, fee=0, instrument=ETH/EUR, id=1, timestamp=Thu Aug 20 16:08:14 CEST 2020, status=NEW, flags=[], userReference=175420665]]]
[order=LimitOrder [limitPrice=370, Order [type=ASK, originalAmount=10, cumulativeAmount=0, averagePrice=0, fee=0, instrument=ETH/EUR, id=2, timestamp=Thu Aug 20 16:08:19 CEST 2020, status=NEW, flags=[], userReference=154148732]]]

Order Book

var count = 0;

function start() {
  var subscription = events.setOrderBook(
    function(event) {
      notifications.info("*** OrderBook BIDS: " + event.orderBook().bids);
      notifications.info("*** OrderBook ASKS: " + event.orderBook().asks);
      
      if (count++ >= 1) {
        control.done()
      }
    },
    parameters.selectedCoin
  );
  
  return RUNNING
}

function stop() {
  events.clear(subscription);  // Stop the subscription
}

Example Response:

[LimitOrder [limitPrice=347.77000000, Order [type=BID, originalAmount=0.32508000, cumulativeAmount=null, averagePrice=null, fee=null, instrument=ETH/EUR, id=, timestamp=Thu Aug 20 15:12:35 CEST 2020, status=null, flags=[], userReference=192475211]], LimitOrder [limitPrice=347.75000000, Order [type=BID, originalAmount=0.16254000, cumulativeAmount=null, averagePrice=null, fee=null, instrument=ETH/EUR, id=, timestamp=Thu Aug 20 15:12:37 CEST 2020, status=null, flags=[], userReference=113477373]], LimitOrder [limitPrice=347.56000000, Order [type=BID, originalAmount=1.07717000, cumulativeAmount=null, averagePrice=null, fee=null, instrument=ETH/EUR, id=, timestamp=Thu Aug 20 15:12:26 CEST 2020, status=null, flags=[], userReference=155455028]], LimitOrder [limitPrice=347.38000000, Order [type=BID, originalAmount=2.69161000, cumulativeAmount=null, averagePrice=null, fee=null, instrument=ETH/EUR, id=null, timestamp=null, status=null, flags=[], userReference=115320557]] ...