用于 Evedex REST APIS 和 WebSockets 的节点.js & JavaScript SDK
[技选
此 SDK 允许程序访问 Evedex 交换 服务,包括市场数据流、账户计量和订单管理.
- 整合 sdk 与 Evedex REST API 和 WebSockets 合并.
- TypeScript 支持(大多数API请求和回复都有类型声明).
- 带有钱包私钥或 API 密钥的认证
- 实时余额,位置,订单簿,以及带有缓存管理的订单状态更新.
- 通过钱包账户处理命令的方法:创建替换取消命令.
- 包括订单、位置和取出方法的内部签名请求有效载荷
安装
-
输入 npm 项目
-
安装交换- 机器人- sdk 依赖性
pnpm add @evedex/exchange-bot-sdk
使用量
初始化容器
可以使用演示(用于测试目的)或生产环境. 要初始化容器, 您需要通过 Websocket 实例 .
如果您使用节点环境, 您需要安装 ws 此外:
pnpm add ws
在初始化容器方法时使用
import { WebSocket } from "ws";
德莫·特拉迪环 环境
const isDebugMode = true; // optional parameter false by default, true for debugging mode
const container = new evedexSdk.DemoContainer({
centrifugeWebSocket: WebSocket,
wallets: {
baseAccount: {
privateKey: "0x...",
},
},
apiKeys: {},
}, isDebugMode);
生产环境
const container = new evedexSdk.ProdContainer({
centrifugeWebSocket: WebSocket,
wallets: {
baseAccount: {
privateKey: "0x...",
},
},
apiKeys: {},
});
初始化账户
Api 密钥账户
ApiKeyAccount旨在读取用户账户状态,包括:余额,位置,订单.
如果您已经登录到 evedex 交换, 可以创建 api 密钥 .
点击右上角的avatar, 进入配置菜单。 请访问设置 API 创建 API 密钥
输入示例
import * as evedexSdk from "@evedex/exchange-bot-sdk";
const container = evedexSdk.initContainer(evedexSdk.Environment.DEMO, {
centrifugeWebSocket: WebSocket,
wallets: {},
apiKeys: {
mainApiKey: {
apiKey: "cUxD***uOUQ=",
},
},
});
// or
const demoContainer = new evedexSdk.DemoContainer({
centrifugeWebSocket: WebSocket,
wallets: {},
apiKeys: {
mainApiKey: {
apiKey: "cUxD***uOUQ=",
},
},
});
const apiKeyAccount = await container.apiKeyAccount('mainApiKey');
const accountInfo = await apiKeyAccount.fetchMe();
console.log('👤 Account info:', accountInfo);
钱包账户
钱包Accout 拥有读取用户账户状态的所有可能性,还包括:
-
命令( 创建、 替换、 取消、 质量取消 ) 用内部签名的方法
-
职务工作方法
-
平衡的工作方法
输入示例
import * as evedexSdk from "@evedex/exchange-bot-sdk";
const container = new evedexSdk.DemoContainer({
centrifugeWebSocket: WebSocket,
wallets: {
baseAccount: {
privateKey: "0x...",
},
},
});
使用一击交易钱包和 api 密钥的钱包账户
钱包账户可以使用一击交易的钱包私钥和API密钥账户进行即时处理
输入示例
import * as evedexSdk from "@evedex/exchange-bot-sdk";
const container = new evedexSdk.DemoContainer({
centrifugeWebSocket: WebSocket,
wallets: {
oneClickTradingAccount: {
privateKey: "0x...",
},
},
apiKeys: {
mainApiKey: {
apiKey: "cUxD***uOUQ=",
},
},
});
// Create api key account
const apiKeyAccount = await container.apiKeyAccount('mainApiKey');
// Receive account info
const accountInfo = await apiKeyAccount.fetchMe();
// Initialize one-click-trading wallet account
const walletAccount = new evedexSdk.WalletAccount({
gateway: apiKey.gateway,
wallet: container.wallet('oneClickTradingAccount'),
exchangeAccount: accountInfo,
});
await walletAccount.createLimitOrderV2({
instrument: 'BTCUSD:DEV',
quantity: 0.001,
side: evedexSdk.Side.Buy,
limitPrice: 107625,
leverage: 1,
postOnly: false,
});
余额
余额实例旨在计算可用的用户余额并处理交换事件.
获取前缀返回缓存状态的方法如下:
- 数量(货币) -
- 获取 postitionList () -
- 获得(文书) -
- 获得命令列表( ) -
- 获取 TpSlList () -
- 获得AvailableBalance() -
- 获得权力(文书) -
获取前缀的方法用于从 REST API 检索数据:
- 获取 TpSlList( query) - 获取 TP/ SL 列表
- 获取Me( ) - 获取用户信息
- 获取 Postitions () - 获取位置
- 获取命令( 命令列表查询) — 获取命令
- 获取 AvailableBalance () — 获取可用余额
- 获取 OpenOrders () - 获取打开的命令
余额 listen 交换活动的方法订阅:更新位置,订单,资金,tpsl.
信号会因处理事件而解析:
- 帐号更新
- 供资最新情况
- 状态更新
- 命令更新
- tpSl 更新
- 命令填报更新
样本
import * as evedexSdk from "@evedex/exchange-bot-sdk";
const container = new evedexSdk.DemoContainer({
centrifugeWebSocket: WebSocket,
wallets: {
baseAccount: {
privateKey: "0x...",
},
},
});
const account = await container.account("baseAccount");
const balance = account.getBalance();
balance.listen();
console.log(balance.getPower("BTCUSDT:DEMO"));
console.log(await balance.fetchOrders({ instrument: "BTCUSDT:DEMO" }));
balance.onAccountUpdate((a) => console.info(a));
实例
Sdk 使用的完整示例 :
import * as evedexSdk from "@evedex/exchange-bot-sdk";
import { AxiosError } from "axios";
import WebSocket from "ws";
const cfg = {
centrifugeWebSocket: WebSocket,
// your wallet private key
wallets: { myWallet: { privateKey: "5b7..." } },
// your api key
apiKeys: { myApiKey: { apiKey: "GNL+Y/VgRj..." } },
};
const container = new evedexSdk.DemoContainer(cfg); // or ProdContainer
const gateway = container.gateway(); // for public api methods
const sampleMarketData = async () => {
//let's subscribe to the order book update and print 1st value
console.log("Subscribing to order book update");
gateway.onOrderBookUpdate((o) => {
console.log(o);
gateway.unListenOrderBook("BTCUSDT:DEMO");
});
gateway.listenOrderBook("BTCUSDT:DEMO");
//let's subscribe to the order book best update and print 1st value
console.log("Subscribing to order book best update");
gateway.onOrderBookBestUpdate((o) => {
console.log(o);
gateway.unListenOrderBookBest("BTCUSDT:DEMO");
});
const wsTimeout = 2000;
// wsTimeout ms optional arg - by default 1000 ms
gateway.listenOrderBookBest("BTCUSDT:DEMO", wsTimeout);
//let's fetch orderbook directly
console.log(await gateway.fetchMarketDepth({ instrument: "BTCUSDT:DEMO", maxLevel: 10 }));
//let's fetch instruments
console.log(
(await container.gateway().fetchInstrumentsWithMetrics()).find(
(i) => i.name === "BTCUSDT:DEMO",
),
);
console.log(
(await container.gateway().fetchInstruments()).find((i) => i.name === "BTCUSDT:DEMO"),
);
//lets fetch coins
console.log((await gateway.fetchCoins()).find((c: any) => c.name === "BTC"));
console.log(await gateway.fetchTrades({ instrument: "BTCUSDT:DEMO" }));
};
const sampleAccountData = async (account: evedexSdk.WalletAccount | evedexSdk.ApiKeyAccount) => {
//show account info
console.log(await account.fetchMe());
const accountState = account.getBalance(); // for account ws callbacks and state
// let's subscribe to account state metrics
await accountState.listen(); //await is important here as it will wait till cache is populated
console.log("Account metrics subscription done, getting state now:");
// log current state from cache
console.log(accountState.getOrderList().filter((o) => o.status === evedexSdk.OrderStatus.New));
console.log(accountState.getFundingQuantity(evedexSdk.CollateralCurrency.USDT));
console.log(accountState.getAvailableBalance());
console.log(accountState.getPositionList());
console.log(accountState.getTpSlList());
console.log(accountState.getPower("BTCUSDT:DEMO"));
//also we can fetch the same data from gateway directly
console.log(await account.fetchOrders({ instrument: "BTCUSDT:DEMO" }));
console.log(await account.fetchPositions());
console.log(await account.fetchAvailableBalance());
console.log(await account.fetchTpSlList({ instrument: "BTCUSDT:DEMO" }));
//now let's attach callbacks to account updates to print new values
console.log("Subscribing to account updates");
accountState.onAccountUpdate((a) => console.info(a));
accountState.onFundingUpdate((f) => console.info(f));
accountState.onPositionUpdate((p) => console.info(p));
accountState.onOrderUpdate((o) => console.info(o));
accountState.onTpSlUpdate((t) => console.info(t));
};
const sampleOrders = async (account: evedexSdk.WalletAccount) => {
// //this is how leverage is managed
await account.updatePosition({ instrument: "BTCUSDT:DEMO", leverage: 20 });
console.log("Placing limit order");
const md = await gateway.fetchMarketDepth({ instrument: "BTCUSDT:DEMO", maxLevel: 1 });
const limitOrder = {
instrument: "BTCUSDT:DEMO",
side: evedexSdk.Side.Buy,
quantity: 0.001,
limitPrice: md.bids[0].price - 500,
leverage: 20,
};
const order = await account.createLimitOrderV2(limitOrder);
console.info(`Order created: ${order.id}`);
console.log("Cancelling limit order...");
await account.cancelOrder({ orderId: order.id });
try {
//both queries will fail with 400 as order is already cancelled
await account.massCancelUserOrders({ instrument: "BTCUSDT:DEMO" });
await account.massCancelUserOrdersById({ orderIds: [order.id] });
} catch (e: any) {
if (e instanceof AxiosError) console.log(e.response?.data.error);
}
};
const main = async () => {
const account = await container.account("myWallet"); // for account methods
const apiKeyAccount = await container.apiKeyAccount("myApiKey"); // for readonly account methods via api key
console.log("Init done");
await sampleMarketData();
await sampleAccountData(apiKeyAccount); // or apiKeyAccount
await sampleOrders(account); //order placements only for wallet account
console.log("Done");
};
main().catch((e) => console.error(e));
如何在开发环境中测试USDT
为了方便,有一个测试水龙头 立即将1000美元 存入你的智能账户 开发环境.
- 第一次运行在您注册时自动发生 https://exchange.evedex.com (中文(简体) )
- 之后,您可以偶尔使用交易所屏幕下方右侧的按钮"Request Demo Funds"请求测试资金.
方法树
集装箱
constructor(config: ContainerConfig)——集装箱实例初始化.
输入容器使用实例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
wallet(walletName: string)返回钱包类实例.
钱包方法使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const wallet = devContainer.wallet("myWallet");
钱包类提供了使用醚类库与Ethereum钱包交互的方法.
方法解释:
getChainId(): 返回 Ethereum 网络的链式ID, 要么从提供的选项返回 。 链字符串或查询签名人的提供者.getAddress(): 返回与钱包相关的Ethereum地址.solidityPackedKeccak256(types, values): 计算所提供的类型和值的固态包装克恰克-256散列.getBytes(value): 返回所提供值字符串的字节表示.serializeSignature(signature):将提供的签名字符串序列化为适合传输的格式.signMessage(message): 使用钱包的私密密钥签名提供的消息字符串或 Uint8Array .signTypedData(domain, types, value):根据EIP-712打出的数据规格,使用钱包的私人密钥,在所提供的域名,类型和值上签名.
- 帐号( wallet Name: string) — 返回 钱包账户实例。 。 。 .
账户方法使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
- apiKey( apiKeyName: string) – 通过配置名返回用户 api 密钥 .
apiKey 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const userApiKey = devContainer.apiKey("mainApiKey"); // returns 'your-api-key'
- apiKey Account( apiKey) —— 返回 ApiKey 账户实例。 。 。 .
apiKeycount 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
- 网关() — 返回网关实例( 已过期, 不建议使用) 。 回返a
Gateway类案例. - 关闭WsConnection()——关闭离心机网锁连接.
密钥账户
ApiKeyAccount类代表了API密钥账户,该密钥账户提供了与交换网关互动的方法.
要初始化 ApiKeyAccount 您需要将您的 API 密钥传递到容器配置 .
分类方法
计数器 :
gateway: 返回网关实例(已过期,不建议使用).authGateway: 返回认证网关(已过期,不建议使用).exchangeGateway: 返回交换网关(过期,不建议使用).wsGateway: 返回WebSocket网关(过期,不建议使用).exchangeAccount: 返回与 API 密钥相关的交换账户.
交换账户方法使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const exchangeAccountData = apiKeyAccount.exchangeAccount();
交换账户结果实例
{
"id": "8f0f1f6e-4a6d-4f6a-8e6f-0f6a4f6a8ev",
"authId": "b6b3a4c6-5a6d-43e6-b6b3-a4c65a6d43e6",
"exchangeId": 1,
"name": "John Doe",
"email": "[email protected]",
"wallet": "0x1234567890abcdef",
"social": [
{
"type": "twitter",
"value": "@johndoe"
},
{
"type": "github",
"value": "johndoe"
}
],
"avatar": "https://example.com/avatar.jpg",
"level": 2,
"locale": "en-US",
"dateTimeFormat": "MM/DD/YYYY",
"favoriteInstruments": ["BTCUSDT"],
"marginCall": false,
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z"
}
session: 返回与 API 密钥账户相关的会话。 如果 api ey 账户返回 api 密钥 .
方法:
-
getBalance: 为 API 密钥账户返回一个新的平衡类实例. -
fetchTpSlList: 获取基于所提供的查询参数的Take Profit and Stop Loss(TpSl)命令列表.
获取 TpSlList 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container, TpSlType } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const query = {
instrument: ["BTCUSDT", "ETHUSDT"],
status: ["active", "pending"],
type: TpSlType.TakeProfit,
offset: 0,
limit: 10,
};
const tpslList = await apiKeyAccount.fetchTpSlList(query);
tpsl 列表结果示例
{
"list": [
{
"id": "f47ac10b-58cc-4752-9f6a-8e3f9e7a6c11",
"instrument": "BTCUSDT",
"type": "take-profit",
"side": "BUY",
"quantity": "0.1",
"price": "50000.00",
"status": "active",
"triggerOrder": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b9d4c22",
"triggeredQuantity": "0.05",
"cancelledReason": "",
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z"
}
]
}
fetchMe: 获取当前用户信息.
获取 Me 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const userData = await apiKeyAccount.fetchMe();
获取我的结果示例
{
"id": "8f0f1f6e-4a6d-4f6a-8e6f-0f6a4f6a8ev",
"authId": "b6b3a4c6-5a6d-43e6-b6b3-a4c65a6d43e6",
"exchangeId": 1,
"name": "John Doe",
"email": "[email protected]",
"wallet": "0x1234567890abcdef",
"social": [
{
"type": "twitter",
"value": "@johndoe"
},
{
"type": "github",
"value": "johndoe"
}
],
"avatar": "https://example.com/avatar.jpg",
"level": 2,
"locale": "en-US",
"dateTimeFormat": "MM/DD/YYYY",
"favoriteInstruments": ["BTCUSDT"],
"marginCall": false,
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z"
}
fetchPositions:获取当前用户位置列表.
获取 Postitions 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const positions = await apiKeyAccount.fetchPositions();
获取结果示例
[
{
"id": "1-BTCUSDT",
"user": "1",
"instrument": "BTCUSDT",
"side": "buy",
"quantity": 0.1,
"avgPrice": 50000.0,
"fundingRate": 0.01,
"leverage": 10,
"maintenanceMargin": 0.05,
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"unRealizedPnL": 1000.0,
"adlLevel": 2
}
]
fetchOrders:根据提供的查询参数获取用户命令列表.
获取命令方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
Side,
OrderType,
OrderGroup,
OrderStatus,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const orderListQueryParams = {
instrument: "BTCUSDT",
status: [OrderStatus.New, OrderStatus.PartiallyFilled],
group: [OrderGroup.Manually, OrderGroup.TpSl],
type: [OrderType.Limit, OrderType.Market],
side: Side.Buy,
version: 2,
limit: 10,
offset: 0,
};
const orderList = await apiKeyAccount.fetchOrders(orderListQueryParams);
获取命令结果示例
{
"list": [
{
"id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
"user": "67890",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "LIMIT",
"quantity": 0.1,
"cashQuantity": 5000.0,
"limitPrice": 50000.0,
"stopPrice": null,
"status": "PARTIALLY_FILLED",
"unFilledQuantity": 0.05,
"filledAvgPrice": 50050.0,
"realizedPnL": 100.0,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"triggeredAt": null,
"group": "manually"
}
],
"count": 1
}
fetchAvailableBalance:获取当前用户可用的余额.
获取 AvailableBalance 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
Side,
OrderType,
OrderGroup,
OrderStatus,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const availableBalance = await apiKeyAccount.fetchAvailableBalance();
获取 AvailableBalance 结果示例
{
"funding": {
"currency": "USDT",
"balance": "10000.00"
},
"positions": [
{
"instrument": "BTCUSDT",
"side": "buy",
"volume": "0.1",
"initialMargin": "500.00"
},
{
"instrument": "ETHUSDT",
"side": "sell",
"volume": "1.0",
"initialMargin": "1000.00"
}
],
"openOrders": [
{
"instrument": "BTCUSDT",
"side": "buy",
"unFilledVolume": "0.05",
"unFilledInitialMargin": "250.00"
},
{
"instrument": "ETHUSDT",
"side": "sell",
"unFilledVolume": "0.5",
"unFilledInitialMargin": "500.00"
}
],
"availableBalance": "5000.00"
}
fetchPower:获取用户电源以出售并购买侧.
获取Power 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
Side,
OrderType,
OrderGroup,
OrderStatus,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const powerQueryParams = {
instrument: "BTCUSDT",
};
const power = await apiKeyAccount.fetchPower(powerQueryParams);
获取Power 结果示例
{
"buy": {
"power": 1000
},
"sell": {
"power": 2000
}
}
fetchOpenOrders:为当前用户获取打开命令列表.
获取 OpenOrders 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
Side,
OrderType,
OrderGroup,
OrderStatus,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const apiKeyAccount = devContainer.apiKeyAccount("mainApiKey");
const openOrders = await apiKeyAccount.fetchOpenOrders();
获取 OpenOrders 结果示例
[
{
"id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
"user": "67890",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "LIMIT",
"status": "PARTIALLY_FILLED",
"quantity": 0.1,
"limitPrice": 50000.0,
"unFilledQuantity": 0.05,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"updatedAt": "2022-01-15T14:30:00.000Z",
"cashQuantity": 5000.0
}
]
钱包账户( 扩展会话账户)
此类扩展了会话账户类, 它扩展了 ApiKey Account .
WalletAccount 包含 ApiKeyAccount • 提供执行各种贸易行动的方法和方法.
要初始化 WalletAccount 您需要将您的钱包私钥传递到容器配置.
分类方法
createWithdraw(withdraw)——用于创建已签名的退出请求并发送到交换网关的方法.
创建Wordraw 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container, type TradingBalanceWithdraw } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const withdrawQueryParams: TradingBalanceWithdraw = {
recipient: "0x1234567890abcdef",
amount: 100.5,
};
const withdrawResult = await walletAccount.createWithdraw(withdrawQueryParams);
创建( W)
{
"id": "123e4567-e89b-12d3-a456-426655440000",
"user": "f47ac10b-58cc-4372-a567-0e02bdc8d47d",
"type": "withdraw",
"coin": "USDT",
"amount": 100.5,
"fee": 0.1,
"status": "pending",
"createdAt": "2023-02-20T14:30:00.000Z",
"updatedAt": "2023-02-20T14:30:00.000Z"
}
createClosePositionOrderV2(order)– 用于创建已签名的近位置命令并发送到交换网关的方法
创建 ClosePostion OrderV2 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container, type PositionCloseOrderPayload } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const positionCloseOrderPayload: PositionCloseOrderPayload = {
instrument: "BTCUSDT",
leverage: 10,
quantity: 0.1,
};
const closePositionResult = await walletAccount.createClosePositionOrderV2(positionCloseOrderPayload);
创建 ClosePostion OrderV2 结果示例
{
"id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
"user": "67890",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "MARKET",
"quantity": 0.1,
"cashQuantity": 5000.0,
"limitPrice": null,
"stopPrice": null,
"status": "FILLED",
"unFilledQuantity": 0,
"filledAvgPrice": 50050.0,
"realizedPnL": 100.0,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"triggeredAt": null,
"group": "manually"
}
updatePosition(query)——用于更新开放位置杠杆的方法.
创建Wordraw 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container, type PositionUpdateQuery } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const positionUpdatePayload: PositionUpdateQuery = {
instrument: "BTCUSDT",
leverage: 20,
};
const updatePositionResult = await walletAccount.updatePosition(positionCloseOrderPayload);
更新结果实例
{
"instrument": "BTCUSDT",
"side": "BUY",
"quantity": 10,
"avgPrice": 100.0,
"leverage": 20,
"maintenanceMargin": 1000.0,
}
createLimitOrderV2(order)——用于创建已签名的限制令并发送到交换网关的方法.
创建 LimitOrderV2( order) 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type LimitOrderPayload,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const limitOrderPayload: LimitOrderPayload = {
instrument: "BTCUSDT",
side: Side.Buy,
leverage: 10,
quantity: 0.01,
limitPrice: 100000,
tpsl: [
{
type: TpSlType.TakeProfit,
side: Side.Buy,
quantity: 0.01,
price: 120000,
},
{
type: TpSlType.StopLoss,
side: Side.Buy,
quantity: 0.01,
price: 80000,
},
],
// Optional flag to use for POST only limit orders
postOnly: true
};
const createLimitOrderResult = await walletAccount.createLimitOrderV2(limitOrderPayload);
创建LimitV2 顺序结果示例
{
"id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
"user": "67890",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "LIMIT",
"quantity": 0.01,
"cashQuantity": 0,
"limitPrice": 100000,
"stopPrice": null,
"status": "NEW",
"unFilledQuantity": 0.01,
"filledAvgPrice": 0,
"realizedPnL": 0,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"triggeredAt": null,
"group": "manually",
"exchangeRequestId": "1"
}
batchCreateLimitOrderV2(orders)——用于创建已签名的限制令并发送到交换网关的方法.
批量创建LimitOrderV2(顺序)方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type LimitOrderPayload,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const instrument = "BTCUSDT";
const limitOrderPayloads: LimitOrderPayload[] = [
{
instrument,
side: Side.Buy,
leverage: 10,
quantity: 0.01,
limitPrice: 100000,
postOnly: true
},
{
instrument,
side: Side.Buy,
leverage: 10,
quantity: 0.02,
limitPrice: 101000,
},
];
const batchCreateLimitOrderResult = await walletAccount.batchCreateLimitOrderV2(
instrument,
limitOrderPayloads,
);
批量创建LimitOrderV2 结果示例
[
{
"orderId": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e7",
"success": true
},
{
"orderId": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e8",
"success": false,
"failReason": "Insufficient funds"
}
]
replaceLimitOrder(order)——用于更新(替换)开放限制令的方法.
替换 LimitOrder( 顺序) 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type ReplaceLimitOrder,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const replaceLimitOrderPayload: ReplaceLimitOrder = {
orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
quantity: 0.02,
limitPrice: 105000,
// Optional flag to use for POST only limit orders
postOnly: true
};
const replaceLimitOrderResult = await walletAccount.replaceLimitOrder(replaceLimitOrderPayload);
替换 LimitOrder 结果示例
{
"id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
"user": "67890",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "LIMIT",
"quantity": 0.02,
"cashQuantity": 0,
"limitPrice": 105000,
"stopPrice": null,
"status": "REPLACED",
"unFilledQuantity": 0.02,
"filledAvgPrice": 0,
"realizedPnL": 0,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"triggeredAt": null,
"group": "manually",
"exchangeRequestId": "1"
}
-
batchReplaceLimitOrder(orderList)——用于批量替换开放限制令的方法. 已去已去已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已取已. 代之以批量重置仪器命令方法 -
batchReplaceInstrumentLimitOrder(instrument, orderList)——用于批量替换开放限制令的方法.
重置仪器Limit Order( 仪器, 订单) 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type ReplaceLimitOrder,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const replaceLimitOrderPayloads: ReplaceLimitOrder[] = [
{
orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
quantity: 0.02,
limitPrice: 105000,
// Optional flag to use for POST only limit orders
postOnly: true
},
{
orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1n",
quantity: 0.01,
limitPrice: 95000,
},
];
const batchReplaceInstrumentLimitOrderResult = await walletAccount.batchReplaceInstrumentLimitOrder(
"BTCUSDT",
replaceLimitOrderPayloads,
);
更换仪器命令结果实例
{}
createMarketOrderV2(order)——用于创建签字市场秩序的方法.
创建 MarketOrderV2( 顺序) 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type MarketOrderPayload,
TimeInForce,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const marketOrderPayload: MarketOrderPayload = {
instrument: "BTCUSDT",
side: Side.Buy,
leverage: 10,
timeInForce: TimeInForce.IOC,
cashQuantity: 1000,
tpsl: [
{
type: TpSlType.TakeProfit,
side: Side.Buy,
quantity: 0.01,
price: 120000,
},
{
type: TpSlType.StopLoss,
side: Side.Buy,
quantity: 0.01,
price: 80000,
},
],
};
const createMarketOrderResult = await walletAccount.createMarketOrderV2(marketOrderPayload);
创建 MarketOrderV2 结果示例
{
"id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
"user": "67890",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "MARKET",
"quantity": 0,
"cashQuantity": 1000,
"limitPrice": 0,
"stopPrice": null,
"status": "NEW",
"unFilledQuantity": 0.01,
"filledAvgPrice": 0,
"realizedPnL": 0,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"triggeredAt": null,
"group": "manually",
"exchangeRequestId": "1"
}
createStopLimitOrderV2(order)——用于创建止止限令的方法.
创建StopLimitOrderV2(order)方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type StopLimitOrderPayload,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const limitOrderPayload: StopLimitOrderPayload = {
instrument: "BTCUSDT",
side: Side.Buy,
leverage: 10,
quantity: 0.01,
limitPrice: 100000,
stopPrice: 100500,
tpsl: [
{
type: TpSlType.TakeProfit,
side: Side.Buy,
quantity: 0.01,
price: 120000,
},
{
type: TpSlType.StopLoss,
side: Side.Buy,
quantity: 0.01,
price: 80000,
},
],
};
const createStopLimitOrderResult = await walletAccount.createStopLimitOrderV2(limitOrderPayload);
创建StopLimitOrderV2 结果示例
{
"id": "a6f1c4e5-3b7d-42e6-b6b3-a4c65a6d43e6",
"user": "67890",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "STOP_LIMIT",
"quantity": 0.01,
"cashQuantity": 0,
"limitPrice": 100000,
"stopPrice": 100500,
"status": "NEW",
"unFilledQuantity": 0.01,
"filledAvgPrice": 0,
"realizedPnL": 0,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"triggeredAt": null,
"group": "manually",
"exchangeRequestId": "1"
}
replaceStopLimitOrder(order)——用于替换停放限制令的方法.
替换 StopLimit Order( 顺序) 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type ReplaceStopLimitOrder,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const replaceLimitOrderPayload: ReplaceStopLimitOrder = {
orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
quantity: 0.02,
limitPrice: 105000,
stopPrice: 105500,
};
const replaceLimitOrderResult = await walletAccount.replaceStopLimitOrder(replaceLimitOrderPayload);
替换“停止命令”结果示例
{
"id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
"user": "67890",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "LIMIT",
"quantity": 0.02,
"cashQuantity": 0,
"limitPrice": 105000,
"stopPrice": 105500,
"status": "REPLACED",
"unFilledQuantity": 0.02,
"filledAvgPrice": 0,
"realizedPnL": 0,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"triggeredAt": null,
"group": "manually",
"exchangeRequestId": "1"
}
cancelOrder(query)——取消订单的方法.
取消命令( query) 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container, type OrderCancelQuery } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const cancelOrderPayload: OrderCancelQuery = {
orderId: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
};
const cancelOrderResult = await walletAccount.cancelOrder(cancelOrderPayload);
取消命令结果示例
{}
massCancelUserOrdersById(query)——由ids取消用户订单的方法.
质量终止用户命令ById( 清) 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container, type OrderMassCancelByIdQuery } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const massCancelUserOrdersByIdParams: OrderMassCancelByIdQuery = {
orderIds: ["4f6c21a4-3c4f-4f2e-8f6d-5b4c7a9d2e1f", "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f"],
};
const massCancelUserOrdersResult = await walletAccount.massCancelUserOrdersById(
massCancelUserOrdersByIdParams,
);
质量取消用户命令ById 结果实例
{}
massCancelUserOrders(query)——通过仪器取消用户订单的方法.
质量取消用户命令( query) 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container, type OrderMassCancelQuery } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const massCancelUserOrdersParams: OrderMassCancelQuery = {
instrument: "BTCUSDT",
};
const massCancelUserOrdersResult = await walletAccount.massCancelUserOrders(
massCancelUserOrdersParams,
);
质量取消用户命令结果示例
{}
createTpSl(tpsl)——用于创建Take Profit/Stop Loss订单的方法.
创建 TpSl(tpsl) 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type TpSlCreatePayload,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const tpslPayload: TpSlCreatePayload = {
type: TpSlType.TakeProfit,
side: Side.Buy,
quantity: 0.01,
price: 120000,
order: "4f6c21a4-3c4f-4f2e-8f6d-5b4c7a9d2e1f",
instrument: "BTCUSDT",
};
const createTpSlResult = await walletAccount.createTpSl(tpslPayload);
创建 TpSl 结果示例
{
"id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
"instrument": "BTCUSD",
"type": "take-profit",
"side": "BUY",
"quantity": "0.01",
"price": "120000",
"status": "waitOrder",
"triggerOrder": null,
"triggeredQuantity": "0",
"cancelledReason": "",
"createdAt": "2023-02-20T14:30:00.000Z",
"updatedAt": "2023-02-20T14:30:00.000Z"
}
updateTpSl(query)——用于更新Take Profit/Stop Loss订单的方法.
更新 TpSl( query) 方法使用示例
import { WebSocket } from "ws";
import {
Environment,
Container,
type TpSlUpdateQuery,
Side,
TpSlType,
} from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const tpslUpdatePayload: TpSlUpdateQuery = {
type: TpSlType.TakeProfit,
side: Side.Buy,
quantity: 0.01,
price: 121000,
order: "4f6c21a4-3c4f-4f2e-8f6d-5b4c7a9d2e1f",
instrument: "BTCUSDT",
id: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
};
const updateTpSlResult = await walletAccount.updateTpSl(tpslUpdatePayload);
更新 TpSl 结果示例
{
"id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
"instrument": "BTCUSD",
"type": "take-profit",
"side": "BUY",
"quantity": "0.01",
"price": "121000",
"status": "waitOrder",
"triggerOrder": null,
"triggeredQuantity": "0",
"cancelledReason": "",
"createdAt": "2023-02-20T14:30:00.000Z",
"updatedAt": "2023-02-20T14:30:00.000Z"
}
cancelTpSl(query)- 取消利润/停止损失订单的方法.
取消 TpSl( query) 方法使用示例
import { WebSocket } from "ws";
import { Environment, Container, type TpSlCancelQuery } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = devContainer.account("myWallet");
const tpslCancelPayload: TpSlCancelQuery = {
instrument: "BTCUSDT",
id: "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
};
const cancelTpSlResult = await walletAccount.cancelTpSl(tpslCancelPayload);
取消 TpSl 结果示例
{
"id": "a8f5e2b4-4c9a-4e3a-8f6d-5b4c7a9d2e1f",
"instrument": "BTCUSD",
"type": "take-profit",
"side": "BUY",
"quantity": "0.01",
"price": "121000",
"status": "cancelled",
"triggerOrder": null,
"triggeredQuantity": "0",
"cancelledReason": "",
"createdAt": "2023-02-20T14:30:00.000Z",
"updatedAt": "2023-02-20T14:30:00.000Z"
}
余额
这个班级用来获取实时可用的平衡和动力数据并处理交换事件.
constructor(options: BalanceOptions)——用于创建Balance举个例子.
Init 平衡使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
// using wallet account
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
// or using api key account
const apiKeyAccount = await devContainer.apiKeyAccount("mainApiKey");
const balanceFromApiKeyAccount = apiKeyAccount.getBalance();
listen()- 用于订阅交换事件和填充平衡状态的方法。 返回平衡类实例
声音( ) 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
unListen()- 用于不订阅交换事件并重置平衡状态的方法。 返回平衡类实例
未倾听( ) 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
await balance.unListen();
getFundingQuantity(currency)——用于获取余额当前资金的方法.
获得资金数量()使用实例
import { WebSocket } from "ws";
import { Environment, Container, CollateralCurrency } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
const funding = balance.getFundingQuantity(CollateralCurrency.USDT); // Example: returns "1000"
getWithdrawTransferPendingQuantity()退还待收回的转移款总额的方法.
获取Wordraw TransferPending 数量
import { WebSocket } from "ws";
import { Environment, Container, CollateralCurrency } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
const withdrawPendingTrasferAmount = balance.getWithdrawTransferPendingQuantity(
CollateralCurrency.USDT,
); // Example: returns Big instance
getPositionList()返回平衡的所有位置的方法.
获取 PositionList () 使用示例
import { WebSocket } from "ws";
import { Environment, Container, CollateralCurrency } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
const positions = balance.getPositionList();
获取选项 列表结果示例
[
{
"id": "1-BTCUSDT",
"user": "johnDoe",
"instrument": "BTCUSDT",
"side": "BUY",
"quantity": 0.1,
"avgPrice": 50000,
"fundingRate": 0.01,
"leverage": 5,
"maintenanceMargin": 100,
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-01T12:00:00.000Z"
}
]
getPosition(instrument)——按仪器返回用户位置的方法.
获取设备( 仪器) 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
const position = balance.getPosition("BTCUSDT");
获取结果示例
{
"id": "1-BTCUSDT",
"user": "johnDoe",
"instrument": "BTCUSDT",
"side": "BUY",
"quantity": 0.1,
"avgPrice": 50000,
"fundingRate": 0.01,
"leverage": 5,
"maintenanceMargin": 100,
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-01T12:00:00.000Z"
}
getOrderList()——返回现有订单列表的方法.
获取命令列表 () 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
const orderList = balance.getOrderList();
获得命令列表 () 结果示例
[
{
"id": "9fcbf9d3-4a3d-4a6b-8a6f-5f4c9d3a1b2c",
"user": "1",
"instrument": "BTCUSDT",
"side": "BUY",
"type": "LIMIT",
"status": "NEW",
"quantity": 0.1,
"limitPrice": 50000,
"unFilledQuantity": 0.1,
"fee": [
{
"coin": "USDT",
"quantity": 10.0
}
],
"updatedAt": "2022-01-01T12:00:00.000Z",
"cashQuantity": 0
}
]
getTpSlList()——返回已有的Take Profit/Stop Loss订单的方法.
获取 TpSlList () 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
const tpSlList = balance.getTpSlList();
获得 TpSlList () 结果示例
[
{
"id": "f47ac10b-58cc-4752-9f6a-8e3f9e7a6c11",
"instrument": "BTCUSDT",
"type": "take-profit",
"side": "BUY",
"quantity": "0.1",
"price": "50000.00",
"status": "active",
"triggerOrder": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b9d4c22",
"triggeredQuantity": "0.05",
"cancelledReason": "",
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z"
}
]
getAvailableBalance()——返回账户现有余额、现有位置和未结订单的方法.
获得 AvailableBalance () 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
const availableBalance = balance.getAvailableBalance();
获得AvailableBalance () 结果实例
{
"funding": {
"currency": "USDT",
"balance": "10000.00"
},
"positions": [
{
"instrument": "BTCUSDT",
"side": "buy",
"volume": "0.1",
"initialMargin": "500.00"
},
{
"instrument": "ETHUSDT",
"side": "sell",
"volume": "1.0",
"initialMargin": "1000.00"
}
],
"openOrders": [
{
"instrument": "BTCUSDT",
"side": "buy",
"unFilledVolume": "0.05",
"unFilledInitialMargin": "250.00"
},
{
"instrument": "ETHUSDT",
"side": "sell",
"unFilledVolume": "0.5",
"unFilledInitialMargin": "500.00"
}
],
"availableBalance": "5000.00"
}
getPower(instrument)——返回当前买卖力的方法(最大可用订单价值).
获取Power( 仪器) 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
const power = balance.getPower("BTCUSDT");
获取Power( 工具) 结果示例
{
"buy": 1000,
"sell": 1500
}
信号 :
平衡类实例可以处理由使用信号被websocket取回的交换产生的实时事件.
onAccountUpdate()- 更新用户数据的信号
账户更新( ) 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
balance.onAccountUpdate((accountState) => console.log(accountState));
() 事件有效载荷实例
{
"id": "8f0f1f6e-4a6d-4f6a-8e6f-0f6a4f6a8ev",
"authId": "b6b3a4c6-5a6d-43e6-b6b3-a4c65a6d43e6",
"exchangeId": 1,
"name": "John Doe",
"email": "[email protected]",
"wallet": "0x1234567890abcdef",
"social": [
{
"type": "twitter",
"value": "@johndoe"
},
{
"type": "github",
"value": "johndoe"
}
],
"avatar": "https://example.com/avatar.jpg",
"level": 2,
"locale": "en-US",
"dateTimeFormat": "MM/DD/YYYY",
"favoriteInstruments": ["BTCUSDT"],
"marginCall": false,
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z"
}
onFundingUpdate()- 更新用户数据的信号
() 使用实例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
balance.onFundingUpdate((fundingState) => console.log(fundingState));
事件有效载荷实例
{
"coin": "BTC",
"quantity": 0.5,
"updatedAt": "2022-01-01T12:00:00.000Z"
}
onTransferUpdate()——更新用户传输数据的信号
在 TransferUpdate () 使用示例上
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
balance.onTransferUpdate((transferState) => console.log(transferState));
() 事件有效载荷实例
{
"id": "8b6e9f4c-4a3d-4f6b-8a6f-5f4c9d3a1b2c",
"user": "1",
"type": "withdraw",
"coin": "BTC",
"amount": 0.5,
"fee": 0.001,
"status": "pending",
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-01T12:00:00.000Z"
}
onPositionUpdate()- 用户位置数据更新信号
使用实例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.getBalance();
await balance.listen();
balance.onPositionUpdate((positionState) => console.log(positionState));
事件有效载荷实例
{
"id": "1-BTCUSDT",
"user": "1",
"instrument": "BTCUSDT",
"side": "buy",
"quantity": 0.1,
"avgPrice": 50000.0,
"fundingRate": 0.01,
"leverage": 10,
"maintenanceMargin": 0.05,
"createdAt": "2022-01-01T12:00:00.000Z",
"updatedAt": "2022-01-15T14:30:00.000Z",
"unRealizedPnL": 1000.0,
"adlLevel": 2
}
onOrderUpdate()——更新用户订单数据信号
命令更新( ) 使用示例
import { WebSocket } from "ws";
import { Environment, Container } from "@evedex/exchange-bot-sdk";
const config = {
environment: Environment.DEV,
centrifugeWebSocket: WebSocket,
wallets: {
myWallet: {
privateKey: "your-private-key",
},
},
apiKeys: {
mainApiKey: {
apiKey: "your-api-key",
},
},
};
const devContainer = new Container(config);
const walletAccount = await devContainer.account("myWallet");
const balance = walletAccount.g