-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconsole.js
executable file
·108 lines (83 loc) · 2.4 KB
/
console.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
#!/usr/bin/env node
"use strict";
require('./core/polyfill');
const repl = require('repl');
const term = require('./core/terminal');
const command = require('./core/command');
const api = require('./lightning/api');
const pub = require('./lightning/builder/pub');
const pri = require('./lightning/builder/pri');
const version = require('./package.json').version;
const banner = `${term.yellow}${term.bold}
_ _
| | | |
| |__ | | __ _ ___
| '_ \\| |/ _\` |/ __|
| |_) | | (_| | (__
|_.__/|_|\\__,_|\\___|
${term.reset}${term.yellow}
bitflyer - lightning - api - console
${term.reset}
コンテキスト変数:
api -> APIクライアント
pub -> パブリックAPI
pri -> プライベートAPIと認証
コマンド:
.help または .bf_* help を参照
> .bf_buy help
APIドキュメント:
bitFlyer Lightning API - https://lightning.bitflyer.jp/docs
例:
> pri.set_credential(YOUR_API_KEY, YOUR_API_SECRET)
> pri.getchildorders.create()
> _.product_code("BTC_JPY").child_order_state("ACTIVE")
> _.executeSync()
`;
const loadCredential = () => {
try {
const config = require('./.credential.json');
if (config.api_key && config.api_secret) {
pri.set_credential(config.api_key, config.api_secret);
console.log(term.colorful(term.green, " (.credential.json loaded)\n\n"));
}
} catch (e) {
// not found
}
};
const initContext = (context) => {
context.api = api;
context.pub = pub;
context.pri = pri;
};
const main = (program) => {
if (!program.nobanner) {
process.stdout.write(term.clear);
process.stdout.write(term.nl);
process.stdout.write(banner);
}
loadCredential();
let server = repl.start('> ');
initContext(server.context);
server.on('reset', initContext);
Object.values(command.commands)
.forEach(cmd => server.defineCommand(cmd.getName(), {
help: cmd.getHelp(),
action(arg) {
cmd.doAction(server, arg);
}
}));
};
const program = require('commander');
program
.version(require("./package.json").version)
.description("bitflyer - lightning - api - console")
.option("-n, --no-banner", "Don't show ugly startup banner", false)
.on("--help", () => {
console.log("");
console.log(" Examples:");
console.log("");
console.log(" $ node console.js -n");
console.log("");
})
.parse(process.argv);
main(program);