Skip to content

Market orders fail on new email/magic accounts #83

Description

@gipadm

Hi Polymarket team,

I am not able to send market orders via clob-client-v2. Here is my setup:

  • "@polymarket/clob-client-v2": "1.0.6"
  • PM account was recently created using email/magic.
  • Account was funded from Deposit -> Cash (credit card).
  • Over 10 manual trades are already successfully completed on polymarket.com.

Now here is my sample code with inline comments:

import { ClobClient, AssetType, Side, OrderType } from "@polymarket/clob-client-v2";
import { createWalletClient, http } from "viem";
import { polygon } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";

const TOKEN = "{any token here}";
const HOST = "https://clob.polymarket.com";
const CHAIN_ID = 137;

// Polymarket Address copied from https://polymarket.com/settings?tab=profile
// Note: Do not send funds to this address. This address is for API use only.
// Address string: 0xABCD...
const POLY_ADDR = process.env.POLYMARKET_API_ADDR;

// Polymarket Private key copied from
// https://polymarket.com/settings?tab=account > https://reveal.magic.link/polymarket
const PRIVATE_KEY = process.env.POLYMARKET_API_KEY as `0x${string}`;

const ACCOUNT = privateKeyToAccount(PRIVATE_KEY);

const SIGNER = createWalletClient({
	account: ACCOUNT,
	chain: polygon,
	transport: http(),
});

const tempClient = new ClobClient({
	host: HOST,
	chain: CHAIN_ID,
	signer: SIGNER,
});

const API_CREDS = await tempClient.createOrDeriveApiKey();
console.log(API_CREDS);
/*
This returns a credential set with values. Note that these values never change.
{
  key: 'xxx-xxx-xxx-xxx-xxx',
  secret: 'yyyyyyyy',
  passphrase: 'zzzzzzzz'
}
*/

const CLOB_CLIENT = new ClobClient({
	host: HOST,
	chain: CHAIN_ID,
	signer: SIGNER,
	creds: API_CREDS,
	signatureType: 3,
});

const balance = await CLOB_CLIENT.getBalanceAllowance({
	asset_type: AssetType.COLLATERAL,
});
console.log(`Balance: ${balance.balance}`);
/*
	This returns the correct account balance!
*/

const tickSize = await CLOB_CLIENT.getTickSize(TOKEN);
console.log(`Tick size: ${tickSize}`);
/*
	This returns a valid tick size!
*/

const order = await CLOB_CLIENT.createMarketOrder({
	tokenID: TOKEN,
	side: Side.BUY,
	amount: 1,
	price: 0.8,
},
{
	tickSize: tickSize,
	negRisk: false
});

console.log(order);
/*
	Note: maker and signer are the same as the POLY_ADDR string
{
  maker: '0xABCD...',
  signer: '0xABCD...',
}
*/

const posted = await CLOB_CLIENT.postOrder(order, OrderType.FOK);

console.log(posted);
/*
	This always returns the following error:
{
  error: 'the order signer address has to be the address of the API KEY',
  status: 400
}
*/

Using signatureType = 0, 1 or 2 returns error: 'maker address not allowed, please use the deposit wallet flow' on postOrder() calls.

I tried forcing creation of fresh credentials using createApiKey() but it fails with response: { error: 'Could not create api key', status: 400 }
If I run deleteApiKey() the client does lose its key but then createApiKey() returns the old key that was just deleted.

What is a working example of sending a market order for newly created email/magic accounts?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions