From 8e10eb88410e70843c8e514fd6d919bc76289cda Mon Sep 17 00:00:00 2001 From: arekgotfryd Date: Sat, 24 Jun 2023 16:14:12 +0200 Subject: [PATCH] #39 fix for invalid side, FOK orders can only be buys/bids orders --- dist/main.js | 2 +- src/services/polymarket.service.spec.ts | 105 +++++++++++++++++++++--- src/services/polymarket.service.ts | 20 +++-- 3 files changed, 106 insertions(+), 21 deletions(-) diff --git a/dist/main.js b/dist/main.js index 37d611c..72119a2 100644 --- a/dist/main.js +++ b/dist/main.js @@ -1,3 +1,3 @@ #! /usr/bin/env node -(()=>{"use strict";var e={283:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.usdcContractABI=void 0,t.usdcContractABI=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"authorizer",type:"address"},{indexed:!0,internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"AuthorizationCanceled",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"authorizer",type:"address"},{indexed:!0,internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"AuthorizationUsed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"account",type:"address"}],name:"Blacklisted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"userAddress",type:"address"},{indexed:!1,internalType:"address payable",name:"relayerAddress",type:"address"},{indexed:!1,internalType:"bytes",name:"functionSignature",type:"bytes"}],name:"MetaTransactionExecuted",type:"event"},{anonymous:!1,inputs:[],name:"Pause",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"newRescuer",type:"address"}],name:"RescuerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"account",type:"address"}],name:"UnBlacklisted",type:"event"},{anonymous:!1,inputs:[],name:"Unpause",type:"event"},{inputs:[],name:"APPROVE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"BLACKLISTER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"CANCEL_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DECREASE_ALLOWANCE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEPOSITOR_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"EIP712_VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"INCREASE_ALLOWANCE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"META_TRANSACTION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PAUSER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PERMIT_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"RESCUER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"TRANSFER_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"WITHDRAW_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"approveWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"authorizer",type:"address"},{internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"authorizationState",outputs:[{internalType:"enum GasAbstraction.AuthorizationState",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"blacklist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"blacklisters",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"authorizer",type:"address"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"cancelAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"decrement",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"decreaseAllowanceWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"depositData",type:"bytes"}],name:"deposit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"userAddress",type:"address"},{internalType:"bytes",name:"functionSignature",type:"bytes"},{internalType:"bytes32",name:"sigR",type:"bytes32"},{internalType:"bytes32",name:"sigS",type:"bytes32"},{internalType:"uint8",name:"sigV",type:"uint8"}],name:"executeMetaTransaction",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"uint256",name:"index",type:"uint256"}],name:"getRoleMember",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleMemberCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"increment",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"increaseAllowanceWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newName",type:"string"},{internalType:"string",name:"newSymbol",type:"string"},{internalType:"uint8",name:"newDecimals",type:"uint8"},{internalType:"address",name:"childChainManager",type:"address"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"initialized",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"isBlacklisted",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"pausers",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"tokenContract",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"rescueERC20",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"rescuers",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"transferWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"unBlacklist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newName",type:"string"},{internalType:"string",name:"newSymbol",type:"string"}],name:"updateMetadata",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"withdrawWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"}]},858:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.AppModule=void 0;const i=n(481),s=n(498),r=n(255),o=n(442),p=n(235);let y=class AppModule{};y=a([(0,i.Module)({imports:[s.HttpModule],providers:[r.PolymarketService,o.ConfigService,p.ContractService]})],y),t.AppModule=y},974:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getProgram=void 0;const a=n(304),i=n(598);t.getProgram=()=>{const e=new a.Command;return e.version(i.version).description("Command line interface for Polymarket").option("-l, --list ","List available markets with question filter. Usage: pmarket-cli -l ").option("-b, --buy ","Buy token order. Usage: pmarket-cli -b ").option("-s, --sell ","Sell token order. Usage: pmarket-cli -s ").option("-a, --allowance ","Set USDC allowance for CTFExchange contract. Usage: pmarket-cli -a ").option("-o, --orderBook ","Show order book for specific tokenId. Usage: pmarket-cli -o ").option("-c, --cancelAll","Cancel all open orders. Usage: pmarket-cli -c").option("-k, --keys","Get or generate api keys. Usage: pmarket-cli -k"),e}},442:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigService=void 0;const s=n(481),r=n(147),o=n(17),p=n(37),y=".pmarket-cli",l="config.json";let u=class ConfigService{constructor(){this.isConfigAvailable()?this.loadConfig():this.createNewConfig()}isConfigAvailable(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;return(0,r.existsSync)(e)}loadConfig(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;this.config=JSON.parse((0,r.readFileSync)(e,"utf8"))}createNewConfig(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;this.config={apiKey:"",apiSecret:"",passphrase:"",rpcProvider:"",privateKey:""},(0,r.existsSync)((0,p.homedir)()+o.sep+y)||(0,r.mkdirSync)((0,p.homedir)()+o.sep+y),(0,r.writeFileSync)(e,JSON.stringify(this.config,null,4))}get(e){return this.config[e]}getCreds(){return{key:this.config.apiKey,secret:this.config.apiSecret,passphrase:this.config.passphrase}}};u=a([(0,s.Injectable)(),i("design:paramtypes",[])],u),t.ConfigService=u},235:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ContractService=void 0;const s=n(481),r=n(982),o=n(283),p=n(442);let y=class ContractService{constructor(e){this.configService=e,this.polygonProvider=new r.ethers.providers.JsonRpcProvider(this.configService.get("rpcProvider"));try{this.wallet=new r.ethers.Wallet(this.configService.get("privateKey"),this.polygonProvider)}catch(e){console.log("Please provide valid private key and rpc provider in config.json file")}}async setAllowance(e){const t=await this.getBlockGasLimit(),n=await this.polygonProvider.getGasPrice(),a=new r.ethers.Contract("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",o.usdcContractABI,this.wallet),i=r.ethers.utils.parseUnits(e.toString(),"6");return await a.approve("0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",i,{gasLimit:t,gasPrice:n})}async getBlockGasLimit(){const e=await this.polygonProvider.getBlockNumber(),t=(await this.polygonProvider.getBlock(e)).gasLimit;console.log("Block Gas Limit:",t.toString())}};y=a([(0,s.Injectable)(),i("design:paramtypes",[p.ConfigService])],y),t.ContractService=y},255:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.PolymarketService=void 0;const s=n(481),r=n(204),o=n(509),p=n(167),y=n(982),l=n(442);let u;const c="https://clob.polymarket.com/";let d=class PolymarketService{constructor(e){this.configService=e;const t=new y.ethers.providers.JsonRpcProvider(this.configService.get("rpcProvider")),n=new y.ethers.Wallet(this.configService.get("privateKey"),t);u=this.configService.getCreds(),this.clobClient=new r.ClobClient(c,o.Chain.POLYGON,n,u)}async getMarkets(){return(await p.default.get(`${c}markets`)).data}async getMarketsAcceptingOrders(){return(await this.getMarkets()).filter((e=>e.accepting_orders)).map((e=>({token_0:e.tokens[0],token_1:e.tokens[1],question:e.question})))}async determineMakerOrTakerFee(e,t,n,a,i){const s={side:"taker",fee:0};if(t===o.Side.SELL){if(a.bids.map((e=>({price:parseFloat(e.price),size:parseFloat(e.size)}))).filter((e=>e.price>=i)).reduce(((e,t)=>t.size),0)>=n){const t=await this.getFeeRateBps(e,"taker");return s.side="taker",s.fee=t,s}{const t=await this.getFeeRateBps(e,"maker");return s.side="maker",s.fee=t,s}}if(t===o.Side.BUY){if(a.asks.map((e=>({price:parseFloat(e.price),size:parseFloat(e.size)}))).filter((e=>e.price<=i)).reduce(((e,t)=>e+t.size),0)>=n){const t=await this.getFeeRateBps(e,"taker");return s.side="taker",s.fee=t,s}{const t=await this.getFeeRateBps(e,"maker");return s.side="maker",s.fee=t,s}}}async getFeeRateBps(e,t){const n=(await this.getMarkets()).filter((t=>t.tokens.map((e=>e.token_id)).indexOf(e)>=0))[0];return"taker"===t?n.taker_base_fee:n.maker_base_fee}async marketOrder(e,t,n,a){t===o.Side.BUY&&(n=Math.floor(n/a));const i=await this.clobClient.getOrderBook(e);console.log(i);const s=await this.determineMakerOrTakerFee(e,t,n,i,a);console.log("Fee rate: "+s.fee),console.log(t),console.log(n),console.log(a);const r=await this.clobClient.createOrder({tokenID:e,price:a,side:t,size:n,feeRateBps:s.fee,nonce:0,expiration:0});let p;return"taker"===s.side?p=await this.clobClient.postOrder(r,o.OrderType.FOK):"maker"===s.side&&(p=await this.clobClient.postOrder(r,o.OrderType.GTC)),p}async getOrderBook(e){return this.clobClient.getOrderBook(e)}async cancelAll(){const e=await this.clobClient.cancelAll();return console.log(e),e}async getApiKeys(){const e=await this.clobClient.deriveApiKey();return e.error?this.clobClient.createApiKey():e}};d=a([(0,s.Injectable)(),i("design:paramtypes",[l.ConfigService])],d),t.PolymarketService=d},832:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AllowanceStrategy=void 0;t.AllowanceStrategy=class AllowanceStrategy{constructor(e){this.contractService=e}async execute(e){try{const t=await this.contractService.setAllowance(+e.allowance);console.log(t)}catch(e){console.error(e)}}}},733:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ApiKeysStrategy=void 0;t.ApiKeysStrategy=class ApiKeysStrategy{constructor(e){this.polymarketService=e}async execute(){const e=await this.polymarketService.getApiKeys();console.log(e)}}},719:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BuyStrategy=void 0;const a=n(204);t.BuyStrategy=class BuyStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=e.buy[0],n=+e.buy[1],i=+e.buy[2];try{const e=await this.polymarketService.marketOrder(t,a.Side.BUY,n,i);console.log(e)}catch(e){console.error(e)}}}},943:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CancelAllStrategy=void 0;t.CancelAllStrategy=class CancelAllStrategy{constructor(e){this.polymarketService=e}async execute(){try{await this.polymarketService.cancelAll()}catch(e){console.error(e)}}}},638:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Context=void 0;const a=n(946),i=n(719),s=n(280),r=n(832),o=n(398),p=n(943),y=n(733);t.Context=class Context{constructor(e,t){this.polymarketService=e,this.contractService=t,this.setStrategy=e=>{this.strategy=e},this.executeStrategy=e=>{this.strategy.execute(e)},this.determineStrategy=e=>{let t;return e.list&&(t=new a.ListStrategy(this.polymarketService)),e.buy&&3===e.buy.length&&(t=new i.BuyStrategy(this.polymarketService)),e.sell&&3===e.sell.length&&(t=new s.SellStrategy(this.polymarketService)),e.allowance&&(t=new r.AllowanceStrategy(this.contractService)),e.orderBook&&(t=new o.OrderBookStrategy(this.polymarketService)),e.cancelAll&&(t=new p.CancelAllStrategy(this.polymarketService)),e.keys&&(t=new y.ApiKeysStrategy(this.polymarketService)),t}}}},946:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ListStrategy=void 0;t.ListStrategy=class ListStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=await this.polymarketService.getMarketsAcceptingOrders();console.log(t.filter((t=>t.question.toLowerCase().includes(e.list.toLowerCase()))))}}},398:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OrderBookStrategy=void 0;t.OrderBookStrategy=class OrderBookStrategy{constructor(e){this.polymarketService=e}async execute(e){try{const t=await this.polymarketService.getOrderBook(e.orderBook);console.log(t)}catch(e){console.error(e)}}}},280:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SellStrategy=void 0;const a=n(204);t.SellStrategy=class SellStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=e.sell[0],n=+e.sell[1],i=+e.sell[2];try{const e=await this.polymarketService.marketOrder(t,a.Side.SELL,n,i);console.log(e)}catch(e){console.error(e)}}}},593:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.setAndExecuteStrategy=void 0;t.setAndExecuteStrategy=(e,t,n)=>{n.setStrategy(e),n.executeStrategy(t)}},498:e=>{e.exports=require("@nestjs/axios")},481:e=>{e.exports=require("@nestjs/common")},143:e=>{e.exports=require("@nestjs/core")},204:e=>{e.exports=require("@polymarket/clob-client")},509:e=>{e.exports=require("@polymarket/clob-client/dist/types")},167:e=>{e.exports=require("axios")},304:e=>{e.exports=require("commander")},982:e=>{e.exports=require("ethers")},116:e=>{e.exports=require("figlet")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},17:e=>{e.exports=require("path")},598:e=>{e.exports=JSON.parse('{"name":"pmarket-cli","version":"0.7.2","description":"CLI tool to trade on Polymarket","license":"MIT","author":{"name":"Arkadiusz Gotfryd","email":"arekgotfryd@g.pl"},"keywords":["cli","npmtool","polymarket"],"repository":"https://github.com/arekgotfryd/pmarket-cli","homepage":"https://github.com/arekgotfryd/pmarket-cli/blob/master/README.md","main":"dist/main.js","bin":{"pmarket-cli":"./dist/main.js"},"scripts":{"prebuild":"rimraf dist","build":"nest build --webpack --webpackPath webpack.config.js","format":"prettier --write \\"src/**/*.ts\\" \\"test/**/*.ts\\"","start":"nest start","start:dev":"nest start --watch","start:debug":"nest start --debug --watch","start:prod":"node dist/main","lint":"eslint src/**/*.ts --fix","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:debug":"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e":"echo \'No e2e tests implemented yet.\'","build:postinstall":"nest build --webpack --webpackPath webpack.postinstall.config.js","postinstall":"node ./scripts/create-config.js"},"dependencies":{"@nestjs/axios":"^2.0.0","@nestjs/common":"^9.4.2","@nestjs/core":"^9.4.2","@polymarket/clob-client":"^1.4.0","axios":"^1.3.4","commander":"^10.0.1","ethers":"^5.7.1","figlet":"^1.6.0","reflect-metadata":"0.1.13","rimraf":"3.0.2"},"devDependencies":{"@nestjs/cli":"^9.5.0","@nestjs/testing":"^9.4.2","@types/jest":"^29.5.2","@types/node":"18.0.3","@typescript-eslint/eslint-plugin":"5.30.5","@typescript-eslint/parser":"5.30.5","eslint":"8.19.0","eslint-config-prettier":"8.5.0","jest":"28.1.2","prettier":"2.7.1","ts-jest":"28.0.5","ts-loader":"9.3.1","ts-node":"10.8.2","typescript":"4.7.4","webpack-shebang-plugin":"^1.1.8"}}')}},t={};function __webpack_require__(n){var a=t[n];if(void 0!==a)return a.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,__webpack_require__),i.exports}(()=>{const e=__webpack_require__(143),t=__webpack_require__(858),n=__webpack_require__(255),a=__webpack_require__(974),i=__webpack_require__(235),s=__webpack_require__(116),r=__webpack_require__(638),o=__webpack_require__(593),p=__webpack_require__(598);!async function bootstrap(){const y=await e.NestFactory.createApplicationContext(t.AppModule,{logger:!1}),l=y.get(n.PolymarketService),u=y.get(i.ContractService);console.log(s.textSync(p.name));const c=(0,a.getProgram)();process.argv.slice(2).length||c.outputHelp();const d=c.parse(process.argv).opts(),m=new r.Context(l,u),b=m.determineStrategy(d);b&&(0,o.setAndExecuteStrategy)(b,d,m)}()})()})(); \ No newline at end of file +(()=>{"use strict";var e={283:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.usdcContractABI=void 0,t.usdcContractABI=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"authorizer",type:"address"},{indexed:!0,internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"AuthorizationCanceled",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"authorizer",type:"address"},{indexed:!0,internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"AuthorizationUsed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"account",type:"address"}],name:"Blacklisted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"userAddress",type:"address"},{indexed:!1,internalType:"address payable",name:"relayerAddress",type:"address"},{indexed:!1,internalType:"bytes",name:"functionSignature",type:"bytes"}],name:"MetaTransactionExecuted",type:"event"},{anonymous:!1,inputs:[],name:"Pause",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"newRescuer",type:"address"}],name:"RescuerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"account",type:"address"}],name:"UnBlacklisted",type:"event"},{anonymous:!1,inputs:[],name:"Unpause",type:"event"},{inputs:[],name:"APPROVE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"BLACKLISTER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"CANCEL_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DECREASE_ALLOWANCE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DEPOSITOR_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"EIP712_VERSION",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"INCREASE_ALLOWANCE_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"META_TRANSACTION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PAUSER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PERMIT_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"RESCUER_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"TRANSFER_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"WITHDRAW_WITH_AUTHORIZATION_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"approveWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"authorizer",type:"address"},{internalType:"bytes32",name:"nonce",type:"bytes32"}],name:"authorizationState",outputs:[{internalType:"enum GasAbstraction.AuthorizationState",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"blacklist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"blacklisters",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"authorizer",type:"address"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"cancelAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"decrement",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"decreaseAllowanceWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"},{internalType:"bytes",name:"depositData",type:"bytes"}],name:"deposit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"userAddress",type:"address"},{internalType:"bytes",name:"functionSignature",type:"bytes"},{internalType:"bytes32",name:"sigR",type:"bytes32"},{internalType:"bytes32",name:"sigS",type:"bytes32"},{internalType:"uint8",name:"sigV",type:"uint8"}],name:"executeMetaTransaction",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"uint256",name:"index",type:"uint256"}],name:"getRoleMember",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleMemberCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"increment",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"increaseAllowanceWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newName",type:"string"},{internalType:"string",name:"newSymbol",type:"string"},{internalType:"uint8",name:"newDecimals",type:"uint8"},{internalType:"address",name:"childChainManager",type:"address"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"initialized",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"isBlacklisted",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"pausers",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"tokenContract",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"rescueERC20",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"rescuers",outputs:[{internalType:"address[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"transferWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"unBlacklist",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newName",type:"string"},{internalType:"string",name:"newSymbol",type:"string"}],name:"updateMetadata",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"validAfter",type:"uint256"},{internalType:"uint256",name:"validBefore",type:"uint256"},{internalType:"bytes32",name:"nonce",type:"bytes32"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"withdrawWithAuthorization",outputs:[],stateMutability:"nonpayable",type:"function"}]},858:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r};Object.defineProperty(t,"__esModule",{value:!0}),t.AppModule=void 0;const i=n(481),s=n(498),r=n(255),o=n(442),p=n(235);let y=class AppModule{};y=a([(0,i.Module)({imports:[s.HttpModule],providers:[r.PolymarketService,o.ConfigService,p.ContractService]})],y),t.AppModule=y},974:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getProgram=void 0;const a=n(304),i=n(598);t.getProgram=()=>{const e=new a.Command;return e.version(i.version).description("Command line interface for Polymarket").option("-l, --list ","List available markets with question filter. Usage: pmarket-cli -l ").option("-b, --buy ","Buy token order. Usage: pmarket-cli -b ").option("-s, --sell ","Sell token order. Usage: pmarket-cli -s ").option("-a, --allowance ","Set USDC allowance for CTFExchange contract. Usage: pmarket-cli -a ").option("-o, --orderBook ","Show order book for specific tokenId. Usage: pmarket-cli -o ").option("-c, --cancelAll","Cancel all open orders. Usage: pmarket-cli -c").option("-k, --keys","Get or generate api keys. Usage: pmarket-cli -k"),e}},442:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ConfigService=void 0;const s=n(481),r=n(147),o=n(17),p=n(37),y=".pmarket-cli",l="config.json";let u=class ConfigService{constructor(){this.isConfigAvailable()?this.loadConfig():this.createNewConfig()}isConfigAvailable(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;return(0,r.existsSync)(e)}loadConfig(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;this.config=JSON.parse((0,r.readFileSync)(e,"utf8"))}createNewConfig(){const e=(0,p.homedir)()+o.sep+y+o.sep+l;this.config={apiKey:"",apiSecret:"",passphrase:"",rpcProvider:"",privateKey:""},(0,r.existsSync)((0,p.homedir)()+o.sep+y)||(0,r.mkdirSync)((0,p.homedir)()+o.sep+y),(0,r.writeFileSync)(e,JSON.stringify(this.config,null,4))}get(e){return this.config[e]}getCreds(){return{key:this.config.apiKey,secret:this.config.apiSecret,passphrase:this.config.passphrase}}};u=a([(0,s.Injectable)(),i("design:paramtypes",[])],u),t.ConfigService=u},235:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.ContractService=void 0;const s=n(481),r=n(982),o=n(283),p=n(442);let y=class ContractService{constructor(e){this.configService=e,this.polygonProvider=new r.ethers.providers.JsonRpcProvider(this.configService.get("rpcProvider"));try{this.wallet=new r.ethers.Wallet(this.configService.get("privateKey"),this.polygonProvider)}catch(e){console.log("Please provide valid private key and rpc provider in config.json file")}}async setAllowance(e){const t=await this.getBlockGasLimit(),n=await this.polygonProvider.getGasPrice(),a=new r.ethers.Contract("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",o.usdcContractABI,this.wallet),i=r.ethers.utils.parseUnits(e.toString(),"6");return await a.approve("0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E",i,{gasLimit:t,gasPrice:n})}async getBlockGasLimit(){const e=await this.polygonProvider.getBlockNumber(),t=(await this.polygonProvider.getBlock(e)).gasLimit;console.log("Block Gas Limit:",t.toString())}};y=a([(0,s.Injectable)(),i("design:paramtypes",[p.ConfigService])],y),t.ContractService=y},255:function(e,t,n){var a=this&&this.__decorate||function(e,t,n,a){var i,s=arguments.length,r=s<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(r=(s<3?i(r):s>3?i(t,n,r):i(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},i=this&&this.__metadata||function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)};Object.defineProperty(t,"__esModule",{value:!0}),t.PolymarketService=void 0;const s=n(481),r=n(204),o=n(509),p=n(167),y=n(982),l=n(442);let u;const c="https://clob.polymarket.com/";let d=class PolymarketService{constructor(e){this.configService=e;const t=new y.ethers.providers.JsonRpcProvider(this.configService.get("rpcProvider")),n=new y.ethers.Wallet(this.configService.get("privateKey"),t);u=this.configService.getCreds(),this.clobClient=new r.ClobClient(c,o.Chain.POLYGON,n,u)}async getMarkets(){return(await p.default.get(`${c}markets`)).data}async getMarketsAcceptingOrders(){return(await this.getMarkets()).filter((e=>e.accepting_orders)).map((e=>({token_0:e.tokens[0],token_1:e.tokens[1],question:e.question})))}async determineMakerOrTakerFee(e,t,n,a,i){const s={side:"taker",fee:0};if(t===o.Side.SELL){if(a.bids.map((e=>({price:parseFloat(e.price),size:parseFloat(e.size)}))).filter((e=>e.price>=i)).reduce(((e,t)=>t.size),0)>=n){const t=await this.getFeeRateBps(e,"taker");return s.side="taker",s.fee=t,s}{const t=await this.getFeeRateBps(e,"maker");return s.side="maker",s.fee=t,s}}if(t===o.Side.BUY){if(a.asks.map((e=>({price:parseFloat(e.price),size:parseFloat(e.size)}))).filter((e=>e.price<=i)).reduce(((e,t)=>e+t.size),0)>=n){const t=await this.getFeeRateBps(e,"taker");return s.side="taker",s.fee=t,s}{const t=await this.getFeeRateBps(e,"maker");return s.side="maker",s.fee=t,s}}}async getFeeRateBps(e,t){const n=(await this.getMarkets()).filter((t=>t.tokens.map((e=>e.token_id)).indexOf(e)>=0))[0];return"taker"===t?n.taker_base_fee:n.maker_base_fee}async marketOrder(e,t,n,a){t===o.Side.BUY&&(n=Math.floor(n/a));const i=await this.clobClient.getOrderBook(e);console.log(i);const s=await this.determineMakerOrTakerFee(e,t,n,i,a);console.log("Fee rate: "+s.fee),console.log(t),console.log("Amount of shares/tokens: "+n),console.log("Price"+a);const r=await this.clobClient.createOrder({tokenID:e,price:a,side:t,size:n,feeRateBps:s.fee,nonce:0,expiration:0});let p;return console.log(r),"taker"===s.side&&t===o.Side.BUY?p=await this.clobClient.postOrder(r,o.OrderType.FOK):("taker"===s.side&&t===o.Side.SELL||"maker"===s.side)&&(p=await this.clobClient.postOrder(r,o.OrderType.GTC)),p}async getOrderBook(e){return this.clobClient.getOrderBook(e)}async cancelAll(){const e=await this.clobClient.cancelAll();return console.log(e),e}async getApiKeys(){const e=await this.clobClient.deriveApiKey();return e.error?this.clobClient.createApiKey():e}};d=a([(0,s.Injectable)(),i("design:paramtypes",[l.ConfigService])],d),t.PolymarketService=d},832:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.AllowanceStrategy=void 0;t.AllowanceStrategy=class AllowanceStrategy{constructor(e){this.contractService=e}async execute(e){try{const t=await this.contractService.setAllowance(+e.allowance);console.log(t)}catch(e){console.error(e)}}}},733:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ApiKeysStrategy=void 0;t.ApiKeysStrategy=class ApiKeysStrategy{constructor(e){this.polymarketService=e}async execute(){const e=await this.polymarketService.getApiKeys();console.log(e)}}},719:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.BuyStrategy=void 0;const a=n(204);t.BuyStrategy=class BuyStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=e.buy[0],n=+e.buy[1],i=+e.buy[2];try{const e=await this.polymarketService.marketOrder(t,a.Side.BUY,n,i);console.log(e)}catch(e){console.error(e)}}}},943:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.CancelAllStrategy=void 0;t.CancelAllStrategy=class CancelAllStrategy{constructor(e){this.polymarketService=e}async execute(){try{await this.polymarketService.cancelAll()}catch(e){console.error(e)}}}},638:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Context=void 0;const a=n(946),i=n(719),s=n(280),r=n(832),o=n(398),p=n(943),y=n(733);t.Context=class Context{constructor(e,t){this.polymarketService=e,this.contractService=t,this.setStrategy=e=>{this.strategy=e},this.executeStrategy=e=>{this.strategy.execute(e)},this.determineStrategy=e=>{let t;return e.list&&(t=new a.ListStrategy(this.polymarketService)),e.buy&&3===e.buy.length&&(t=new i.BuyStrategy(this.polymarketService)),e.sell&&3===e.sell.length&&(t=new s.SellStrategy(this.polymarketService)),e.allowance&&(t=new r.AllowanceStrategy(this.contractService)),e.orderBook&&(t=new o.OrderBookStrategy(this.polymarketService)),e.cancelAll&&(t=new p.CancelAllStrategy(this.polymarketService)),e.keys&&(t=new y.ApiKeysStrategy(this.polymarketService)),t}}}},946:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ListStrategy=void 0;t.ListStrategy=class ListStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=await this.polymarketService.getMarketsAcceptingOrders();console.log(t.filter((t=>t.question.toLowerCase().includes(e.list.toLowerCase()))))}}},398:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.OrderBookStrategy=void 0;t.OrderBookStrategy=class OrderBookStrategy{constructor(e){this.polymarketService=e}async execute(e){try{const t=await this.polymarketService.getOrderBook(e.orderBook);console.log(t)}catch(e){console.error(e)}}}},280:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SellStrategy=void 0;const a=n(204);t.SellStrategy=class SellStrategy{constructor(e){this.polymarketService=e}async execute(e){const t=e.sell[0],n=+e.sell[1],i=+e.sell[2];try{const e=await this.polymarketService.marketOrder(t,a.Side.SELL,n,i);console.log(e)}catch(e){console.error(e)}}}},593:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.setAndExecuteStrategy=void 0;t.setAndExecuteStrategy=(e,t,n)=>{n.setStrategy(e),n.executeStrategy(t)}},498:e=>{e.exports=require("@nestjs/axios")},481:e=>{e.exports=require("@nestjs/common")},143:e=>{e.exports=require("@nestjs/core")},204:e=>{e.exports=require("@polymarket/clob-client")},509:e=>{e.exports=require("@polymarket/clob-client/dist/types")},167:e=>{e.exports=require("axios")},304:e=>{e.exports=require("commander")},982:e=>{e.exports=require("ethers")},116:e=>{e.exports=require("figlet")},147:e=>{e.exports=require("fs")},37:e=>{e.exports=require("os")},17:e=>{e.exports=require("path")},598:e=>{e.exports=JSON.parse('{"name":"pmarket-cli","version":"0.7.3","description":"CLI tool to trade on Polymarket","license":"MIT","author":{"name":"Arkadiusz Gotfryd","email":"arekgotfryd@g.pl"},"keywords":["cli","npmtool","polymarket"],"repository":"https://github.com/arekgotfryd/pmarket-cli","homepage":"https://github.com/arekgotfryd/pmarket-cli/blob/master/README.md","main":"dist/main.js","bin":{"pmarket-cli":"./dist/main.js"},"scripts":{"prebuild":"rimraf dist","build":"nest build --webpack --webpackPath webpack.config.js","format":"prettier --write \\"src/**/*.ts\\" \\"test/**/*.ts\\"","start":"nest start","start:dev":"nest start --watch","start:debug":"nest start --debug --watch","start:prod":"node dist/main","lint":"eslint src/**/*.ts --fix","test":"jest","test:watch":"jest --watch","test:cov":"jest --coverage","test:debug":"node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand","test:e2e":"echo \'No e2e tests implemented yet.\'","build:postinstall":"nest build --webpack --webpackPath webpack.postinstall.config.js","postinstall":"node ./scripts/create-config.js"},"dependencies":{"@nestjs/axios":"^2.0.0","@nestjs/common":"^9.4.2","@nestjs/core":"^9.4.2","@polymarket/clob-client":"^1.4.0","axios":"^1.3.4","commander":"^10.0.1","ethers":"^5.7.1","figlet":"^1.6.0","reflect-metadata":"0.1.13","rimraf":"3.0.2"},"devDependencies":{"@nestjs/cli":"^9.5.0","@nestjs/testing":"^9.4.2","@types/jest":"^29.5.2","@types/node":"18.0.3","@typescript-eslint/eslint-plugin":"5.30.5","@typescript-eslint/parser":"5.30.5","eslint":"8.19.0","eslint-config-prettier":"8.5.0","jest":"28.1.2","prettier":"2.7.1","ts-jest":"28.0.5","ts-loader":"9.3.1","ts-node":"10.8.2","typescript":"4.7.4","webpack-shebang-plugin":"^1.1.8"}}')}},t={};function __webpack_require__(n){var a=t[n];if(void 0!==a)return a.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,__webpack_require__),i.exports}(()=>{const e=__webpack_require__(143),t=__webpack_require__(858),n=__webpack_require__(255),a=__webpack_require__(974),i=__webpack_require__(235),s=__webpack_require__(116),r=__webpack_require__(638),o=__webpack_require__(593),p=__webpack_require__(598);!async function bootstrap(){const y=await e.NestFactory.createApplicationContext(t.AppModule,{logger:!1}),l=y.get(n.PolymarketService),u=y.get(i.ContractService);console.log(s.textSync(p.name));const c=(0,a.getProgram)();process.argv.slice(2).length||c.outputHelp();const d=c.parse(process.argv).opts(),m=new r.Context(l,u),b=m.determineStrategy(d);b&&(0,o.setAndExecuteStrategy)(b,d,m)}()})()})(); \ No newline at end of file diff --git a/src/services/polymarket.service.spec.ts b/src/services/polymarket.service.spec.ts index 1eb2a8e..1b6b21f 100644 --- a/src/services/polymarket.service.spec.ts +++ b/src/services/polymarket.service.spec.ts @@ -1,8 +1,9 @@ -import { Side } from '@polymarket/clob-client'; +import { ClobClient, OrderBookSummary, OrderType, Side } from '@polymarket/clob-client'; import { ConfigService } from './config.service'; import { PolymarketService } from './polymarket.service'; import { Test } from '@nestjs/testing'; import { ethers } from 'ethers'; +import { SignatureType, SignedOrder } from '@polymarket/order-utils'; const markets = [{ "condition_id": "0xa00a22b16d602abf9ed695404df68a71ddd4ef05573bf9590de4f0fccf096c93", @@ -78,27 +79,30 @@ const markets = [{ "taker_base_fee": 0 }] -const orderBook = { +const orderBook:OrderBookSummary = { bids: [ { - price: 0.5, - size: 100 + price: '0.5', + size: '100' }, { - price: 0.4, - size: 100 + price: '0.4', + size: '100' } ], asks: [ { - price: 0.6, - size: 100 + price: '0.6', + size: '100' }, { - price: 0.7, - size: 100 + price: '0.7', + size: '100' } - ] + ], + market: 'marketID', + asset_id: 'asset_id', + hash: 'hash' } describe('PolymarketService', () => { @@ -152,4 +156,83 @@ describe('PolymarketService', () => { expect(makerFee).toStrictEqual({ fee: 0, side: 'maker' }); }); + it('should call postOrder with BUY OrderType.FOK', async () => { + const signedOrder:SignedOrder = { + signature: '', + salt: '', + maker: '', + signer: '', + taker: '', + tokenId: '', + makerAmount: '', + takerAmount: '', + expiration: '', + nonce: '', + feeRateBps: '', + side: Side.BUY, + signatureType: SignatureType.EOA + }; + jest.spyOn(polymarketService, 'determineMakerOrTakerFee').mockImplementation(() => Promise.resolve({ fee: 0, side: 'taker' })); + + const getOrderBookSpy = jest.spyOn(ClobClient.prototype, 'getOrderBook'); + getOrderBookSpy.mockImplementation((tokenID):Promise => { + // Mocked implementation + return Promise.resolve(orderBook); + }); + + const createOrderBookSpy = jest.spyOn(ClobClient.prototype, 'createOrder'); + createOrderBookSpy.mockImplementation((userOrder):Promise => { + // Mocked implementation + return Promise.resolve(signedOrder); + }); + + const postOrderSpy = jest.spyOn(ClobClient.prototype, 'postOrder'); + postOrderSpy.mockImplementation((order,orderType,optionalParams):Promise => { + // Mocked implementation + return Promise.resolve({}); + }); + const resp = await polymarketService.marketOrder('tokenID', Side.BUY, 20, 0.50,); + expect(postOrderSpy).toHaveBeenCalledWith(signedOrder, OrderType.FOK); + postOrderSpy.mockRestore(); + createOrderBookSpy.mockRestore(); + }); + + it('should call postOrder with SELL OrderType.GTC', async () => { + const signedOrder:SignedOrder = { + signature: '', + salt: '', + maker: '', + signer: '', + taker: '', + tokenId: '', + makerAmount: '', + takerAmount: '', + expiration: '', + nonce: '', + feeRateBps: '', + side: Side.SELL, + signatureType: SignatureType.EOA + }; + + const getOrderBookSpy = jest.spyOn(ClobClient.prototype, 'getOrderBook'); + getOrderBookSpy.mockImplementation((tokenID):Promise => { + // Mocked implementation + return Promise.resolve(orderBook); + }); + + const createOrderBookSpy = jest.spyOn(ClobClient.prototype, 'createOrder'); + createOrderBookSpy.mockImplementation((userOrder):Promise => { + // Mocked implementation + return Promise.resolve(signedOrder); + }); + + const postOrderSpy = jest.spyOn(ClobClient.prototype, 'postOrder'); + postOrderSpy.mockImplementation((order,orderType,optionalParams):Promise => { + // Mocked implementation + return Promise.resolve({}); + }); + const resp = await polymarketService.marketOrder('tokenID', Side.SELL, 20, 0.50,); + expect(postOrderSpy).toHaveBeenCalledWith(signedOrder, OrderType.GTC); + }); + }); \ No newline at end of file diff --git a/src/services/polymarket.service.ts b/src/services/polymarket.service.ts index af045a8..676a97f 100644 --- a/src/services/polymarket.service.ts +++ b/src/services/polymarket.service.ts @@ -80,13 +80,11 @@ export class PolymarketService { if (sumOfSizeOfAsksWithPriceLowerThanPrice >= size) { //get taker const takerFee = await this.getFeeRateBps(tokenId, 'taker'); - // return takerFee; resp.side = 'taker'; resp.fee = takerFee; return resp; } else { const makerFee = await this.getFeeRateBps(tokenId, 'maker'); - // return makerFee; resp.side = 'maker'; resp.fee = makerFee; return resp; @@ -111,25 +109,29 @@ export class PolymarketService { tokenID, ); console.log(orderBook); - const feeRepsonse: FeeResponse = await this.determineMakerOrTakerFee(tokenID, side, amount, orderBook, price) - console.log("Fee rate: " + feeRepsonse.fee); + const feeResponse: FeeResponse = await this.determineMakerOrTakerFee(tokenID, side, amount, orderBook, price) + console.log("Fee rate: " + feeResponse.fee); console.log(side); - console.log(amount); - console.log(price); + console.log("Amount of shares/tokens: " + amount); + console.log("Price" + price); const marketOrder = await this.clobClient.createOrder({ tokenID: tokenID, price: price, side: side, size: amount, - feeRateBps: feeRepsonse.fee, + feeRateBps: feeResponse.fee, nonce: 0, expiration: 0, }); + console.log(marketOrder); let resp; - if (feeRepsonse.side === 'taker') { + if (feeResponse.side === 'taker' && side === Side.BUY) { //fill or kill resp = await this.clobClient.postOrder(marketOrder, OrderType.FOK); - } else if (feeRepsonse.side === 'maker') { + } else if (feeResponse.side === 'taker' && side === Side.SELL) { + //good till cancelled + resp = await this.clobClient.postOrder(marketOrder, OrderType.GTC); + } else if (feeResponse.side === 'maker') { //good till cancelled resp = await this.clobClient.postOrder(marketOrder, OrderType.GTC); }