diff --git a/config.yml b/config.yml index 1d4c663..4c4a544 100644 --- a/config.yml +++ b/config.yml @@ -51,6 +51,7 @@ interfaces: - name: "since_transaction_id" type: "string" doc: "ID of the Transaction to get Account changes since." + required: true - module_name: "Instruments" description: "Interface for Oanda instruments." functions: @@ -100,16 +101,6 @@ interfaces: type: "string" doc: "The day of the week used for granularities that have weekly alignment." default: "Friday" - - description: "Get position book data for an instrument." - http_method: "GET" - path: "/instruments/:instrument/positionBook" - arguments: - - "instrument" - parameters: - - name: "time" - type: "string" - doc: "The time of the snapshot to fetch using either RFC 3339 or Unix format. If not specified, then the most recent snapshot is fetched." - module_name: "Orders" description: "Interface for Oanda orders." functions: diff --git a/lib/models/definitions/account/account_summary.ex b/lib/models/definitions/account/account_summary.ex index 180fe08..0272c50 100644 --- a/lib/models/definitions/account/account_summary.ex +++ b/lib/models/definitions/account/account_summary.ex @@ -15,7 +15,7 @@ defmodule ExOanda.AccountSummary do field(:currency, :string) field(:created_by_user_id, :integer) field(:created_time, :utc_datetime_usec) - field(:resettabled_pl_time, :utc_datetime_usec) + field(:resettable_pl_time, :utc_datetime_usec) field(:margin_rate, :float) field(:open_trade_count, :integer) field(:open_position_count, :integer) @@ -54,7 +54,7 @@ defmodule ExOanda.AccountSummary do def changeset(struct, params) do struct |> cast(params, [ - :id, :alias, :currency, :created_by_user_id, :created_time, :resettabled_pl_time, + :id, :alias, :currency, :created_by_user_id, :created_time, :resettable_pl_time, :margin_rate, :open_trade_count, :open_position_count, :pending_order_count, :hedging_enabled, :unrealized_pl, :nav, :margin_used, :margin_available, :position_value, :margin_closeout_unrealized_pl, :margin_closeout_nav, @@ -66,7 +66,7 @@ defmodule ExOanda.AccountSummary do ]) |> cast_embed(:guaranteed_stop_loss_order_parameters) |> validate_required([ - :id, :alias, :currency, :created_by_user_id, :created_time, :resettabled_pl_time, + :id, :alias, :currency, :created_by_user_id, :created_time, :resettable_pl_time, :margin_rate, :open_trade_count, :open_position_count, :pending_order_count, :hedging_enabled, :unrealized_pl, :nav, :margin_used, :margin_available, :position_value, :margin_closeout_unrealized_pl, :margin_closeout_nav, diff --git a/lib/models/response/accounts/update_account.ex b/lib/models/response/accounts/update_account.ex index 12b1b35..ece0a3a 100644 --- a/lib/models/response/accounts/update_account.ex +++ b/lib/models/response/accounts/update_account.ex @@ -16,15 +16,13 @@ defmodule ExOanda.Response.UpdateAccount do embeds_one :client_configure_transaction, ClientConfigureTransaction embeds_one :client_configure_reject_transaction, ClientConfigureRejectTransaction - field(:error_code, :string) - field(:error_message, :string) field(:last_transaction_id, :string) end @doc false def changeset(struct, params) do struct - |> cast(params, [:error_code, :error_message, :last_transaction_id]) + |> cast(params, [:last_transaction_id]) |> cast_embed(:client_configure_transaction) |> cast_embed(:client_configure_reject_transaction) end diff --git a/lib/models/response/error.ex b/lib/models/response/error.ex deleted file mode 100644 index 8b951f4..0000000 --- a/lib/models/response/error.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule ExOanda.Error do - @moduledoc """ - Standard error wrapper - """ - - use TypedEctoSchema - import Ecto.Changeset - - @primary_key false - - typed_embedded_schema do - field(:error_code, :string) - field(:error_message, :string) - end - - @doc false - def changeset(struct, params) do - struct - |> cast(params, [:error_code, :error_message]) - end -end diff --git a/lib/models/response/orders/cancel_order.ex b/lib/models/response/orders/cancel_order.ex index 6e2774a..ba4a1c6 100644 --- a/lib/models/response/orders/cancel_order.ex +++ b/lib/models/response/orders/cancel_order.ex @@ -17,14 +17,12 @@ defmodule ExOanda.Response.CancelOrder do embeds_one :order_cancel_reject_transaction, OrderCancelRejectTransaction field(:related_transaction_ids, {:array, :string}) field(:last_transaction_id, :string) - field(:error_code, :string) - field(:error_message, :string) end @doc false def changeset(struct, params) do struct - |> cast(params, [:related_transaction_ids, :last_transaction_id, :error_code, :error_message]) + |> cast(params, [:related_transaction_ids, :last_transaction_id]) |> cast_embed(:order_cancel_transaction) |> cast_embed(:order_cancel_reject_transaction) end diff --git a/lib/models/response/orders/create_order.ex b/lib/models/response/orders/create_order.ex index 284407e..32001c6 100644 --- a/lib/models/response/orders/create_order.ex +++ b/lib/models/response/orders/create_order.ex @@ -21,8 +21,6 @@ defmodule ExOanda.Response.CreateOrder do embeds_one :order_reissue_reject_transaction, Transaction embeds_one :order_reject_transaction, Transaction - field(:error_code, :string) - field(:error_message, :string) field(:related_transaction_ids, {:array, :string}) field(:last_transaction_id, :string) end @@ -30,7 +28,7 @@ defmodule ExOanda.Response.CreateOrder do @doc false def changeset(struct, params) do struct - |> cast(params, [:error_code, :error_message, :related_transaction_ids, :last_transaction_id]) + |> cast(params, [:related_transaction_ids, :last_transaction_id]) |> cast_embed(:order_create_transaction) |> cast_embed(:order_fill_transaction) |> cast_embed(:order_cancel_transaction) diff --git a/lib/models/response/orders/modify_client_extensions.ex b/lib/models/response/orders/modify_client_extensions.ex index a1f0ac3..836294d 100644 --- a/lib/models/response/orders/modify_client_extensions.ex +++ b/lib/models/response/orders/modify_client_extensions.ex @@ -15,8 +15,6 @@ defmodule ExOanda.Response.OrderModifyClientExtensions do typed_embedded_schema do field(:related_transaction_ids, {:array, :string}) field(:last_transaction_id, :string) - field(:error_code, :string) - field(:error_message, :string) embeds_one :order_client_extensions_modify_transaction, OrderClientExtensionsModifyTransaction embeds_one :order_client_extensions_modify_reject_transaction, OrderClientExtensionsModifyRejectTransaction @@ -25,7 +23,7 @@ defmodule ExOanda.Response.OrderModifyClientExtensions do @doc false def changeset(struct, params) do struct - |> cast(params, [:related_transaction_ids, :last_transaction_id, :error_code, :error_message]) + |> cast(params, [:related_transaction_ids, :last_transaction_id]) |> cast_embed(:order_client_extensions_modify_transaction) |> cast_embed(:order_client_extensions_modify_reject_transaction) end diff --git a/lib/models/response/orders/replace_order.ex b/lib/models/response/orders/replace_order.ex index 34696c6..5e9f66b 100644 --- a/lib/models/response/orders/replace_order.ex +++ b/lib/models/response/orders/replace_order.ex @@ -23,8 +23,6 @@ defmodule ExOanda.Response.ReplaceOrder do embeds_one :order_reject_transaction, Transaction embeds_one :order_cancel_reject_transaction, Transaction - field(:error_code, :string) - field(:error_message, :string) field(:related_transaction_ids, {:array, :string}) field(:last_transaction_id, :string) end diff --git a/lib/models/response/positions/close_position.ex b/lib/models/response/positions/close_position.ex index a5c7fda..d4546c7 100644 --- a/lib/models/response/positions/close_position.ex +++ b/lib/models/response/positions/close_position.ex @@ -17,8 +17,6 @@ defmodule ExOanda.Response.ClosePosition do typed_embedded_schema do field(:related_transaction_ids, {:array, :string}) field(:last_transaction_id, :string) - field(:error_code, :string) - field(:error_message, :string) embeds_one :long_order_create_transaction, MarketOrderTransaction embeds_one :long_order_fill_transaction, OrderFillTransaction @@ -33,7 +31,7 @@ defmodule ExOanda.Response.ClosePosition do @doc false def changeset(struct, params) do struct - |> cast(params, [:related_transaction_ids, :last_transaction_id, :error_code, :error_message]) + |> cast(params, [:related_transaction_ids, :last_transaction_id]) |> cast_embed(:long_order_create_transaction) |> cast_embed(:long_order_fill_transaction) |> cast_embed(:long_order_cancel_transaction) diff --git a/lib/models/response/response.ex b/lib/models/response/response.ex index 9999dd8..90e32be 100644 --- a/lib/models/response/response.ex +++ b/lib/models/response/response.ex @@ -17,12 +17,14 @@ defmodule ExOanda.Response do field(:data, MapOrList) field(:request_id, :string) field(:status, Atom) + field(:error_code, :string) + field(:error_message, :string) end @doc false def changeset(struct, params) do struct - |> cast(params, [:data, :request_id, :status]) + |> cast(params, [:data, :request_id, :status, :error_code, :error_message]) |> validate_required([:data, :request_id, :status]) end end diff --git a/lib/models/response/trades/close_trade.ex b/lib/models/response/trades/close_trade.ex index fd7fe86..30dd686 100644 --- a/lib/models/response/trades/close_trade.ex +++ b/lib/models/response/trades/close_trade.ex @@ -17,8 +17,6 @@ defmodule ExOanda.Response.CloseTrade do typed_embedded_schema do field(:related_transaction_ids, {:array, :string}) field(:last_transaction_id, :string) - field(:error_code, :string) - field(:error_message, :string) embeds_one :order_create_transaction, MarketOrderTransaction embeds_one :order_fill_transaction, OrderFillTransaction @@ -29,7 +27,7 @@ defmodule ExOanda.Response.CloseTrade do @doc false def changeset(struct, params) do struct - |> cast(params, [:related_transaction_ids, :last_transaction_id, :error_code, :error_message]) + |> cast(params, [:related_transaction_ids, :last_transaction_id]) |> cast_embed(:order_create_transaction) |> cast_embed(:order_fill_transaction) |> cast_embed(:order_cancel_transaction) diff --git a/lib/models/response/trades/modify_client_extensions.ex b/lib/models/response/trades/modify_client_extensions.ex index 4ada45d..df3f52b 100644 --- a/lib/models/response/trades/modify_client_extensions.ex +++ b/lib/models/response/trades/modify_client_extensions.ex @@ -15,8 +15,6 @@ defmodule ExOanda.Response.TradeModifyClientExtensions do typed_embedded_schema do field(:related_transaction_ids, {:array, :string}) field(:last_transaction_id, :string) - field(:error_code, :string) - field(:error_message, :string) embeds_one :trade_client_extensions_modify_transaction, TradeClientExtensionsModifyTransaction embeds_one :trade_client_extensions_modify_reject_transaction, TradeClientExtensionsModifyRejectTransaction @@ -25,7 +23,7 @@ defmodule ExOanda.Response.TradeModifyClientExtensions do @doc false def changeset(struct, params) do struct - |> cast(params, [:related_transaction_ids, :last_transaction_id, :error_code, :error_message]) + |> cast(params, [:related_transaction_ids, :last_transaction_id]) |> cast_embed(:trade_client_extensions_modify_transaction) |> cast_embed(:trade_client_extensions_modify_reject_transaction) end diff --git a/lib/models/response/trades/update_trade.ex b/lib/models/response/trades/update_trade.ex index d284394..56f940d 100644 --- a/lib/models/response/trades/update_trade.ex +++ b/lib/models/response/trades/update_trade.ex @@ -44,8 +44,6 @@ defmodule ExOanda.Response.UpdateTrade do embeds_one :guaranteed_stop_loss_order_cancel_reject_transaction, OrderCancelRejectTransaction embeds_one :guaranteed_stop_loss_order_reject_transaction, GuaranteedStopLossOrderRejectTransaction - field(:error_code, :string) - field(:error_message, :string) field(:related_transaction_ids, {:array, :string}) field(:last_transaction_id, :string) end @@ -53,7 +51,7 @@ defmodule ExOanda.Response.UpdateTrade do @doc false def changeset(struct, params) do struct - |> cast(params, [:related_transaction_ids, :last_transaction_id, :error_code, :error_message]) + |> cast(params, [:related_transaction_ids, :last_transaction_id]) |> cast_embed(:take_profit_order_cancel_transaction) |> cast_embed(:take_profit_order_transaction) |> cast_embed(:take_profit_order_fill_transaction) diff --git a/lib/util/transform.ex b/lib/util/transform.ex index 1e02133..b9e4061 100644 --- a/lib/util/transform.ex +++ b/lib/util/transform.ex @@ -33,7 +33,23 @@ defmodule ExOanda.Transform do |> Map.get("requestid", []) |> List.first() - %{"data" => data, "status" => status, "request_id" => request_id} + error_code = + response + |> Map.get(:body, %{}) + |> Map.get("errorCode", nil) + + error_message = + response + |> Map.get(:body, %{}) + |> Map.get("errorMessage", nil) + + %{ + "data" => data, + "status" => status, + "request_id" => request_id, + "error_code" => error_code, + "error_message" => error_message + } end @spec preprocess_data(nil | atom(), map()) :: [Ecto.Schema.t()] | [map()] | Ecto.Schema.t() | map()