-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.dev.ts
More file actions
88 lines (77 loc) · 2.02 KB
/
Copy pathclient.dev.ts
File metadata and controls
88 lines (77 loc) · 2.02 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
import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";
import path from "path";
import { fileURLToPath } from "url";
import type { ProtoGrpcType } from "./proto/node";
import { Action } from "./proto/cex_broker/Action";
import { config } from "dotenv";
import { log } from "./helpers/logger";
import CEXBroker from ".";
// import CEXBroker from "../dist/index";
import { loadPolicy } from "./helpers";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Safe absolute path to proto
const protoPath = path.join(__dirname, ".", "proto", "node.proto");
const port = 8086;
const packageDef = protoLoader.loadSync(protoPath);
const grpcObj = grpc.loadPackageDefinition(
packageDef,
) as unknown as ProtoGrpcType;
const client = new grpcObj.cex_broker.cex_service(
`0.0.0.0:${port}`,
grpc.credentials.createInsecure(),
);
config();
const broker = new CEXBroker({}, loadPolicy("./policy/policy.json"), {
useVerity: true,
});
broker.loadEnvConfig();
broker.run();
const metadata = new grpc.Metadata();
// metadata.add("api-key", process.env.BYBIT_API_KEY ?? ""); // Example header
// metadata.add("api-secret", process.env.BYBIT_API_SECRET ?? "");
const deadline = new Date();
deadline.setSeconds(deadline.getSeconds() + 5);
client.waitForReady(deadline, (err) => {
if (err) {
log.error(err);
return;
}
onClientReady();
});
function onClientReady() {
// Test ExecuteAction for ticker
client.executeAction(
{
cex: "mexc",
symbol: "ETHUSDT",
action: Action.FetchTicker,
},
metadata,
(err, result) => {
if (err) {
log.error({ err });
return;
}
log.info("ExecuteAction Ticker Result:", { result });
},
);
// Test ExecuteAction for balance
client.executeAction(
{
cex: "binance",
symbol: "USDT,BTC,ETH",
payload: { type: "spot" },
action: Action.FetchBalances,
},
metadata,
(err, result) => {
if (err) {
log.error({ err });
return;
}
log.info("ExecuteAction Balance Result:", { result });
},
);
}