Skip to content

Commit

Permalink
Add quote api
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldonth committed Jan 11, 2016
1 parent 64aa1e1 commit 80c1889
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 29 deletions.
19 changes: 9 additions & 10 deletions NodeActiveTick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,15 @@ NAN_METHOD(NodeActiveTick::Connect) {
// )

NAN_METHOD(NodeActiveTick::QuoteDbRequest) {
// Isolate* isolate = Isolate::GetCurrent();
// if (isolate) {
// HandleScope scope(isolate);
NodeActiveTick *obj = ObjectWrap::Unwrap<NodeActiveTick>(info.Holder());
Local<String> symbol_string = info[0]->ToString();
char cstr_symbol[symbol_string->Utf8Length()];
symbol_string->WriteUtf8(cstr_symbol);
ATSYMBOL s = Helper::StringToSymbol(std::string(cstr_symbol));
printf("Foo bar");
// }
NodeActiveTick *obj = ObjectWrap::Unwrap<NodeActiveTick>(info.Holder());
// Local<String> symbol_string = info[0]->ToString();
Nan::Utf8String ticker_string(info[0]->ToString());
std::string ticker = std::string(*ticker_string);
std::vector<ATSYMBOL> symbols = Helper::StringToSymbols(ticker);
std::vector<ATQuoteFieldType> fields;
fields.push_back(obj->enumConverter->toAtQuoteField("QuoteFieldSymbol"));
s_pInstance->m_hLastRequest = obj->requestor->SendATQuoteDbRequest(symbols.data(), symbols.size(), fields.data(), fields.size(), DEFAULT_REQUEST_TIMEOUT);
info.GetReturnValue().Set(Nan::New<Number>(s_pInstance->m_hLastRequest));
}

NAN_METHOD(NodeActiveTick::BarHistoryDbRequest) {
Expand Down
21 changes: 17 additions & 4 deletions Requestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Shared/ATServerAPIDefines.h>
#include <ActiveTickServerAPI/ATQuoteStreamResponseParser.h>
#include <ActiveTickServerAPI/ATBarHistoryDbResponseParser.h>
#include <ActiveTickServerAPI/ATQuoteDbResponseParser.h>
#include "NodeActiveTick.h"
#include "protobuf/messages.pb.h"
#include "import/atfeed-cppsdk/example/Helper.h"
Expand All @@ -22,10 +23,23 @@ Requestor::~Requestor() {

}

// ATQuoteDbResponseType responseType
// QuoteDbResponseSuccess
// QuoteDbResponseInvalidRequest
// QuoteDbResponseDenied
// QuoteDbResponseUnavailable
void Requestor::OnATQuoteDbResponse ( uint64_t origRequest,
ATQuoteDbResponseType responseType,
LPATQUOTEDB_RESPONSE pResponse,
uint32_t responseCount ) {
ATQuoteDbResponseParser parser = ATQuoteDbResponseParser(pResponse, responseCount);
NodeActiveTickProto::ATQuoteDbResponse *quoteDbResponse = new NodeActiveTickProto::ATQuoteDbResponse();
quoteDbResponse->set_atquotedbresponsetype(ATQuoteDbResponseType);
}

void Requestor::OnATBarHistoryDbResponse ( uint64_t origRequest,
ATBarHistoryResponseType responseType,
LPATBARHISTORY_RESPONSE pResponse)
{
LPATBARHISTORY_RESPONSE pResponse) {
ATBarHistoryDbResponseParser *parser = new ATBarHistoryDbResponseParser(pResponse);
NodeActiveTickProto::ATBarHistoryDbResponse *dbResponse = new NodeActiveTickProto::ATBarHistoryDbResponse();
if (parser->MoveToFirstRecord()) {
Expand Down Expand Up @@ -104,8 +118,7 @@ void Requestor::OnATConstituentListResponse(uint64_t origRequest, LPATSYMBOL pSy
void Requestor::OnATQuoteStreamResponse (uint64_t origRequest,
ATStreamResponseType responseType,
LPATQUOTESTREAM_RESPONSE pResponse,
uint32_t responseCount)
{
uint32_t responseCount) {
NodeActiveTickProto::ATQuoteStreamResponse *msg = new NodeActiveTickProto::ATQuoteStreamResponse;
ATQuoteStreamResponseParser parser = ATQuoteStreamResponseParser(pResponse);
std::string response = ProtobufHelper::atresponsetype_string(responseType);
Expand Down
5 changes: 5 additions & 0 deletions Requestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ class Requestor : public ActiveTickServerRequestor
LPATQUOTESTREAM_RESPONSE pResponse,
uint32_t responseCount);

virtual void OnATQuoteDbResponse ( uint64_t origRequest,
ATQuoteDbResponseType responseType,
LPATQUOTEDB_RESPONSE pResponse,
uint32_t responseCount);

};
5 changes: 3 additions & 2 deletions example/example.iced
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ updateLogStatement = (tickers, lastTrades, lastQuotes) =>
main = () ->
await a = new ActiveTick(defer())
await a.connect config.api_key, config.username, config.password, defer(result)
a.quoteDBRequest 'AAPL', (quote) ->
a.quoteDBRequest 'FB', (quote) ->
console.log 'quoteDBRequest callback'
console.log quote

a.barHistoryDBRequest 'FB', 'BarHistoryIntraday', 20, '20150908100000', '20150910100000', (result) ->
console.log 'barhistory', result
# @last_trades = {}
# @last_quotes = {}
# a.on 'trade', (trade) =>
Expand Down
3 changes: 3 additions & 0 deletions example/example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions iced/ActiveTick.iced
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if debug_exists # prefer debug
else
{NodeActiveTick} = require(release_path)

console.log NodeActiveTick

async = require 'async'
_ = require 'underscore'
ProtoBuf = require 'protobufjs'
Expand Down Expand Up @@ -39,6 +37,7 @@ class ActiveTick extends EventEmitter
@ATQuoteStreamTradeUpdate = @messages_builder.build "NodeActiveTickProto.ATQuoteStreamTradeUpdate"
@ATQuoteStreamQuoteUpdate = @messages_builder.build "NodeActiveTickProto.ATQuoteStreamQuoteUpdate"
@ATBarHistoryDbResponse = @messages_builder.build "NodeActiveTickProto.ATBarHistoryDbResponse"
@ATQuoteDbResponse = @messages_builder.build "NodeActiveTickProto.ATQuoteDbResponse"
readyCb()

barHistoryDBRequest: (symbol, barhistorytype, intradayminutecompression, startime, endtime, requestCb) =>
Expand All @@ -47,7 +46,7 @@ class ActiveTick extends EventEmitter

quoteDBRequest: (symbol, requestCb) =>
request_id = @api.quoteDbRequest symbol
@callbacks[request_id] = request if requestCb?
@callbacks[request_id] = requestCb if requestCb?

beginQuoteStream: (symbols, ATStreamRequestTypeIndex, requestCb) =>
if typeof symbols is 'object'
Expand All @@ -68,8 +67,6 @@ class ActiveTick extends EventEmitter
@callbacks[request_id] = cb

connect: (apiKey, username, password, cb) =>
console.log @api
console.log @api.connect
request_id = @api.connect apiKey, username, password
@callbacks[request_id] = cb

Expand All @@ -89,8 +86,8 @@ class ActiveTick extends EventEmitter
else if msgType is 'ATQuoteStreamQuoteUpdate'
msg = @ATQuoteStreamQuoteUpdate.decode msgData
@emit 'quote', msg
# else if msgType is 'ATQuoteDbResponse'
# msg = @ATQuoteDb
else if msgType is 'ATQuoteDbResponse'
msg = @ATQuoteDbResponse.decode msgData
if (c = @callbacks[msgID])?
c(msg)

Expand Down
6 changes: 1 addition & 5 deletions js/ActiveTick.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 80c1889

Please sign in to comment.