-
Notifications
You must be signed in to change notification settings - Fork 102
/
hashpower.js
107 lines (92 loc) · 2.09 KB
/
hashpower.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
import config from './config'
import Api from './api'
var log = function () {
return console.log(...arguments);
}
var algo, pool, order;
const api = new Api(config);
// get server time - required
api.getTime()
.then(() => {
log('server time', api.time)
log('--')
})
// get algo settings
.then(() => api.get('/main/api/v2/mining/algorithms'))
.then(res => {
algo = res.miningAlgorithms[0]; // SCRYPT
log('algorithms', res);
log('--')
})
// get balance
// .then(() => api.get('/main/api/v2/accounting/accounts2'))
// .then(res => {
// log('accounts', res);
// })
//// create new pool
.then(() => {
var body = {
algorithm: 'SCRYPT',
name: 'my pool',
username: 'pool_username',
password: 'x',
stratumHostname: 'pool.host.name',
stratumPort: '3456',
};
return api.post('/main/api/v2/pool',{body})
})
.then(res => {
pool = res;
log('new pool', res);
log('--')
})
// create new order
.then(() => {
var body = {
algorithm: 'SCRYPT',
amount: "0.005",
displayMarketFactor: algo.displayMarketFactor,
limit: algo.minSpeedLimit,
market: 'EU', // or USA
marketFactor: algo.marketFactor,
poolId: pool.id,
price: '0.0010',
type: 'STANDARD',
};
return api.post('/main/api/v2/hashpower/order',{body})
})
.then(res => {
order = res;
log('new order', res);
log('--')
})
// update order price or limit
.then(() => {
var body = {
displayMarketFactor: algo.displayMarketFactor,
marketFactor: algo.marketFactor,
limit: '0.11',
price: '0.00123',
};
return api.post(`/main/api/v2/hashpower/order/${order.id}/updatePriceAndLimit`,{body})
})
.then(res => {
log('updated order', res);
log('--')
})
// cancel order
.then(() => api.delete(`/main/api/v2/hashpower/order/${order.id}`))
.then(res => {
log('deleted order', res);
log('--')
})
// delete pool
.then(() => api.delete(`/main/api/v2/pool/${pool.id}`))
.then(res => {
log('deleted pool', res);
log('--')
})
.catch(err => {
if(err && err.response) log(err.response.request.method,err.response.request.uri.href);
log('ERROR', err.error || err);
})