ib-symbols 1.0 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # This script connects to IB API and subscribes to market data for Forex symbols.
4
- # It then prints out all trades that exceed certain size.
5
-
6
- require 'bundler/setup'
7
- require 'ib/symbols'
8
-
9
- # Define the symbols we're interested in.
10
- @market = {
11
- 123 => IB::Symbols::Futures[:gbp],
12
- 234 => IB::Symbols::Futures[:jpy],
13
- 444 => IB::Symbols::Forex[:usdjpy]
14
- }
15
-
16
- # First, connect to IB TWS. Arbitrary :client_id is used to identify your script
17
- ib = IB::Connection.new :client_id => 1112 #, :port => 7496 # TWS
18
-
19
- # Subscribe to TWS alerts/errors
20
- ib.subscribe(:Alert, :ManagedAccounts) { |msg| puts msg.to_human }
21
-
22
- # This method filters out non-:last type events, and filters out any sale < MIN_SIZE.
23
- # Note that we have to look the ticker id of each incoming message
24
- # up in local memory to figure out what it's for.
25
- # (N.B. The description field is not from IB TWS. It is defined
26
- # locally in symbols/futures.rb symbols/forex.rb, and is just arbitrary text.)
27
- def show_sales_and_size(msg)
28
- #return if msg.type != :last_price || msg.data[:size] < MIN_SIZE
29
- puts @market[msg.ticker_id].description + ": " +
30
- (msg.is_a?(IB::Messages::Incoming::TickPrice) ?
31
- "#{msg.data[:size]} at #{msg.data[:price]}" : msg.to_human)
32
- end
33
-
34
- # Now, subscribe to TickerPrice and TickerSize events. The code passed in the block
35
- # will be executed when a message of that type is received, with the received message
36
- # as its argument. In this case, we just print out the tick.
37
- ib.subscribe(:TickPrice, :TickSize, :TickString) { |msg| show_sales_and_size(msg) }
38
-
39
- # Now we actually request market data for the symbols we're interested in.
40
- @market.each_pair do |id, contract|
41
- ib.send_message :RequestMarketData, :ticker_id => id, :contract => contract
42
- end
43
-
44
- puts "\nSubscribed to TWS market data"
45
- puts "\n******** Press <Enter> to cancel... *********\n\n"
46
- STDIN.gets
47
- puts "Unsubscribing from TWS market data.."
48
-
49
- @market.each_pair { |id, contract| ib.send_message :CancelMarketData, :ticker_id => id }
50
-
51
- sleep 2