Class: IGMarkets::DealingPlatform
- Inherits:
-
Object
- Object
- IGMarkets::DealingPlatform
- Defined in:
- lib/ig_markets/dealing_platform.rb,
lib/ig_markets/dealing_platform/market_methods.rb,
lib/ig_markets/dealing_platform/account_methods.rb,
lib/ig_markets/dealing_platform/position_methods.rb,
lib/ig_markets/dealing_platform/streaming_methods.rb,
lib/ig_markets/dealing_platform/watchlist_methods.rb,
lib/ig_markets/dealing_platform/working_order_methods.rb,
lib/ig_markets/dealing_platform/client_sentiment_methods.rb,
lib/ig_markets/dealing_platform/sprint_market_position_methods.rb
Overview
This is the primary class for interacting with the IG Markets API. After signing in using #sign_in most functionality can be accessed using the following methods:
See ‘README.md` for code examples.
If any errors occur while executing requests to the IG Markets API then an IGMarketsError subclass will be raised.
Defined Under Namespace
Classes: AccountMethods, ClientSentimentMethods, MarketMethods, PositionMethods, SprintMarketPositionMethods, StreamingMethods, WatchlistMethods, WorkingOrderMethods
Instance Attribute Summary collapse
-
#account ⇒ AccountMethods
readonly
Methods for working with the balances and history of the logged in account.
-
#client_account_summary ⇒ ClientAccountSummary
readonly
The summary of the client account that is returned as part of a successful sign in.
-
#client_sentiment ⇒ ClientSentimentMethods
readonly
Methods for working with client sentiment.
-
#markets ⇒ MarketMethods
readonly
Methods for working with markets.
-
#positions ⇒ PositionMethods
readonly
Methods for working with positions.
-
#session ⇒ Session
readonly
The session used by this dealing platform.
-
#sprint_market_positions ⇒ SprintMarketPositionMethods
readonly
Methods for working with sprint market positions.
-
#streaming ⇒ StreamingMethods
readonly
Methods for working with live streaming of IG Markets data.
-
#watchlists ⇒ WatchlistMethods
readonly
Methods for working with watchlists.
-
#working_orders ⇒ WorkingOrderMethods
readonly
Methods for working with working orders.
Instance Method Summary collapse
-
#applications ⇒ Array<Application>
Returns details on the IG Markets applications for the accounts associated with this login.
-
#deal_confirmation(deal_reference) ⇒ DealConfirmation
Returns a full deal confirmation for the specified deal reference.
-
#disable_api_key ⇒ Application
Disables the API key currently being used by the logged in session.
-
#initialize ⇒ DealingPlatform
constructor
A new instance of DealingPlatform.
-
#instantiate_models(model_class, source) ⇒ nil, ...
This method is used to instantiate the various ‘Model` subclasses from data returned by the IG Markets API.
-
#instantiate_models_from_json(model_class, json) ⇒ nil, `model_class`
This method is the same as #instantiate_models but takes an unparsed JSON string as its input.
-
#sign_in(username, password, api_key, platform) ⇒ ClientAccountSummary
Signs in to the IG Markets Dealing Platform, either the live platform or the demo platform.
-
#sign_out ⇒ Object
Signs out of the IG Markets Dealing Platform, ending any current session.
Constructor Details
#initialize ⇒ DealingPlatform
Returns a new instance of DealingPlatform.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ig_markets/dealing_platform.rb', line 68 def initialize @session = Session.new @account = AccountMethods.new self @client_sentiment = ClientSentimentMethods.new self @markets = MarketMethods.new self @positions = PositionMethods.new self @sprint_market_positions = SprintMarketPositionMethods.new self @watchlists = WatchlistMethods.new self @working_orders = WorkingOrderMethods.new self @streaming = StreamingMethods.new self end |
Instance Attribute Details
#account ⇒ AccountMethods (readonly)
Methods for working with the balances and history of the logged in account.
31 32 33 |
# File 'lib/ig_markets/dealing_platform.rb', line 31 def account @account end |
#client_account_summary ⇒ ClientAccountSummary (readonly)
The summary of the client account that is returned as part of a successful sign in.
26 27 28 |
# File 'lib/ig_markets/dealing_platform.rb', line 26 def client_account_summary @client_account_summary end |
#client_sentiment ⇒ ClientSentimentMethods (readonly)
Methods for working with client sentiment.
36 37 38 |
# File 'lib/ig_markets/dealing_platform.rb', line 36 def client_sentiment @client_sentiment end |
#markets ⇒ MarketMethods (readonly)
Methods for working with markets.
41 42 43 |
# File 'lib/ig_markets/dealing_platform.rb', line 41 def markets @markets end |
#positions ⇒ PositionMethods (readonly)
Methods for working with positions.
46 47 48 |
# File 'lib/ig_markets/dealing_platform.rb', line 46 def positions @positions end |
#session ⇒ Session (readonly)
The session used by this dealing platform.
21 22 23 |
# File 'lib/ig_markets/dealing_platform.rb', line 21 def session @session end |
#sprint_market_positions ⇒ SprintMarketPositionMethods (readonly)
Methods for working with sprint market positions.
51 52 53 |
# File 'lib/ig_markets/dealing_platform.rb', line 51 def sprint_market_positions @sprint_market_positions end |
#streaming ⇒ StreamingMethods (readonly)
Methods for working with live streaming of IG Markets data.
66 67 68 |
# File 'lib/ig_markets/dealing_platform.rb', line 66 def streaming @streaming end |
#watchlists ⇒ WatchlistMethods (readonly)
Methods for working with watchlists.
56 57 58 |
# File 'lib/ig_markets/dealing_platform.rb', line 56 def watchlists @watchlists end |
#working_orders ⇒ WorkingOrderMethods (readonly)
Methods for working with working orders.
61 62 63 |
# File 'lib/ig_markets/dealing_platform.rb', line 61 def working_orders @working_orders end |
Instance Method Details
#applications ⇒ Array<Application>
Returns details on the IG Markets applications for the accounts associated with this login.
117 118 119 |
# File 'lib/ig_markets/dealing_platform.rb', line 117 def applications instantiate_models Application, session.get('operations/application') end |
#deal_confirmation(deal_reference) ⇒ DealConfirmation
Returns a full deal confirmation for the specified deal reference.
110 111 112 |
# File 'lib/ig_markets/dealing_platform.rb', line 110 def deal_confirmation(deal_reference) instantiate_models DealConfirmation, session.get("confirms/#{deal_reference}") end |
#disable_api_key ⇒ Application
Disables the API key currently being used by the logged in session. This means that any further requests to the IG Markets API with this key will raise Errors::APIKeyDisabledError. Disabled API keys can only be re-enabled through the web platform.
126 127 128 |
# File 'lib/ig_markets/dealing_platform.rb', line 126 def disable_api_key instantiate_models Application, session.put('operations/application/disable') end |
#instantiate_models(model_class, source) ⇒ nil, ...
This method is used to instantiate the various ‘Model` subclasses from data returned by the IG Markets API. It recurses through arrays and sub-hashes present in `source`, instantiating the required models based on the types of each attribute as defined on the models. All model instances returned by this method will have their `@dealing_platform` instance variable set.
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/ig_markets/dealing_platform.rb', line 145 def instantiate_models(model_class, source) return nil if source.nil? source = prepare_source model_class, source if source.is_a? Array source.map { |entry| instantiate_models model_class, entry } elsif source.is_a? Hash instantiate_model_from_attributes_hash model_class, source else raise ArgumentError, "#{model_class}: can't instantiate from a source of type #{source.class}" end end |
#instantiate_models_from_json(model_class, json) ⇒ nil, `model_class`
This method is the same as #instantiate_models but takes an unparsed JSON string as its input.
167 168 169 |
# File 'lib/ig_markets/dealing_platform.rb', line 167 def instantiate_models_from_json(model_class, json) instantiate_models model_class, ResponseParser.parse(JSON.parse(json)) end |
#sign_in(username, password, api_key, platform) ⇒ ClientAccountSummary
Signs in to the IG Markets Dealing Platform, either the live platform or the demo platform.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ig_markets/dealing_platform.rb', line 90 def sign_in(username, password, api_key, platform) session.username = username session.password = password session.api_key = api_key session.platform = platform result = session.sign_in @client_account_summary = instantiate_models ClientAccountSummary, result end |
#sign_out ⇒ Object
Signs out of the IG Markets Dealing Platform, ending any current session.
102 103 104 105 |
# File 'lib/ig_markets/dealing_platform.rb', line 102 def sign_out streaming.disconnect session.sign_out end |