-
Notifications
You must be signed in to change notification settings - Fork 8
/
mm.js
116 lines (102 loc) · 2.97 KB
/
mm.js
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
//EXAMPLE Market Making Bot using the graviex API
var graviex = require("./graviex.js");
graviex.accessKey = "";
graviex.secretKey = "";
/*
graviex.allMarketsTicker(function(res){
if(!res.error){
console.log(res);
}else{
console.log(res);
}
})
*/
//MARKET MAKER BOT TEST
setInterval(function() {
console.log("_________________________________________________________");
//test market maker bot\
var theMarket = "onzbtc";
var increase = 0.000000001;
var volume = 100;
//CLOSE ALL ORDERS
//
graviex.clearAllOrders(function(res){
if(!res.error){
console.log("Removing old orders...");
res.forEach(function(order){
console.log(order.id + "|" + order.state + "|" + order.side);
});
graviex.orderBook(theMarket, function(res){
if(!res.error){
//get spread
var selling = parseFloat(res.asks[0].price);
var buying = parseFloat(res.bids[0].price);
console.log("[Market Making]");
console.log("Selling At: " + selling.toFixed(9));
console.log("Buying At: " + buying.toFixed(9));
var spread = ((selling - increase) - (buying + increase)).toFixed(9);
console.log("Spread BTC: " + spread);
if(spread < 0.00000003){
//not worth it end
console.log("Not worth it, spread is to low...");
return;
}
//
//check if those orders our ours,
var oursSell = false;
var oursBuy = false;
graviex.orders("onzbtc", function(res){
if(!res.error){
//if not ours open orders + 1 and -1 each side of the market to try win spread
//console.log(res);
res.forEach(function(order){
console.log(order.price);
if(order.price == selling){
oursSell = true;
}
if(order.price == buying){
oursBuy = true;
}
});
var buyPrice = (buying + increase).toFixed(9);
var sellPrice = (selling - increase).toFixed(9);
if(!oursBuy || !oursSell){
console.log("Orders live are not ours, making new orders...");
//buy
console.log("Buy Price: " + buyPrice);
console.log("Sell Price: " + sellPrice);
graviex.createOrder("onzbtc", "buy", volume, buyPrice, function(res){
if(!res.error){
//sell
graviex.createOrder("onzbtc", "sell", volume, sellPrice, function(res2){
if(!res.error){
console.log(res.id + "|" + res.state + "|" + res.side);
console.log(res2.id + "|" + res2.state + "|" + res2.side);
//
//rinse and repeate?
//rinse and repeate?
//rinse and repeate?
}else{
console.log(res)
}
});
}else{
console.log(res)
}
});
}else{
console.log("Orders live are ours...");
}
}else{
console.log(res)
}
});
}else{
console.log(res)
}
});
}else{
console.log(res)
}
});
}, 30 * 1000); // 60 * 1000 milsec