incent-api-sdk
v1.0.41
Published
incent api sdk tools
Downloads
15
Readme
incent-api-sdk
简介
根据平台 websocket封装的sdk工具 可实现WS接口的异步编程 以及主动监听推送事件
使用
1.安装依赖
npm i incent-api-sdk --registry http://3.1.56.48:4873
2.初始化SDK
import IncentApi from 'incent-api-sdk'
IncentApi.init({
quotation_socket_url: '<websocket-url>',
trade_socket_url: '<websocket-url>',
})
const Quotation = IncentApi.Quotation()
Quotation.on('quotation', (e) => {
console.log(e)
})
;(async function () {
await Quotation.init()
// query commodity
const commodity = await Quotation.queryCommodity()
// subscribe commodity
commodity.forEach(item => {
Quotation.subscribeCommodity(item.ExchangeNo, item.CommodityNo, item.MainContract)
})
})()
示例
1.克隆项目 安装依赖
git clone http://3.1.56.48:8080/ifp-web-development/incent-api-sdk.git
cd incent-api-sdk
npm i
2.启动Demo Vue or React
npm run vue
or
npm run react
3.打开浏览器访问 vue demo http://localhost:9000 or react demo http://localhost:9001
API
常量
const Constant = {
ORDER: {
DIRECTION: { BUY: 0, SELL: 1 },
PRICE_TYPE: { LIMIT_PRICE: 0, MARKET_PRICE: 1 },
},
STOP_LOSS: {
STOP_LOSS_TYPE: { SL: 0, TP: 1, FLOAT_SL: 2 },
ORDER_TYPE: { MARKET_PRICE: 1, CONSIDERATION: 2 },
},
CONDITION: {
CONDITION_TYPE: { PRICE: 0, TIME: 1, AB: 2 },
COMPARE_TYPE: { GT: 0, LT: 1, GTE: 2, LTE: 2 },
ORDER_TYPE: { MARKET_PRICE: 1, CONSIDERATION: 2 },
ADDITION_FLAG: { YES: true, No: false },
DIRECTION: { BUY: 0, SELL: 1 },
STOP_LOSS_TYPE: { SL: 0, TP: 1, SL_TP: 2, FLOAT_SL: 3, NO: 4 },
}
}
枚举
const Eumn = {
DIRECTION: { 0: '多', 1: '空' },
ORDER_TYPE: { 0: '订单已提交', 1: '排队中', 2: '部分成交', 3: '完全成交', 4: '已撤单', 5: '下单失败', 6: '未知' },
CONDITIONS_STATUS: { 0: '运行中', 1: '暂停', 2: '已触发', 3: '已取消', 4: '插入失败', 5: '触发失败' },
CONDITIONS_TYPE: { 0: '价格条件', 1: '时间条件', 2: 'AB单' },
STOP_LOSS_STATUS: { 0: '运行中', 1: '暂停', 2: '已触发', 3: '已取消', 4: '插入失败', 5: '触发失败' },
STOP_LOSS_TYPE: { 0: '限价止损', 1: '限价止盈', 2: '动态止损' }
}
Common
methods
| name | description | | ------ | ------ | | void on(listener_tag[, commodityNo], callback) | 事件订阅 | | void off(listener_tag, callback) | 取消事件订阅 | | void close() | 关闭连接 |
listener
| name | description | | ------ | ------ | | open | 建立连接通知 | | error | 连接出错通知 | | message | 响应套接字通知 | | close | 连接关闭通知 | | disconnect | 断线通知(非主动关闭) |
Quotation
methods
| name | description | | ------ | ------ | | Promise init() | 连接行情 | | Promise login() | 行情登录 | | Promise queryCommodity() | 查询全部合约 | | Promise subscribeCommodity(exchangeNo, commodityNo, contractNo) | 关注合约 | | Promise getCommodityHistory(exchangeNo, commodityNo, contractNo, beginTime, endTime, type, count) | 查询该合约历史记录 |
listener
| name | description | | ------ | ------ | | quotation | 行情套接字通知 | | quotation[, commodityNo] | 所选合约行情套接字通知 |
Trade
methods
| name | description | | ------ | ------ | | Promise init() | 连接行情 | | Promise login(clientNo, password[, isMock = 1][, source = 'N_WEB'][, version = '3.3']) | 交易账户登录 | | Promise logout(clientNo) | 交易账户登出 | | Promise queryHoldRecord() | 查询持仓合计 | | Promise queryOrderRecord() | 查询订单信息 | | Promise queryTradeRecord() | 查询成交记录 | | Promise queryAccountBalance() | 查询账户信息 | | Promise queryStopLossRecord() | 查询止盈止损单 | | Promise queryHistoryTradeRecord(beginTime, endTime) | 查询历史成交记录 | | Promise insertOrder( exchangeNo, commodityNo, contractNo, count, direction, CONSTANT.ORDER.DIRECTION, CONSTANT.ORDER.PRICE_TYPE [,limitPrice] ) | 查询条件单 | | Promise cancelOrder(orderId) | 取消订单 | | Promise modifyOrder(orderId, count, price) | 修改订单 | | Promise insertStopLoss( exchangeNo, commodityNo, contractNo, count, CONSTANT.STOP_LOSS.STOP_LOSS_TYPE, stopLossPrice, stopLossDiff, avgPrice, direction, CONSTANT.STOP_LOSS.ORDER_TYPE ) | 添加止盈止损单 | | Promise modifyStopLoss( stopLossNo, count, CONSTANT.STOP_LOSS.STOP_LOSS_TYPE, CONSTANT.STOP_LOSS.ORDER_TYPE, stopLossPrice, stopLossDiff) | 修改止盈止损单 | | Promise deleteStopLoss(stopLossNo) | 删除止盈止损单 | | Promise pauseStopLoss(stopLossNo) | 暂停止盈止损单 | | Promise startStopLoss(stopLossNo) | 激活止盈止损单 | | Promise insertCondition( exchangeNo, commodityNo, contractNo, count, CONSTANT.CONDITION.CONDITION_TYPE, CONSTANT.CONDITION.COMPARE_TYPE, priceTriggerPoint, timeTriggerPoint, CONSTANT.CONDITION.ORDER_TYPE, CONSTANT.CONDITION.DIRECTION, CONSTANT.CONDITION.ADDITION_FLAG, CONSTANT.CONDITION.COMPARE_TYPE, additionPrice) | 新增条件单 | | Promise modifyCondition( conditionNo, count, CONSTANT.CONDITION.CONDITION_TYPE, CONSTANT.CONDITION.COMPARE_TYPE, priceTriggerPoint, timeTriggerPoint, CONSTANT.CONDITION.ORDER_TYPE, CONSTANT.CONDITION.DIRECTION, CONSTANT.CONDITION.ADDITION_FLAG, CONSTANT.CONDITION.COMPARE_TYPE, additionPrice) | 修改条件单 | | Promise deleteCondition(conditionNo) | 删除条件单 | | Promise pauseCondition(conditionNo) | 暂停条件单 | | Promise startCondition(conditionNo) | 激活条件单 |
listener
| name | description | | ------ | ------ | | holds-change | 持仓变化套接字通知 | | account-change | 资金变化套接字通知 | | order-change | 订单变化通知 | | trade-change | 交易记录变化通知 | | stop-loss-change | 止盈止损单变化通知 | | condition-change | 条件单变化通知 |