Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example cross market maker + byproduct utility functions #107

Merged
merged 10 commits into from
Jul 25, 2022

Conversation

waterquarks
Copy link
Contributor

@waterquarks waterquarks commented Jul 18, 2022

  • Adds an ensureOpenOrdersAccount function function, that creates an open orders account for the submitted Serum market if it doesn't already exist. This is tested against an example market maker which is to receive further updates.
  • Install KrisM's risk check.

@waterquarks waterquarks changed the title Add ensureOpenOrdersAccount method and cross market maker v1 Add ensureOpenOrdersAccount method and cross market maker V1 Jul 18, 2022
package.json Outdated Show resolved Hide resolved
src/client.ts Outdated Show resolved Hide resolved

while (recentFills.length > 256) {
recentFills.shift()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big fan of this, a better solution would be to just filter the array and override it:

recentFills = recentFills.filter(fill => fill.slot > slot)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is a much simpler solution

const queuedBasePosition = perpEventQueue.getUnconsumedEvents()
.filter(event => event.fill !== undefined)
.map(event => event.fill)
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code shouldn't ignore any typescript compilation issues

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patched

expiryTimestamp
),
// @ts-ignore
// tx.add(riskChecker.makeCheckRiskInstruction(perpMarketConfig, perpMarket))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

risk check should be enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-enabled, was just fixing compiler errors

const slots = _.uniq([mangoAccountRaw.context.slot, perpEventQueueRaw.context.slot])

if (slots.length !== 1) {
throw new Error('Inconsistent slots on Mango account monitor.')
Copy link
Contributor

@mschneider mschneider Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error is not correctly handled in the calling function, might cause "unhandled promise rejection" issues at runtime which can be really hard to trace, you can either handle the exception or switch to an optional return type

Copy link
Contributor Author

@waterquarks waterquarks Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at the code for getMultipleAccounts - the context is the same for all elements in the result array: no need for this check, went ahead and removed it


const recentBlockTime = await connection.getBlockTime(
await connection.getSlot('finalized')
)
Copy link
Contributor

@mschneider mschneider Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so stupidly inefficient, can you please open an issue on solana-labs/solana ?

if (isSnapshot) {
for (const event of data.events.map(parseEvent)) {
const fill = perpMarket.parseFillEvent(event.fill)

Copy link
Contributor

@mschneider mschneider Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit annoying we don't have the slot number here. in general better to remove this unused code and just
if (isSnapshot) return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah having slot number for each fill in the snapshot message would be handy in this case - removed this bit in the meantime

@waterquarks waterquarks changed the title Add ensureOpenOrdersAccount method and cross market maker V1 Example cross market maker + byproduct utility functions Jul 21, 2022
@mschneider mschneider merged commit eadbedc into main Jul 25, 2022
@mschneider mschneider deleted the waterquarks/xmm branch July 25, 2022 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants