Development resources could use a little brushing up

I’m having a hard time finding relevant information and examples in the current documentation.

More specifically, this is what I’m struggling with:

Login

Is this section up to date? It doesn’t seem to match this example.

What I’m actually interested in is using the apiKey only to login (without the secret), instead of the whole json file. So instead of:

nash.login(require('PATH_TO_KEY.json'))

Is it possible to login like this:

creds = {}
creds.apiKey = '58652459-39...'
nash.login(creds)

or even:

nash.login('58652459-39...')

Market order

I have not succeeded in placing a market order yet.

I am mostly interested in the BTC/USDC pair, so I tried the following (as advertised here):

await client.placeMarketOrder(
  createCurrencyAmount('5.02', CryptoCurrency.USDC),
  OrderBuyOrSell.BUY,
  'btc_usdc'
)

but got an error: "…wrong amount unit for target market…"

I thought maybe BTC required specific methods so I tried the same on the NEO/ETH pair and got "…Invalid timestamp…"

Any help would be appreciated!

5 Likes

Hello,

There what I can say:

Login

Indeed the doc is outdated, the login method here has been renamed to loginLegacy.

Market order

No clue…

Invalid timestamp

I have this kind of error when I spend too much time to debug the Nash code in step by step, otherwise no clue…

Btw I agree the doc is not very useful right now. Usually I search directly in the Nash code.

1 Like

Thanks for contributing @Aurel! Welcome! :nash_n:

1 Like

I haven’t tried to do a market order since the new releases. Last time I did it was with the python api. But in the description you have posted the CryptoCurrency amount is used as the first mentioned currency in the market. Maybe it has to be this way around?

await client.placeMarketOrder(
  createCurrencyAmount('5.02', CryptoCurrency.BTC),
  OrderBuyOrSell.BUY,
  'btc_usdc'
)
1 Like

What I’m actually interested in is using the apiKey only to login (without the secret ), instead of the whole json file. So instead of:

That is not technically possible @Oldsport. The apiKey parameter is just a identifier, what you actually use to authenticate is the secret part. This is true not only for Nash but for any API key system. So unfortunately there is not way around it :expressionless:

await client.placeMarketOrder(
createCurrencyAmount(‘5.02’, CryptoCurrency.USDC),
OrderBuyOrSell.BUY,
‘btc_usdc’
)

@Symiaq is correct, in a market order is not possible to define the resulting total since the price is undefined, you can only specify the order in base currency, so use CryptoCurrency.BTC instead.

Best,

1 Like

But what if someone only want to use non authenticated API methods, for instance listMarket or getOrderBook ? Calling login is still required because the ‘apiKey’ is added into a Authorization header for all methods, even the non authenticated ones, but I guess the secret should not be required.

So maybe calling: nash.login({ apiKey: '58652459-39...', secret: "" }); works, but I haven’t tested it.

1 Like

Not true. I can call a non-authenticated method (e.g. listMarkets()) without any authorization:

let NashTS = require('@neon-exchange/api-client-typescript');

let nash = new NashTS.Client({
    apiURI: 'https://app.nash.io/api/graphql',
    casURI: 'https://app.nash.io/api',
    debug: false
});

const run = async () => {
    let marketsList = await nash.listMarkets()

    marketsList.markets.forEach(async (Market, index) => {
        //  
    })
}

run()
2 Likes

Ah ok, good to know!

Thanks.

Just made the adjustment and it works for market sell orders:

Yes, 5.02 BTC for 21 USDC… :grimacing:

However when trying to market buy BTC with USDC, I get the following error:

which is all the more astonishing that I’m working on sandbox.

Here’s the snippet:

await client.placeMarketOrder(
  createCurrencyAmount('1.06', CryptoCurrency.BTC),
  OrderBuyOrSell.BUY,
  'btc_usdc'
)

@canesin Any known restrictions could be triggering this?

Markets buy have some technical limitations on the protocol, so to emulate that you can do a market sell in the inverse market. The equivalent would be:

await client.placeMarketOrder(
  createCurrencyAmount('21', CryptoCurrency.USDC),
  OrderBuyOrSell.SELL,
  'usdc_btc'
)
3 Likes

It works, thanks!

I didn’t know you could inverse a pair like this.

Market order min amount

Found something a little odd when executing a market sell order of USDC into BTC (so buying BTC with USDC):

Amount 0.13 for currency usdc is less than min amount for market: 5.00000000.  Defaulting to min amount

0.13 < 5 so the message is appropriate, but I would have expected the trade not to go through and getting an error instead. I guess the frontend there for that, but it means if I build an app, it must also implement this front validation myself.

Withdrawal

I am trying to make a withdrawal from a personal account to an external one. Is signWithdrawRequest the right method for that? No luck with the following snippet:

const address = 'AbH99atcxwGECSNBdfoQJDPoC2LWndyCwt';
const amount = createCurrencyAmount('14', CryptoCurrency.NEX);
const signedMovement = await client.signWithdrawRequest(address, amount);
console.log(signedMovement)

Do you get these nonce errors on the latest version of the SDK @Oldsport?

@canesin My version was 5.0.11, I think it’s still the latest.

However, I changed the very method I’m using. I don’t know why it wasn’t showing up in the documentation search before, but I’m now trying to use transferToExternal.

I first tried this, as per the documentation.

const address = 'AbH99atcxwGECSNBdfoQJDPoC2LWndyCwt';
const cryptoAmount = createCurrencyAmount(amountString, CryptoCurrency.NEX);
await client.transferToExternal(cryptoAmount, address);

but got an error:

After taking a closer look inside the SDK, I am now trying this:

const address = 'AbH99atcxwGECSNBdfoQJDPoC2LWndyCwt';
const transferParams = {
  quantity: {
    currency: CryptoCurrency.NEO,
    amount: 25
  },
  address: address
}
await client.transferToExternal(transferParams);

Which yields this error:

I know the message looks pretty self-explanatory, but I did add the destination address to the whitelist of the API key I’m using. I even tried with a newly created API key, to no avail.

Any help would be greatly appreciated :slight_smile:

1 Like

will look into it!

1 Like

I think I misread the documentation :thinking: Parameters appear to be correctly documented. My bad!

My second point (about it not working) still stands :pray:

Quick question: Is there a reason API keys’ secret are so long? Over 6000 characters!

Also, any news about transfers?

Doesn’t work for you on latest version? There was a specific issue with NEO transfers.

The secret is so long because it is a lot of information :sweat_smile:… it is keys for all the chains supported and homomorphic encryption keys. It needs to be able to sign transactions on all the chains and collaborate with the matching engine in the MPC protocol. Not a single simple secret to sign hmacs like usual to API keys.

1 Like

It doesn’t look like it. I updated to version 5.0.19 and still getting that destination address is not part of the whitelisted addresses error. However the destination address is part of the API key whitelist.

Ok, I understand. FYI I had to split it in half to fit into cookies, not the best dev experience, but what can you do! Maybe I ought to use localStorage, but it feels less safe than httpOnly cookies.

1 Like

Will verify, I guess might be some issue on sandbox.

Are you sending the secret to a server in the headers? If you share the use I might help. Normally if the use is only on the client side localStorage or sessionStorage might be better.
If it is used on the server only than doing a push for the keys once and having in a encrypted database might be better.

2 Likes