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.
- checksums.yaml +4 -4
- data/README.md +11 -4
- data/ib-symbols.gemspec +1 -1
- data/lib/ib/symbols/abstract.rb +91 -92
- data/lib/ib/symbols/futures.rb +12 -0
- data/lib/ib/symbols/version.rb +1 -1
- metadata +3 -28
- data/examples/contract_details +0 -71
- data/examples/contract_sample_details +0 -50
- data/examples/contract_samples.rb +0 -716
- data/examples/depth_of_market +0 -45
- data/examples/head_time_stamp +0 -35
- data/examples/historic_data +0 -102
- data/examples/market_data +0 -57
- data/examples/option_data +0 -63
- data/examples/real_time_data +0 -35
- data/examples/snapshot_market_data +0 -105
- data/examples/time_and_sales +0 -51
data/examples/time_and_sales
DELETED
@@ -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
|