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

TypeError: undefined is not a function #9

Closed
adamjerickson opened this issue Jun 29, 2015 · 2 comments
Closed

TypeError: undefined is not a function #9

adamjerickson opened this issue Jun 29, 2015 · 2 comments

Comments

@adamjerickson
Copy link

Been trying to figure out what the problem is here, but can't seem to. Command I'm running is:

bootprint swagger http://localhost:3000/orca.json html

also tried just referencing the file locally, like:

bootprint swagger orca.json html

it always errors with:

/usr/local/lib/node_modules/bootprint/node_modules/q/q.js:155
                throw e;
                      ^
TypeError: undefined is not a function
    at /usr/local/lib/node_modules/bootprint-swagger/lib/preprocessor.js:15:61
    at Array.forEach (native)
    at /usr/local/lib/node_modules/bootprint-swagger/lib/preprocessor.js:13:24
    at Array.forEach (native)
    at Object.module.exports (/usr/local/lib/node_modules/bootprint-swagger/lib/preprocessor.js:12:26)
    at /usr/local/lib/node_modules/bootprint/lib/bootprint.js:64:32
    at _fulfilled (/usr/local/lib/node_modules/bootprint/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/bootprint/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/bootprint/node_modules/q/q.js:796:13)
    at /usr/local/lib/node_modules/bootprint/node_modules/q/q.js:604:44

My JSON file is:

{
  "swagger": "2.0",
  "info": {
    "version": "1.0",
    "title": "Orca API",
    "description": "This API allows you to programmatically retrieve composed options strategies based on your forecast and market data.\n\nThis API Uses OAuth2 to control access.  All methods except the /auth methods expect a valid \"Authorization: Bearer XXXX\" header to be passed with the request.\n"
  },
  "host": "orca.trade",
  "basePath": "/Code/prod/api/public/1_0",
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "parameters": {
    "accessToken": {
      "name": "Access Token",
      "in": "header",
      "required": true,
      "type": "string",
      "description": "OAuth 2 Access token.  Send in the Authorization header as Bearer XXXXXXXX."
    },
    "symbol": {
      "name": "symbol",
      "in": "formData",
      "required": true,
      "schema": {
        "$ref": "symbol"
      },
      "description": "The underlying symbol information."
    },
    "request": {
      "name": "request",
      "in": "formData",
      "required": true,
      "schema": {
        "$ref": "request"
      },
      "description": "The forecast and other information needed when requesting strategies."
    },
    "optionChain": {
      "name": "optionChain",
      "in": "formData",
      "required": true,
      "schema": {
        "$ref": "optionChain"
      },
      "description": "The quoted option chain provided when requesting strategies."
    }
  },
  "paths": {
    "/auth/login": {
      "get": {
        "summary": "Redirects to login page for OAuth2 login",
        "description": "Redirects to https://www.orca.trade/oauth/login"
      }
    },
    "/auth/getLoginUrl": {
      "get": {
        "summary": "Returns OAuth2 Login URL",
        "description": "Returns \"url\":\"https://www.orca.trade/oauth/login\""
      }
    },
    "/auth/getToken": {
      "post": {
        "summary": "Exchange an Auth Code for an Access Token",
        "parameters": {
          "authCode": "The authorization code returned from the OAuth2 signin process"
        },
        "responses": {
          "200": {
            "description": "Returns the token in the body of the request as JSON. \"token\":\"12345678990\""
          }
        }
      }
    },
    "/market/preloadOptionChain/{symbol}": {
      "get": {
        "summary": "Preload an option chain on the server (server contacts your UI).",
        "description": "Informs the server what symbol you're using and asks it to retrieve a static option chain from your the API.  This makes the subsequent retrieval of strategies significantly faster.  \n\nThe endpoint from which the market data is retrieved is determined by the account information attached to the user's access token, and is set up by calling Orca customer support.\n",
        "parameters": [
          {
            "name": "symbol",
            "in": "path",
            "required": true,
            "description": "The underlying symbol code.  (E.g. \"AAPL\")",
            "type": "string"
          }
        ]
      },
      "post": {
        "summary": "Preload an option chain on the server (you supply the option chain as JSON data).",
        "description": "Send a quoted option chain to the server, for the server to use on subsequent strategy requests.  Chain will be cached for two (2) minutes and used by any other users from your organization.  This makes the subsequent retrieval of strategies significantly faster.  \n\nThe endpoint from which the market data is retrieved is determined by the account information attached to the user's access token, and is set up by calling Orca customer support.\n",
        "responses": {
          "200": {
            "description": "true (option chain loaded successfully)"
          },
          "401": {
            "description": "no stream endpoint set for this user's account."
          },
          "403": {
            "description": "Invalid auth key"
          },
          "500": {
            "description": "Other Error. Specified with status:\"failed\", error: \"error text here\"\n",
            "schema": {
              "type": "object",
              "$ref": "error"
            }
          }
        }
      }
    },
    "/market/stream/{symbol}": {
      "get": {
        "summary": "Tell the server to start streaming data about the given symbol.",
        "description": "Informs the server what symbol you're using, and tells it to start streaming data from your API.  This makes the subsequent retrieval of strategies significantly faster.  \n\nUse this instead of preloadOptionChain if you have a fast-moving symbol, or have many users who may request this symbol (e.g. a popular one, like AAPL).\n\nThe endpoint from which the market data is retrieved is determined by the account information attached to the user's access token, and is set up by calling Orca customer support.\n",
        "parameters": [
          {
            "name": "symbol",
            "in": "path",
            "required": true,
            "description": "The underlying symbol code.  (E.g. \"AAPL\")",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "true (successful stream start)"
          },
          "401": {
            "description": "no stream endpoint set for this user's account."
          },
          "403": {
            "description": "Invalid auth key"
          },
          "500": {
            "description": "Other Error. Specified with status:\"failed\", error: \"error text here\"\n",
            "schema": {
              "type": "object",
              "$ref": "error"
            }
          }
        }
      }
    },
    "/core/strategies/{symbol}/{amount}/{price}/{date}/{useIv}/{iv}/{uprice}/{username}/{oaLevel}/{accountType}": {
      "get": {
        "summary": "Returns composed strategies for the given forecast.",
        "description": "Only use this if you have previously called *preloadOptionChain* or *stream*.  Otherwise use the POST method to pass everything at once.",
        "parameters": [
          {
            "name": "symbol",
            "in": "path",
            "required": true,
            "description": "The underlying symbol code.  (E.g. \"AAPL\")",
            "type": "string"
          },
          {
            "name": "amount",
            "in": "path",
            "required": true,
            "description": "The amount you are willing to commit to the trade.",
            "type": "float",
            "format": "two-digit precision"
          },
          {
            "name": "price",
            "in": "path",
            "required": true,
            "description": "The forecast price (what price you believe the stock will be on the forecast data)",
            "type": "float",
            "format": "two-digit precision"
          },
          {
            "name": "date",
            "in": "path",
            "required": true,
            "description": "The forecast date (at which date you believe the stock will reach the forecast price).",
            "type": "date",
            "format": "YYYY-MM-DD"
          },
          {
            "name": "useIv",
            "in": "path",
            "required": true,
            "description": "Pass true or false.  Tells the server whether to pay attention to the next parameter (iv).",
            "type": "boolean"
          },
          {
            "name": "iv",
            "in": "path",
            "requred": true,
            "description": "The forecasted implied volatility. If you passed useIv=false then this value is ignored, but passing 0 is conventional.",
            "type": "float",
            "format": "two-digit precision"
          },
          {
            "name": "uprice",
            "in": "path",
            "required": true,
            "description": "The current price of the underlying.",
            "type": "float",
            "format": "two-digit precision"
          },
          {
            "name": "username",
            "in": "path",
            "required": true,
            "description": "The Orca username of the current user. !!$$$ This needs to go away, we can get the user from their auth token!!$$$.",
            "type": "string"
          },
          {
            "name": "oaLevel",
            "in": "path",
            "required": true,
            "description": "The Option Approval level of the current user on a 1-5 scale.\n1: Covered calls\n2: XXX\n3: XXX\n4: XXX\n5: All option strategies\n",
            "type": "integer",
            "enum": [
              1,
              2,
              3,
              4,
              5
            ]
          },
          {
            "name": "accountType",
            "in": "path",
            "required": true,
            "description": "Type of account you will use to trade these strategies (margin or cash).",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Array of composed strategies",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "strategy"
              }
            }
          },
          "403": {
            "description": "Invalid auth key"
          },
          "500": {
            "description": "Other Error. Specified with status:\"failed\", error: \"error text here\"\n",
            "schema": {
              "type": "object",
              "$ref": "error"
            }
          }
        }
      }
    },
    "/core/strategies": {
      "post": {
        "summary": "Returns strategies for the given request(forecast), symbol, and option chain.",
        "description": null,
        "parameters": [
          {
            "name": "request",
            "in": "formData",
            "required": true,
            "schema": {
              "$ref": "request"
            },
            "description": "The forecast and other information needed when requesting strategies."
          },
          {
            "name": "symbol",
            "in": "formData",
            "required": true,
            "schema": {
              "$ref": "symbol"
            },
            "description": "The underlying symbol information."
          },
          {
            "name": "optionChain",
            "in": "formData",
            "required": true,
            "schema": {
              "$ref": "optionChain"
            },
            "description": "The quoted option chain provided when requesting strategies."
          }
        ],
        "responses": {
          "200": {
            "description": "The composed strategies",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "strategy"
              }
            }
          },
          "403": {
            "description": "Invalid auth key"
          },
          "500": {
            "description": "Other Error. Specified with status:\"failed\", error: \"error text here\"\n",
            "schema": {
              "type": "object",
              "$ref": "error"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "error": {
      "description": "an error object",
      "required": [
        "status",
        "error"
      ],
      "properties": {
        "status": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20,
          "pattern": "^failed|success",
          "description": "failed/success flag"
        },
        "error": {
          "type": "string",
          "minLength": 0,
          "description": "A detailed description of the error."
        }
      },
      "example": {
        "status": "failed",
        "error": "No streaming endpoint for brokerage."
      }
    },
    "option": {
      "description": "an option",
      "required": [
        "ask",
        "bid",
        "strike",
        "daysToExpiry",
        "quantity",
        "opcode",
        "call_or_put",
        "volume",
        "opeinInterest",
        "itheta",
        "symbol",
        "id"
      ],
      "properties": {
        "ask": {
          "type": "number",
          "description": "latest ask price in decimal format (two-digit precision)"
        },
        "bid": {
          "type": "number",
          "description": "latest bid price in decimal format (two-digit precision)"
        },
        "price": {
          "type": "number",
          "description": "latest average price in decimal format (two-digit precision)"
        },
        "strike": {
          "type": "number",
          "description": "strike price price in decimal format (two-digit precision)"
        },
        "daysToExpiry": {
          "type": "integer",
          "description": "Whole or partial days left until the expiry of the option.  If today is the expiry date then daysToExpiry = 1."
        },
        "quantity": {
          "type": "integer",
          "description": "Number of units of this option to buy or sell to create one strategy.  Negative numbers indicate selling the option, positive numbers buying.  \n\nExample -  In a bull call vertical spread, the lower strike would have a positive 1 quantity, and the higher a -1 quantity.\n"
        },
        "opcode": {
          "type": "string",
          "description": "The option symbol in OCC format.  (E.g.: LAMR150117C00052500)\n"
        },
        "call_or_put": {
          "type": "string",
          "description": "C for call, P for put, U for an underlying leg (present in covered calls and collars)\n"
        },
        "volume": {
          "type": "integer",
          "description": "daily trade volume"
        },
        "openInterest": {
          "type": "integer",
          "description": "the total number of option contracts that are currently open for this option - in other words, contracts that have been traded but not yet liquidated by either an offsetting trade or an exercise or assignment\n"
        },
        "itheta": {
          "type": "number",
          "description": "the rate of decline in the value of an option due to the passage of time) for the option."
        },
        "symbol": {
          "type": "string",
          "description": "The underlying symbol for this option.  E.g. \"AAPL\"."
        },
        "id": {
          "description": "same as opcode"
        }
      }
    },
    "optionChain": {
      "description": "an option chain for a single underlying",
      "required": [
        "optionChain"
      ],
      "properties": {
        "optionChain": {
          "description": "An array of option objects representing all tradeable options for a given underlying symbol.",
          "type": "array",
          "items": [
            {
              "$ref": "option"
            }
          ]
        }
      }
    },
    "symbol": {
      "description": "represents an underlying symbol used in a POST /strategies request",
      "required": [
        "ask",
        "bid",
        "last",
        "symbol"
      ],
      "properties": {
        "ask": {
          "description": "latest ask price for the underlying in decimal format (two-digit precision)",
          "type": "number"
        },
        "bid": {
          "description": "latest bid price for the underlying in decimal format (two-digit precision)",
          "type": "number"
        },
        "last": {
          "description": "latest average price for the underlying in decimal format (two-digit precision)",
          "type": "number"
        },
        "symbol": {
          "description": "the underlying symbol code (e.g. \"AAPL\" or \"GM\")",
          "type": "string"
        }
      }
    },
    "strategiesRequest": {
      "description": "forecast and related data used to request strategies",
      "required": [
        "price",
        "date",
        "useIv",
        "iv"
      ],
      "properties": {
        "ask": {
          "description": "the latest ask price for the underlying",
          "type": "number"
        },
        "bid": {
          "description": "the latest bid price for the underlying",
          "type": "number"
        },
        "last": {
          "description": "the latest average price for the underlying",
          "type": "number"
        },
        "symbol": {
          "description": "the underlying symbol code (e.g. \"AAPL\" or \"GM\")",
          "type": "string"
        }
      }
    },
    "strategy": {
      "description": "an individual strategy result",
      "properties": {
        "strategy": {
          "description": "The name of the strategy, in Orca nomenclature.\n"
        },
        "composition": {
          "description": "The makeup of the strategy.  See JSON for more detail.",
          "type": "array",
          "items": [
            {
              "properties": null,
              "strategy": {
                "type": "string",
                "description": "The name of the strategy, in Orca nomenclature.\n"
              },
              "profitTarget": {
                "type": "number",
                "description": "The expected profit for this strategy if the underlying hits the forecast price on the forecast day"
              },
              "amount": {
                "type": "number",
                "description": "The estimated total cost of the strategy, including commissions.  Usually negative.\n"
              },
              "comissionTotal": {
                "type": "number",
                "description": "The estimated total commissions.  Ususally negative."
              },
              "strategyQuantity": {
                "type": "string",
                "description": "The number of strategies possible to put on for \"amount\"."
              },
              "uPrice": {
                "type": "number",
                "description": "The underlying price used in to create this strategy."
              },
              "iv": {
                "type": "number",
                "description": "The underlying implied volatility used to create this strategy"
              },
              "fPrice": {
                "type": "number",
                "description": "The forecast price used to create this strategy"
              },
              "fDays": {
                "type": "number",
                "description": "The number of whole or partial days from today that the given forecast day represents.  If it is 1pm on 1/1/2016 and the forecast date is 1/2/2016, fDays = 1.  If it is 1pm on 1/1/2016 and the forecast date is 1/15/2016, fDays = 16.\n"
              },
              "fIV": {
                "type": "number",
                "description": "The implied volatility forecasted by the user, if any.\n"
              },
              "nodes": {
                "description": "The array of the individual legs that make up this strategy.",
                "items": [
                  {
                    "$ref": "option"
                  }
                ]
              }
            }
          ]
        }
      }
    },
    "strategiesResponse": {
      "description": "An array of strategies returned from a strategiesRequest",
      "properties": {
        "results": {
          "description": "An array of strategy objects.",
          "type": "array",
          "items": [
            {
              "$ref": "strategy"
            }
          ]
        }
      }
    },
    "request": {
      "description": "forecast and related data used to request strategies",
      "required": [
        "username",
        "brokerage",
        "accountType",
        "optionApprovalLevel",
        "forecast"
      ],
      "properties": {
        "username": {
          "description": "the latest ask price for the underlying. Decimal with 2-digit precision.",
          "type": "string"
        },
        "brokerage": {
          "description": "the latest bid price for the underlying. Decimal with 2-digit precision.",
          "type": "string"
        },
        "accountType": {
          "description": "either \"cash\" or \"margin\"",
          "type": "string"
        },
        "forecast": {
          "$ref": "forecast"
        }
      },
      "example": {
        "request": {
          "username": "adamjerickson",
          "brokerage": "eSignal",
          "accountType": "margin",
          "optionApprovalLevel": 5,
          "forecast": {
            "price": 123.12,
            "date": 20151225,
            "amount": 12345.56,
            "useIv": true,
            "iv": 0.32
          }
        }
      }
    },
    "forecast": {
      "description": "A trader's market sentiment.",
      "required": [
        "price",
        "date",
        "amount",
        "useIv"
      ],
      "properties": {
        "price": {
          "type": "number",
          "description": "the price the trader believes the stock will reach.  This is a nominal value, not relative to the current price.\n"
        },
        "date": {
          "type": "date",
          "format": "YYYYMMDD",
          "description": "the date upon which the trader believes the stock will reach the forecasted price."
        },
        "amount": {
          "type": "number",
          "description": "the amount the user is willing to commit to the trade.  Used to calculate strategy quantity, and in some cases, filter out strategies that are too expensive.\n"
        },
        "useIv": {
          "type": "boolean",
          "description": "true|false.  Whether to use the implied volatility given below."
        },
        "iv": {
          "type": "number",
          "description": "the forecasted implied volatility over the forecast period"
        }
      },
      "example": {
        "forecast": {
          "price": 123.12,
          "date": 20151225,
          "amount": 12345.56,
          "useIv": true,
          "iv": 0.32
        }
      }
    }
  }
}
@nknapp
Copy link
Member

nknapp commented Jun 30, 2015

Are you using the latest version of bootprint-swagger and bootprint?
bootprint --version should print 0.5.1 and the normal output of bootprint swagger orca.json html
should print

Loading bootprint-swagger 0.6.0
Loading bootprint-json-schema 0.5.0
Loading bootprint-base 0.4.0

I'm asking because I've tried to reproduce the error and I get a different one:

Loading bootprint-swagger 0.6.0
Loading bootprint-json-schema 0.5.0
Loading bootprint-base 0.4.0

/home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint/node_modules/q/q.js:155
                throw e;
                      ^
TypeError: Object #<Object> has no method 'filter'
    at /home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint-swagger/lib/preprocessor.js:15:61
    at Array.forEach (native)
    at /home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint-swagger/lib/preprocessor.js:13:24
    at Array.forEach (native)
    at Object.module.exports (/home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint-swagger/lib/preprocessor.js:12:26)
    at /home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint/lib/bootprint.js:64:32
    at _fulfilled (/home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint/node_modules/q/q.js:834:54)
    at self.promiseDispatch.done (/home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint/node_modules/q/q.js:863:30)
    at Promise.promise.promiseDispatch (/home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint/node_modules/q/q.js:796:13)
    at /home/nknappmeier/programs/node/node-v0.10.26-linux-x64/lib/node_modules/bootprint/node_modules/q/q.js:604:44

Now, the error I'm getting comes from an the parameter definition of /auth/getToken.post, where the parameter-properties contains an object but it should be an array.
Also, the global parameter definitions are not printed out at the moment.

I have create issues #10 (support global paramater definitions) and #11 (to print a better exception)

@adamjerickson
Copy link
Author

Thanks, that parameter definition was indeed the issue. I made it an array with an object inside and it worked. I'm on OS X rather than Linux, so perhaps that's why the different error message.

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

No branches or pull requests

2 participants