-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.0.0
- Loading branch information
Showing
3 changed files
with
2,762 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
syntax = "proto3"; | ||
|
||
message PricingData { | ||
|
||
enum QuoteType { | ||
NONE = 0; | ||
ALTSYMBOL = 5; | ||
HEARTBEAT = 7; | ||
EQUITY = 8; | ||
INDEX = 9; | ||
MUTUALFUND = 11; | ||
MONEYMARKET = 12; | ||
OPTION = 13; | ||
CURRENCY = 14; | ||
WARRANT = 15; | ||
BOND = 17; | ||
FUTURE = 18; | ||
ETF = 20; | ||
COMMODITY = 23; | ||
ECNQUOTE = 28; | ||
CRYPTOCURRENCY = 41; | ||
INDICATOR = 42; | ||
INDUSTRY = 1000; | ||
}; | ||
|
||
enum OptionType { | ||
CALL = 0; | ||
PUT = 1; | ||
}; | ||
|
||
enum MarketHoursType { | ||
PRE_MARKET = 0; | ||
REGULAR_MARKET = 1; | ||
POST_MARKET = 2; | ||
EXTENDED_HOURS_MARKET = 3; | ||
}; | ||
|
||
string id = 1; | ||
float price = 2; | ||
sint64 time = 3; | ||
string currency = 4; | ||
string exchange = 5; | ||
|
||
|
||
QuoteType quoteType = 6; | ||
MarketHoursType marketHours = 7; | ||
float changePercent = 8; | ||
sint64 dayVolume = 9; | ||
float dayHigh = 10; | ||
float dayLow = 11; | ||
float change = 12; | ||
string shortName = 13; | ||
sint64 expireDate = 14; | ||
float openPrice = 15; | ||
float previousClose = 16; | ||
float strikePrice = 17; | ||
string underlyingSymbol = 18; | ||
sint64 openInterest = 19; | ||
OptionType optionsType = 20; | ||
sint64 miniOption = 21; | ||
sint64 lastSize = 22; | ||
float bid = 23; | ||
sint64 bidSize = 24; | ||
float ask = 25; | ||
sint64 askSize = 26; | ||
sint64 priceHint = 27; | ||
sint64 vol_24hr = 28; | ||
sint64 volAllCurrencies = 29; | ||
string fromcurrency = 30; | ||
string lastMarket = 31; | ||
double circulatingSupply = 32; | ||
double marketcap = 33; | ||
}; | ||
|
||
|
||
message StaticData { | ||
string id = 1; | ||
string displayName = 5; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// package version: npm install [email protected] --save | ||
// npm install bytebuffer | ||
// useful: https://webapplog.com/json-is-not-cool-anymore/ | ||
// data source: https://finance.yahoo.com/__finStreamer-proto.js | ||
const WebSocket = require('ws') | ||
var ProtoBuf = require("protobufjs"); | ||
const io = require("socket.io-client"); | ||
|
||
"use strict"; | ||
//let ProtoBuf = decode.protobuf; | ||
let Message = ProtoBuf | ||
.loadProtoFile('./PricingData.proto', (err, builder)=>{ | ||
Message = builder.build('PricingData') // StaticData // PricingData | ||
loadMessage() | ||
}) | ||
|
||
// Settings - Setup connection for local server. Disabled by default, if such server isn't running or not configured | ||
var useSocket = false; | ||
let socketClientID = "xyz"; | ||
|
||
const socket = io("http://localhost:3200"); | ||
if(useSocket){ | ||
// connect to local socket server - for distributed messages | ||
socket.on('connect', () => { | ||
console.log("Socket ID: "+socket.id) | ||
socketClientID = socket.id; | ||
}) | ||
} | ||
|
||
|
||
// Main Yahoo connection | ||
let loadMessage = ()=> { | ||
const url = 'wss://streamer.finance.yahoo.com' | ||
const connection = new WebSocket(url) | ||
|
||
connection.onopen = () => { | ||
// Subscribe to AMC and Tesla symbols. List can contain many symbols | ||
connection.send('{"subscribe":["AMC", "TSLA"]}') | ||
} | ||
|
||
connection.onerror = (error) => { | ||
console.log(`WebSocket error: ${error}`) | ||
} | ||
|
||
connection.onmessage = (e) => { | ||
|
||
let msg = Message.decode(e.data) | ||
console.log('All data set: ', msg) | ||
console.log('Decoded message', msg.id + ' with price: ' + msg.price) | ||
|
||
// Create object which will be sent to distribution over local socket.io server | ||
var trackedData = { | ||
name: msg.id, | ||
price: msg.price, | ||
identifier: hashCode(msg.id), | ||
sender: "Yahoo", | ||
clientid: socketClientID, | ||
symbol: msg.id | ||
} | ||
|
||
// Use socket server if enabled | ||
if(useSocket){ | ||
socket.emit('tracked', trackedData); | ||
} | ||
|
||
} | ||
} | ||
|
||
// Helper function - converts string into number. Can be used in html to generate unique class names etc. | ||
function hashCode(str) { | ||
var hash = 0, i, chr; | ||
for (i = 0; i < str.length; i++) { | ||
chr = str.charCodeAt(i); | ||
hash = ((hash << 5) - hash) + chr; | ||
hash |= 0; // Convert to 32bit integer | ||
} | ||
if (hash < 0) { | ||
// if negative, convert to positive | ||
hash = hash * (-1); | ||
} | ||
return hash; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// Normalna ne-dekodirana verzija | ||
// const url = 'wss://streamer.finance.yahoo.com' // wss://streamer.finance.yahoo.com //wss://flavio-websockets-server-example.glitch.me | ||
// const connection = new WebSocket(url) | ||
|
||
// connection.onopen = () => { | ||
// connection.send('{"subscribe":["TSLA","AXSM","UBER","MIRM","GRKZF","BTCUSD=X","ETHUSD=X","AUDUSD=X","^DJI","^IXIC","^RUT","^TNX","^VIX","^CMC200","^FTSE","^N225"]}') | ||
// } | ||
|
||
// connection.onerror = (error) => { | ||
// console.log(`WebSocket error: ${error}`) | ||
// } | ||
|
||
// connection.onmessage = (e) => { | ||
// console.log(e.data) | ||
// //let data = 'c3RhY2thYnVzZS5jb20='; | ||
// let buff = new Buffer(e.data, 'base64'); | ||
// let text = buff.toString('ascii'); | ||
|
||
// console.log('Converted: ' + text); | ||
// } |
Oops, something went wrong.