Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ Explicando cada item da configuração:
- **amount** - opcional - informe o valor das operações individuais de compra e venda, na moeda especificada no parâmetro `amountCurrency`.
Por exemplo, se quer que as operações sejam de 100 reais, especifique `amount: 100` e `amountCurrency: 'BRL'`.
Valor padrão: 100.
- **amountCurrency** - opcional - informe a moeda, `'BRL'` ou `'BTC'`, em que está especificada a quantidade (parâmetro `amount`).
Observe que o seu eventual lucro de arbitragem será acumulado na moeda oposta, ou seja, se especificar `'BRL'`, seu lucro
- **amountCurrency** - opcional - informe a moeda, `'BRL'`, `'BTC'` ou `'ETH'`, em que está especificada a quantidade (parâmetro `amount`).
A moeda fiat padrão é `'BRL'`, e a criptomoeda padrão é `'BTC'`, por exemplo, se especificar `'BRL'` a arbitragem será realizada no par `BRL/BTC`,
e caso especifique `'ETH'`, a arbitragem será realizada no par `BRL/ETH`.
O seu eventual lucro (ou prejuízo) de arbitragem será acumulado na moeda oposta, ou seja, se especificar `'BRL'`, seu lucro
será acumulado em BTC, e se especificar `'BTC'`, seu lucro será acumulado em BRL.
Valor padrão: `'BRL'`.
- **initialBuy** - opcional - informe `true` para que o robô execute primeiro compra e depois venda, `false` para que execute
primeiro venda depois compra. Se o seu saldo inicial está em reais, use `true`, se está em BTC, use `false`.
Valor padrão: `true`.
- **minProfitPercent** - informe o lucro mínimo potencial, em percentual, para que o robô tente executar a arbitragem.
Por exemplo, informe `0.01` para que o robô execute arbitragem sempre que o lucro potencial seja igual ou maior a 0,01%.
Valor padrão: `0.02`.
Valor padrão: `0.02` (0.02%).
- **intervalSeconds** - opcional - o intervalo, em segundos, entre verificações de oportunidade de arbitragem.
Informe `null` para que o robô calcule o menor intervalo permitido pela API.
Valor padrão: `null`.
Expand Down
139 changes: 135 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Toledo <gustavo@obex.pw>",
"license": "MIT",
"dependencies": {
"biscoint-api-node": "^1.2.4",
"biscoint-api-node": "git+ssh://git@github.com/Biscoint/biscoint-api-node.git#v1.2.5-RC.4",
"esm": "^3.2.25",
"lodash": "^4.17.21",
"play-sound": "^1.1.3"
Expand Down
28 changes: 17 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,53 @@ import config from './config.js';
// read the configurations
let {
apiKey, apiSecret, amount, amountCurrency, initialBuy, minProfitPercent, intervalSeconds, playSound, simulation,
executeMissedSecondLeg,
executeMissedSecondLeg, apiUrl = undefined,
} = config;

// global variables
let bc, lastTrade = 0, isQuote, balances;
let bc, lastTrade = 0, isQuote, balances, base;

// Initializes the Biscoint API connector object.
const init = () => {
if (!apiKey) {
handleMessage('You must specify "apiKey" in config.json', 'error', true);
}
handleMessage(`API key: "${_.truncate(apiKey, { length: 8, omission: '...'})}"`);
if (!apiSecret) {
handleMessage('You must specify "apiSecret" in config.json', 'error', true);
}

amountCurrency = _.toUpper(amountCurrency);
if (!['BRL', 'BTC'].includes(amountCurrency)) {
handleMessage('"amountCurrency" must be either "BRL" or "BTC". Check your config.json file.', 'error', true);
if (!['BRL', 'BTC', 'ETH'].includes(amountCurrency)) {
handleMessage('"amountCurrency" must be either "BRL", "BTC" or "ETH". Check your config.json file.', 'error', true);
}

if (isNaN(amount)) {
handleMessage(`Invalid amount "${amount}. Please specify a valid amount in config.json`, 'error', true);
}

isQuote = amountCurrency === 'BRL';
base = isQuote ? 'BTC': amountCurrency,

bc = new Biscoint({
apiKey: config.apiKey,
apiSecret: config.apiSecret
apiKey,
apiSecret,
apiUrl,
});
};

// Checks that the balance necessary for the first operation is sufficient for the configured 'amount'.
const checkBalances = async () => {
balances = await bc.balance();
const { BRL, BTC } = balances;
const { BRL, BTC, ETH } = balances;

handleMessage(`Balances: BRL: ${BRL} - BTC: ${BTC} `);
handleMessage(`Balances: BRL: ${BRL} - BTC: ${BTC} - ETH: ${ETH}`);

const nAmount = Number(amount);
let amountBalance = isQuote ? BRL : BTC;
if (nAmount > Number(amountBalance)) {
let amountBalance = balances[amountCurrency];
if (nAmount > Number(amountBalance || 0)) {
handleMessage(
`Amount ${amount} is greater than the user's ${isQuote ? 'BRL' : 'BTC'} balance of ${amountBalance}`,
`Amount ${amount} is greater than the user's ${amountCurrency} balance of ${amountBalance}`,
'error',
true,
);
Expand Down Expand Up @@ -89,6 +92,7 @@ async function tradeCycle() {

const buyOffer = await bc.offer({
amount,
base,
isQuote,
op: 'buy',
});
Expand All @@ -101,6 +105,7 @@ async function tradeCycle() {

const sellOffer = await bc.offer({
amount,
base,
isQuote,
op: 'sell',
});
Expand Down Expand Up @@ -168,6 +173,7 @@ async function tradeCycle() {
);
secondLeg = await bc.offer({
amount,
base,
isQuote,
op: secondOp,
});
Expand Down
Loading