Closed aqilc closed 4 years ago
Also, camelCase is super outdated xd
Also, camelCase is super outdated xd
I'm ex-Java it's second nature to me.. :(
Ohhh, I have a few friends who also retain Java practices when starting javascript. I am telling you, it will make you end up in a deep, unescapable hole of regret in many projects as these two languages are extremely different and you need a fresh mind for both.
Also, after learning JavaScript and mainly TypeScript practices, I can never look at Java code without frustration or disgust anymore.
Also, after learning JavaScript and mainly TypeScript practices, I can never look at Java code without frustration or disgust anymore.
Java is for dinosaurs.
Also adding on to your initial suggestion... could you explain a bit more what you mean by assets cache? Because assets and some of their fields may change minute by minute, a cache of them wouldn't be all that helpful in that sense.
Ohhh, I am a bit new at the stock market and some people just asked me to try making a bot. I found out Alpaca like 2 days ago and now I'm here xd
Welcome to the Alpaca community! :) You ok with me closing this issue or is there more you'd like to add for streamlining the package?
Oh yeah, two things:
Also, I wanted to push something else but keep getting this error(I didn't feel like opening an issue because this is probably me being extremely dumb):
I usually only have private repos on personal projects so I'm not used to pushing much, and would love some help xd.
If there's some permission problem, I can just send the file over.
Also, I wanted to push something else but keep getting this error(I didn't feel like opening an issue because this is probably me being extremely dumb):
No one can push directly to repo except for owners or collaborators. If you wish to make changes you must first fork the repo to your own account, commit changes there, then submit a pull request.
I'm too lazy so can you just commit this yourself? Here is a completely redone README.md. You have the code, so you can revise and change whatever you want before committing too:
A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.
Table of Contents:
> npm i 117/alpaca-trade-api-ts
alpaca.Client
A client for handling all account based requests.
Client
InitializationThe standard way to initialize
// Import the Client
import { Client } from 'alpaca-trade-api-ts'
// The actual initialization
const client = new Client({
key: '...',
secret: '...',
paper: true,
rate_limit: true,
})
You can also use environment variables which will be applied to every new client.
> set APCA_API_KEY_ID=yourKeyGoesHere
> set APCA_API_SECRET_KEY=yourKeyGoesHere
> set APCA_PAPER=true
Due to the asynchronous nature of the client we recommended you listen for interrupts.
// Allow pending promises to resolve before exiting the process.
process.on('SIGINT', async () => {
// Properly closes the client.
await alpacaClient.close()
// Then exits the process
process.exit(0)
})
All Client instance methods.
Checks if the client is authenticated.
await client.isAuthenticated()
Connects to an Alpaca account.
await client.getAccount()
Gets a specific order.
await client.getOrder({
order_id: '6187635d-04e5-485b-8a94-7ce398b2b81c',
})
Gets all orders made by the client.
await client.getOrders({
limit: 25,
status: 'all',
})
Places an order using your account.
await client.placeOrder({
symbol: 'SPY',
qty: 1,
side: 'buy',
type: 'market',
time_in_force: 'day',
})
Re-places an order(to change some details maybe).
await client.replaceOrder({
order_id: '69a3db8b-cc63-44da-a26a-e3cca9490308',
limit_price: 9.74,
})
Cancels an order.
await client.cancelOrder({
order_id: '69a3db8b-cc63-44da-a26a-e3cca9490308',
})
Cancels every single order(be sure to not make a typo here!)
await client.cancelOrders()
More examples are coming soon... give me some time or feel free to contribute.
An Alpaca websocket API for streamlining the exchange of requests and data to and from the Alpaca servers.
alpaca.Stream
InitializationAn API key is allowed 1 simultaneous connection to each server. Connecting to them is easy:
// Imports the Alpaca websocket stream API
import { Stream, BaseURL } from 'alpaca-trade-api-ts';
// Creates a websocket stream
const stream = new Stream(client, {
host: BaseURL.MarketDataStream,
});
// To see all stream messages use .onMessage
stream.subscribe(['T.SPY']);
// Will get called on each new trade event for SPY
stream.onTrade((trade) => {
console.log(trade)
});
Contains 2 properties used for securing a connection to an Alpaca websocket:
URL | Enum |
---|---|
wss://api.alpaca.markets/stream |
BaseURL.AccountStream |
wss://data.alpaca.markets/stream |
BaseURL.MarketDataStream |
Pull requests are encouraged. 😁
Oh you should add a some of the returns of the functions at the end. The previous code was so loosely written that it wouldn't have helped much anyways until a more thorough documentation of the returned classes comes out.
That readme looks great!
Thanks!! :D
Uh can you extract the raw code from it? I don't know if you completely can... I can properly push if you are having problems xd or do a hackaround consisting of changing the file type to .log
and attaching it
Also, I know you are a Java person so you used IntelliJ iDEA a lot before, but Visual Studio Code is a lot better suited for Javascript and Node.js in general for me. Maybe try it out someday :D I can recommend a large suite of extensions too if you need some good ones(I've spent literal days looking for them).
Also, can you link the direct website resources and API responses from the official Alpaca website? It would be helpful.
Also, uh you don't have any descriptions filled out in the script files themselves, which are also sort of needed if you really want this to be complete. I'm imagining a giant "docs" phase of development now xd.
I usually just make the docs as I go in my projects.
Also, can you link the direct website resources and API responses from the official Alpaca website? It would be helpful.
https://alpaca.markets/docs/api-documentation/api-v2/account/
No, I meant in the docs itself lmao.
Actually, I guess it would be super unnecessary to implement it for every class. I think you should just finally add returned types and classes and it should be awesome.
No, I meant in the docs itself lmao.
Ah yeah thats a good idea.
ok so i commited a lot of things in a new pull request
uhhh is it possible for you to accept my friend request and talk on Discord? I sent one a bit ago but you never responded...
I want to discuss further plans there, since GitHub isn't the best place for it.
Client.getAsset(), Client.getAssets(), Client.getWatchlist(), Client.createWatchlist(), etc. seems like a really outdated way to do a modern API. I would suggest an
Client.assets
property that has an assets cache and the required methods built-in like this:which gets all assets without parameters and specific assets using given parameters otherwise. This can be done with watchlists, account configurations, clocks, calendars, and many other methods/objects.