-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
156 lines (132 loc) · 3.98 KB
/
main.js
File metadata and controls
156 lines (132 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const { waitForDebugger } = require('inspector');
const Binance = require('node-binance-api');
const { exit } = require('process');
const binance = new Binance().options({
APIKEY: '',
APISECRET: ''
});
const pairOne = 'XRPETH'
const pairTwo = 'ETHBTC'
const pairThree = 'XRPBTC'
var pairOneBid;
var pairOneAsk;
var pairTwoBid;
var pairTwoAsk;
var pairThreeBid;
var pairThreeSpread;
var pairThreeAsk;
var direction = 0;
var tradesOpen = false;
var gotData = false;
var longPathRate = 0;
var shortPathRate = 0;
var holding;
setInterval(decideFunction,150);
function getMarketData()
{
gotData = true;
binance.bookTickers(pairOne, (error, ticker) => {
if(ticker != undefined && ticker.bidPrice != undefined && ticker.askPrice != undefined)
{
pairOneBid = ticker.bidPrice;
pairOneAsk = ticker.askPrice;
console.info("Bid of Pair 1: ", pairOneBid);
console.info("Ask of Pair 1: ", pairOneAsk);
}
else{gotData = false;}
});
binance.bookTickers(pairTwo, (error, ticker) => {
if(ticker != undefined && ticker.bidPrice != undefined && ticker.askPrice != undefined)
{
pairTwoBid = ticker.bidPrice;
pairTwoAsk = ticker.askPrice;
console.info("Bid of Pair 2: ", pairTwoBid);
console.info("Ask of Pair 2: ", pairTwoAsk);
}
else{gotData = false;}
});
binance.bookTickers(pairThree, (error, ticker) => {
if(ticker != undefined && ticker.bidPrice != undefined && ticker.askPrice != undefined)
{
pairThreeBid = ticker.bidPrice;
pairThreeAsk = ticker.askPrice;
pairThreeSpread = pairThreeAsk - pairThreeBid;
console.info("Bid of Pair 3: ", pairThreeBid);
console.info("Ask of Pair 3: ", pairThreeAsk);
console.info("Spread of Pair 3: ", pairThreeSpread);
}
else{gotData = false;}
});
}
function decideFunction()
{
setTimeout(getMarketData,100);
if(tradesOpen && gotData)
{
manageTrade();
gotData = false;
}
else
{
placeTrade();
gotData = false;
}
}
function placeTrade()
{
if (((pairOneAsk*pairTwoAsk) - pairThreeAsk) / pairThreeAsk > 0.008)
{
/* PLACING TRADE RIGHT HERE IN REAL-TIME TRADING*/
longPathRate = pairOneAsk*pairTwoAsk;
shortPathRate = pairThreeAsk;
direction = 1;
console.log("direction: ", direction);
tradesOpen = true;
}
else if(((pairOneBid*pairTwoBid) - pairThreeBid) / pairThreeBid < -0.008)
{
/* PLACING TRADE RIGHT HERE IN REAL-TIME TRADING*/
longPathRate = pairOneBid*pairTwoBid;
shortPathRate = pairThreeBid;
direction = 2;
console.log("direction: ", direction);
tradesOpen = true;
}
//decideFunction();
}
function placeMarketOrder() {
getMarketData();
binance.balance();
if (((pairOneAsk*pairTwoAsk) - pairThreeAsk) / pairThreeAsk < -0.008)
{
// place buy order
binance.marketBuy(pairOne, holding);
binance.marketBuy(pairTwo, holding);
// place sell order
binance.marketSell(pairThree, holding);
}
}
function manageTrade()
{
getMarketData();
//decideFunction();
//listOpenOrders();
console.log("You made it to manageTrade()");
}
function placeStopLoss() {
binance.balance((error, balances) => {
if ( error ) return console.error(error);
console.log("balances()", balances);
console.log("ETH balance: ", balances.ETH.available);
});
if (binance.balance((error, balance) < 350)) {
var ETHAvailable = balances.ETH.available;
binance.sell("ETHBTC", ETHAvailable, )
marketSell(t)
}
}
function listOpenOrders() {
binance.openOrders(false, (error, openOrders) => {
console.info("openOrder()", openOrders);
});
}