芒果客户端
一个与芒果程序接触的客户端
版本数
2.0.0 释放了June 9, 2021
- 支持 Mango 的 5 个符号版本
- 页:1
0.1.19 联合国
- 支持芒果的3个符号版本
- https://usdt.mango. 市场
测试
所有测试都要在devnet上进行 全面测试运行,需要很长时间才能进行,有时由于连通性问题或其他工作人而失败 脱网因此,建议进行这样的孤立试验:
yarn test -g "<test description>"
例如,以下测试:
it('should log lotSizes', async() => {...});
就会像这样跑
yarn test -g "should log lotSizes"
您还可以指定一个测试组, 可以运行多个测试, 例如下面的组 -
describe('log stuff', async() => {...});
可以这样运行..
yarn test -g "should log lotSizes"
如果你真的想运行 全套测试只是运行 -
yarn test
所需资源
诸如伐木和订单匹配等一些测试将没有任何要求进行,但所有清算测试都期望有一个 AGGREGATOR_PATH 变量集 .env 数据。 。 。 .
这个 AGGREGATOR_PATH 变量应该是 solana-flux-聚合剂 可获取的路径 这里。 。 。 .
示例 .env 数据 文件 -
AGGREGATOR_PATH=~/solana-flux-aggregator
测试清算
套房中最能动的测试之一是清算测试,这可以在 stress testing partial liquidation 组只需在您的 IDE 中搜索它.
所有测试都有变异 stressTestLiquidation 函数.
这个函数大致由 -
- 创建和资金a 丽琪 待清算的账户
- 将预告价格改为订单价格 丽琪 是关于提交
- 代表缔约方提交长或短命令 丽琪
- 将甲骨文价格改为强制 丽琪低于维护门槛值的附带比率
- 创建和资金a 里科尔 将进行清算的账户
- 里科尔 进行清算
以下列出可以产生许多不同清算假设的参数:
mangoGroupSpotMarket: Market,
orderQuantity?: number, // Default = 1
customLiqeeOwner?: Account, // Default = null
shouldPartialLiquidate?: boolean, // Default = false
shouldCreateNewLiqor?: boolean, // Default = true
shouldFinishLiquidationInTest?: boolean, // Default = true
customOrderPrice?: number, // Default = 0
customOrderSize?: number, // Default = 0
leverageCoefficient?: number, // Default = 15
matchLeveragedOrder?: boolean, // Default = false
side?: 'buy' | 'sell' // Default = 'buy'
- 芒果组点市场 应当创造清算机会的现货市场
- 数量 指定多少命令 丽琪 账户应该创建, 它不影响命令Size
- 自定义Liqee-Owner 如果您想要重新使用现有账户,则可以指定
liqee。如果您想要将清算情况连锁起来,则这样做是有用的。 如果空出, 将创建新账户 - 应 PartialLiquidate (应参加) 指明应当定期清算还是部分清算
- 应创建新地址 将建立一个新的liqor账户,为清算提供资金。 如果你把清算方案连在一起 不需要在每一个方案上建立一个清算人 这样你就可以设定它
false - 应完成定量 测试 - 和上面一样,您应该将这个参数设置为
false或希望手工完成清算. - 自定义命令 - 如果不设定,它将使用
minPrice市场 - 自定义命令大小 - 如果不设定,它将使用
minSize市场 - 杠杆 - 此参数指定了当前 丽琪例如,15个系数将生效 丽琪 改为 15x
- 匹配已调整的顺序 指定长或短是否应当相匹配,否则清算方案将与借款一起进行,以便始终保持与开放订单相同的货币。 如果设置为
true它会把杠杆提高一倍. - 边 指定是长还是短才被清算
示例
async function main() {
const client = new MangoClient()
const cluster = 'mainnet-beta'
const clusterUrl = process.env.CLUSTER_URL || IDS.cluster_urls[cluster]
const connection = new Connection(clusterUrl, 'singleGossip')
const programId = new PublicKey(IDS[cluster].mango_program_id)
const dexProgramId = new PublicKey(IDS[cluster].dex_program_id)
const mangoGroupPk = new PublicKey(IDS[cluster].mango_groups['BTC_ETH_USDT'].mango_group_pk)
const keyPairPath = process.env.KEYPAIR || homedir() + '/.config/solana/id.json'
const payer = new Account(JSON.parse(fs.readFileSync(keyPairPath, 'utf-8')))
const mangoGroup = await client.getMangoGroup(connection, mangoGroupPk)
const prices = await mangoGroup.getPrices(connection)
const marginAccounts = (await client.getMarginAccountsForOwner(connection, programId, mangoGroup, payer))
marginAccounts.sort(
(a, b) => (a.computeValue(mangoGroup, prices) > b.computeValue(mangoGroup, prices) ? -1 : 1)
)
let marginAccount = marginAccounts[0]
const market = await Market.load(connection, mangoGroup.spotMarkets[0], { skipPreflight: true, commitment: 'singleGossip'}, mangoGroup.dexProgramId)
console.log('placing order')
const txid = await client.placeOrder(connection, programId, mangoGroup, marginAccount, market, payer, 'buy', 48000, 0.0001)
console.log('order placed')
await sleep(5000)
marginAccount = await client.getMarginAccount(connection, marginAccount.publicKey, mangoGroup.dexProgramId)
const bids = await market.loadBids(connection)
const asks = await market.loadAsks(connection)
console.log('canceling orders')
await marginAccount.cancelAllOrdersByMarket(connection, client, programId, mangoGroup, market, bids, asks, payer)
console.log('orders canceled')
}