Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
[GB] add example usage, fix #2414
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed Aug 9, 2018
1 parent 5d3ff65 commit c0a96f9
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions docs/gekko-broker/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,78 @@ TODO:
- Stop
- If Touched (stop but opposite direction)

### Example

Set up a Gekko Broker instance:

// from the gekko repo (make sure you have deps installed
// inside the exchange folder).
const Broker = require('../gekko/exchange/GekkoBroker');
// or from NPM
// const Broker = require('gekko-broker');

const binance = new Broker({
currency: 'USDT',
asset: 'BTC',
private: true,

exchange: 'binance',
key: 'x', // add your API key
secret: 'y' // add your API secret
});

Now we have an instance that can create a [sticky order](./sticky_order.md):

const type = 'sticky';
const side = 'buy';
const amount = 1;

const order = binance.createOrder(type, side, amount);

order.on('statusChange', s => console.log(now(), 'new status', s));
order.on('fill', s => console.log(now(), 'filled', s));
order.on('error', s => console.log(now(), 'error!', e));
order.on('completed', a => {
console.log(new Date, 'completed!');
order.createSummary((err, s) => {
console.log(new Date, 'summary:');
console.log(JSON.stringify(s, null, 2));
});
});

This one doesn't have an upper limit price for what it will buy at. It will stick it's bid offer at BBO until it's filled. If you have a limit in mind you can specify it when creating, do this instead:

const order = binance.createOrder(type, side, amount, { limit: 100 });

It will never offer to buy for more than 100, even if the BBO is above 100 (the bid will end up deep in the book).

At any point in time you can change the limit (or the amount), for example:

order.moveLimit(120);

Running the above example (without setting a limit and moving it) will yield:

root@foxtail:~/gb/nusadua# node b
2018-07-29 03:46:02 new status SUBMITTED
2018-07-29 03:46:02 new status OPEN
2018-07-29 03:46:04 filled 1
2018-07-29 03:46:04 new status FILLED
2018-07-29T03:46:04.127Z 'completed!'
2018-07-29T03:46:04.358Z 'summary:'
{
"price": 0.0017479,
"amount": 1,
"date": "2018-07-29T03:46:02.576Z",
"side": "buy",
"orders": 1,
"fees": {
"BNB": 0.00075
},
"feePercent": 0.075
}

NOTE: not all status changes are documented and more events are planned but not implemented.

### TODO

- finish all exchange integrations that gekko supports
Expand Down

0 comments on commit c0a96f9

Please sign in to comment.