O le au faʻaosofia i tua atu o le atinaʻeina o le auaunaga faʻamaumauga mo Tinkoff Investments o:
- tusiga i luga o Habré “O le a le mea e le o fai mai e Tinkoff Investments”
- au’ili’iliga o mana’oga o tagata fa’aoga tulaga
- se tala e uiga i le fuafuaina o komisi .
- O le ā o le a talanoaina?
- Atiina o se auaunaga fa’amaumauga i lea laasaga ma lea laasaga:
- So’oga ile Tinkoff Invest API
- Tusi fa’amaumauga mai le Tinkoff Invest API i totonu ole su’esu’ega
- Mauaina o lipoti ma fefa’ataua’iga
- GetBrokerReport
- Metotia mo le mauaina o le aso, i le amanaia o le toesea mai le aso o loʻo iai nei
- Tuuina atu lipoti ole talosaga
- I’uga:
- GetDividendsForeignIssuer
- GetOperationsByCursor
- Fa’atusatusaga ma fa’aulufalega o fa’amatalaga o tu’inanauga
- Galulue ma tau
- O le tau o konekarate i le lumana’i
- OTC maketi
- Gaioiina o le matematika i meafaigaluega
- Microservice ua sauni!
- Fa’ai’uga ma fuafuaga mo le lumana’i
- https://opexbot.info
O le ā o le a talanoaina?
- Na’o le vaega fa’atatau ile atina’e.
- Malamalama moni ma le poto masani, lea e taua tele i le galulue faatasi ma meafaigaluega tau tupe.
- Aotelega o mataupu e galulue i ai
O lea la, ou te manaʻo e faʻatusatusa fuainumera fefaʻatauaʻiga ma faia i se auala faigofie.
Atiina o se auaunaga fa’amaumauga i lea laasaga ma lea laasaga:
- So’oga ile Tinkoff Invest API
- Tusi fa’amaumauga mai le Tinkoff Invest API i totonu ole su’esu’ega
- Mauaina o lipoti ma fefa’ataua’iga
- Fa’atusatusaga ma fa’aulufalega o fa’amatalaga o tu’inanauga
- Fa’ai’uga ma fuafuaga mo le lumana’i
So’oga ile Tinkoff Invest API
Ina ia faʻafesoʻotaʻi i le API, e mafai ona e ave soʻo se sdk mai faʻamaumauga https://github.com/Tinkoff/investAPI#sdk . Po’o le npm package ` tinkoff-sdk-grpc-js `. E taua tele le faʻafouina o le afifi i le faʻamatalaga lata mai e le au atiaʻe. Fa’apipi’i
npm i tinkoff-sdk-grpc-js
Siaki
const {createSdk} = mana’omia(‘tinkoff-sdk-grpc-js’); // Faailoga e mafai ona maua e pei o lenei const TOKEN = ‘YOURAPI’; // Le igoa o le talosaga e mafai ona e mauaina i totonu o le TCS logs. const appName = ‘tcsstat’; const sdk = createSdk(TOKEN, appName); (async () => { console.log(faatalitali sdk.users.getAccounts()); })();
I’uga: o le a fa’aalia se lisi o au tala ile fa’amafanafanaga. Mo se faʻataʻitaʻiga, seʻi o tatou iloiloina le nuances:
- I le lisi o faʻamatalaga o loʻo i ai se “Teuga tupe teu tupe”, lea e le mafai ona e galue e faʻaaoga le API
- Faamolemole ia matau o fanua e sau i camelCase, ae i totonu o faʻamaumauga o nei fanua o loʻo tuʻuina atu i lalo_score.
- O le a faʻapenei i soʻo se mea, o lea e le mafai ai ona e ave ma kopi se fanua mai faʻamaumauga.
Fa’aoga
- E mafai ona e mauaina lenei code i le lala o le poloketi
https://github.com/pskucherov/tcsstat/tree/step1 https://github.com/pskucherov/tcsstat/compare/step1
Tusi fa’amaumauga mai le Tinkoff Invest API i totonu ole su’esu’ega
Na ou ave next.js ma socket.io. E le o se fautuaga malosi, filifili i lau pule faitalia.
npx create-next-app@latest npm i socket.io socket.io-client
Matou te fa’agasolo loa i le la’asaga faauo e sosoo ai + socket + investapi, ma va’ai i le Fa’aoga vaega o lenei la’asaga mo fa’amatalaga uma. O le a ou faʻamatalaina faʻamatalaga:
- I le itu nodejs (server), o loʻo i ai se faila itulau/api/investapi.js. O le mea lea matou te fatuina ai le socket.io server ma faʻafesoʻotaʻi i investapi.
- I luga o le browser (client) itu, matou te faʻafesoʻotaʻi i le ‘auʻaunaga e ala i se socket ma talosagaina faʻamatalaga faʻamatalaga mai le tagata fai pisinisi.
- Matou te mauaina faʻamatalaga mai le tagata fai pisinisi i luga o le ‘auʻaunaga, ona tuʻuina atu lea i le kalani. A maua i luga ole kalani, e fa’aalia ile su’esu’ega.
I’uga: i totonu o le browser console e mafai ona tatou va’aia fa’amatalaga e uiga i fa’amatalaga. O lona uiga, i le laasaga mulimuli, na matou vaʻaia faʻamatalaga e uiga i faʻamatalaga i le faʻamafanafanaga o le server (nodejs), i le laasaga o loʻo i ai nei, na matou tuʻuina atu lenei faʻamatalaga i le tagata o tausia (browser).
Sei o tatou faia ina ia mafai ona e filifilia se tala mai le browser, ma afai e leai se faʻailoga, ona tuʻuina atu lea o se mea sese i le faʻamafanafanaga. O le galuega e faigofie ma e leai se mea fou, o lea ou te tuʻuina atu naʻo sootaga i tautinoga
- https://github.com/pskucherov/tcsstat/commit/7e1ac57061e5e971588479015b06d8814d6609a9
- https://github.com/pskucherov/tcsstat/commit/b28ac973a57494f5232589b4cb6b9fb13b8af759
Fa’aoga
- Faʻafefea ona fai uo i le isi ma le socket o loʻo faʻamatalaina auiliili iinei .
- Fa’ailoga faauo e soso’o+socket+investapi:
https://github.com/pskucherov/tcsstat/commit/a443a4ac1bb4f0aa898f638128755fe7391ee381 Mo i latou o loʻo i luga e faigata, ona matou tumau ai lea i lenei laasaga ma faʻatautaia le code. Afai ei ai ni au fesili – fesili. https://github.com/pskucherov/tcsstat/tree/step2 https://github.com/pskucherov/tcsstat/compare/step1…step2
Mauaina o lipoti ma fefa’ataua’iga
E tolu auala e maua ai lipoti faʻasalalau ma fefaʻatauaiga
Mai lava i le amataga e taua le iloa:
- O le lipoti faʻasalalau e gaosia i le T-3 mode, i.e. fefa’ataua’iga o lo’o fa’aalia iina pe a uma ona fa’ataunu’uina.
- E tusa ai, afai e te talosagaina lenei lipoti mo aso e lua mulimuli, o le a saunia i le tolu aso.
- Ina ia maua fefaʻatauaiga mo aso mulimuli, matou te faʻaogaina le auala mo le mauaina o fefaʻatauaiga, ae ia manatua o latou id ma mea e mafai ona suia pe a maeʻa le lipoti o le faʻasalalauga.
GetBrokerReport
Mo le mauaina o se lipoti faʻatau, e manaʻomia lou ave o le account id, aso amata ma le aso faʻaiʻu o le lipoti, ae le sili atu i le 31 aso. Matou te tu’uina atu se talosaga e fa’atupu se lipoti i le API i le gaosia _broker_report_request , maua se taskId i le tali. A maeʻa lena, faʻaaoga lenei taskId, matou te maua faʻamatalaga mai le get _broker_report_response.
- E tatau ona e fa’asaoina le TaskID e fa’avavau mo nei aso.
- Talu ai afai e te leiloa, ona mo aso talosagaina o le a muamua oʻo mai le lipoti i le tali atu i le talosaga a le tupulaga,
- Ona le oo mai ai lea.
Metotia mo le mauaina o le aso, i le amanaia o le toesea mai le aso o loʻo iai nei
const getDateSubDay = (subDay = 5, amata = moni) => { const aso = aso fou (); date.setUTCDate(date.getUTCDate() – subDay); afai (amata) { date.setUTCHours(0, 0, 0, 0); } isi { date.setUTCHours(23, 59, 59, 999); } aso toe fo’i mai; };
Tuuina atu lipoti ole talosaga
const brokerReport = faatali (sdk.operations.getBrokerReport)({ generatorBrokerReportRequest: { accountId, from, to, }, });
I’uga:
- O se taunuuga o le faatinoga muamua o le poloaiga, matou te maua le taskId.
- O le lipoti e amata ona gaosia i le itu a le tagata fai pisinisi. Pe a sauni e le o iloa, matou te faʻatali ma toso i lea taimi ma lea taimi le taskId e faʻatali ai le lipoti.
- Aisea? Aua afai e le o saunia le lipoti, e lafo se mea sese. Afai e le o saunia le lipoti i le itu a le tagata fai pisinisi, o se mea sese lea i lau code. Fa’amolemole fa’agasolo: 30058|INVALID_ARGUMENT|e le’i mae’a le galuega, fa’amolemole toe taumafai mulimuli ane
O le tulafono mo le faʻatali ma le mauaina o se lipoti e foliga faʻapea.
const timer = taimi async => { toe fo’i le Folafolaga fou(fo’ia => setiTaimi’ese(fofo, taimi)); } const getBrokerResponseByTaskId = async (taskId, itulau = 0) => { taumafai { foi faatali (sdk.operations.getBrokerReport)({ getBrokerReportRequest: { taskId, itulau, }, }); } pu’e (e) { console.log(‘faatalitali’, e); fa’atali taimi(10000); toe fo’i fa’atali getBrokerResponseByTaskId(taskId, itulau); } };
Ona tupu ai lea o le togafiti lava lea e tasi. E taofi le matou tusitusiga, toe amata, e leai sa matou taskId. Matou te faʻatinoina le code ma le taskId talosaga, ae matou te le toe maua le taskId, ae vave le lipoti. Fa’ataulāitu! Ma o le a lelei mea uma pe ana faapea o taimi uma. Ae i le masina o le a leai se faʻamatalaga. Fa’aoga :
- O loʻo faʻamatala atu se vaega o aʻoaʻoga iinei ma iinei .
- O le tuʻufaʻatasia o le code, o le ata faataitai o le a pei o lenei.
https://github.com/pskucherov/tcsstat/tree/step3.1 https://github.com/pskucherov/tcsstat/compare/step3.1
- Afai e maua e se tasi lenei mea, faʻafeiloaʻi i le mataupu . A maeʻa ona latou toe faʻaleleia lenei togafiti, o le a leiloa lona malosi ma o le a ese lava. Ae i le taimi nei (03/21/2023) o loʻo galue faʻapea.
GetDividendsForeignIssuer
Atonu e manatu se tasi o le auala e talitutusa ma le muamua ma e mafai ona e faʻaogaina se tasi auala e te suia ai le igoa o gaioiga. Ae latou te lei mateina! O le fa’aigoaina iina e matua’i ‘ese’ese uma i metotia ma fa’amatalaga toe fa’afo’i mai. Ma o le numera o itulau e amata mai i le 0, sosoo ai ma le 1. Ina ia aua neʻi fenumiai i nei mea uma, e faigofie ona tusia ni auala eseese se lua. O se mea uiga ese, aua e tutusa le manatu o le galuega. Na ou feanu mo se taimi umi pe a ou taumafai e fai se tasi auala ma e itiiti le code. O le a leai ni faʻataʻitaʻiga iinei.
GetOperationsByCursor
La’u fiafia i le tolu. E ui lava e le sili ona saʻo, ae sili ona talafeagai. Matou te faia se talosaga mai le amataga o le fatuina o se teugatupe i le aso aupito maualuga e mafai ai (tapuni se teugatupe poʻo le taimi nei). Matou te maua le tali, ave le cursor ma toe talosaga pe afai e iai faʻamatalaga. Ma o le code e sili atu le puʻupuʻu nai lo faʻataʻitaʻiga o loʻo i luga.
const timer = taimi async => { toe fo’i le Folafolaga fou(fo’ia => setiTaimi’ese(fofo, taimi)); } const getOperationsByCursor = async (sdk, accountId, mai, i, cursor = ”) => { taumafai { const reqData = { accountId, mai, i, tapulaa: 1000, setete: sdk.OperationState.OPERATION_STATE_EXECUTED, e aunoa ma Komisi: sese, e aunoa ma Fefa’ataua’iga: sese, e aunoa maOvernights: sese, fetu’u, }; toe fo’i fa’atali sdk.operations.getOperationsByCursor(reqData); } pu’e (e) { fa’atali taimi(60000); toe fo’i fa’atali getOperationsByCursor(sdk, accountId, from, to, cursor = ”); } };
O le ata e tamoe o iinei: https://github.com/pskucherov/tcsstat/tree/step3.3 https://github.com/pskucherov/tcsstat/compare/step3.3 O lea ua matou sauni e faʻaopoopo le mauaina o gaioiga i la matou talosaga. Afai e fai sa’o, ona e mana’omia lea ona maua lipoti tau fa’atau mo le i ai atoa o le teugatupe. Ma mo faʻamatalaga o loʻo misi, o na lava T-3s, toe faʻaleleia mai gaioiga. Ae e mafai ona vaevaeina lenei mea i se tala ese. O nuances autu o le ae fetaiai o le fa’apipi’i fa’agaioiga ma se lipoti fa’atau.
- Afai o le aso na e mauaina ai se lipoti faʻasalalau ma fefaʻatauaiga mo aso manaʻomia, tuʻu uma i totonu o faʻamaumauga, ona leai lea o ni faʻafitauli.
- O le a iai ni fa’afitauli taeao pe a e mauaina le isi vaega o fa’amaumauga mai le lipoti ma fa’agaioiga ma filifili e fa’amaopoopo i latou ma fa’amaumauga o lo’o iai.
- Le tele o nuances e uiga i le le fetaui poʻo le suia o id pe a maeʻa le gaioiga
- Ae mo le maketi OTC, e le fetaui le id.
- E faʻapea foʻi ma le faʻaogaina o meafaifaʻaili faʻatasi, lea e le o fetaui, ona o uiga faʻapitoa o le API. Ae o se isi tala lena.
Tatou fa’aopoopo le mauaina o fa’amatalaga e uiga i fa’agaioiga i la tatou talosaga. O le fesili autu o le a faʻapipiʻiina ma teuina faʻamaumauga.
- Afai e te faia mo oe lava, o le ae faʻaaogaina faʻamatalaga tutusa mai masini eseese. Ona e manaʻomia lea e faʻagasolo ma teu faʻamaumauga i luga o le server.
- Afai e tele au faʻamatalaga eseese e faʻaaogaina e le tele o tagata faʻaoga eseese, ona e manaʻomia lea e filifili po o le a le mea e sili atu ona taua: le saoasaoa o tagata faʻaoga poʻo le faʻasaoina o le uʻamea i lou itu. Po’o ai lava e mafai ona gafatia se aofa’iga e le i’u o meafaigaluega e faitau mea uma i luga o lana ‘au’aunaga ma fa’avavevave mo tagata fa’aoga, fa’asaoina punaoa fa’aoga, e pei o le maa ma fefa’ataua’iga, lea e taua tele i telefoni.
I le isi itu, o le faitau i le browser e le o se fofo sili ona lelei i le mataupu faavae. O le mea lea, o le a le mea e le taugata, matou te manatu i luga o la matou ‘auʻaunaga. Matou te tu’u le vaega o totoe i le kalani. Ou te manaʻo lava e ave ma fuafua le komisi i luga o le ‘auʻaunaga. Ae o iinei e sau ai le nuance ua taʻua o le “interactivity”. Fa’apea e faitau afe au gaioiga ma e mana’omia le lima minute e maua ai. O le a le mea e maua e le tagata fa’aoga i lenei taimi? Spinner? Alualu i luma? Infa e uiga i le tele na fa’apipi’i? E lelei le fa’aogaina o le “fa’atali malosi” pe a mafai e le tagata fa’aoga i le faagasologa ona va’aia se mea. Ole I’uga lea:
- utaina itulau
- E talosagaina uma pili
- A maeʻa lena, o fefaʻatauaiga uma ma komisi mo fefaʻatauaiga faʻatinoina e talosagaina mo faʻamatalaga uma. A’o maua fa’amatalaga, e tu’uina atu i le su’esu’ega.
Ina ia aua neʻi faʻamama faʻamaumauga i mea tutupu i taimi taʻitasi, matou te tosoina a matou lava mea na tupu mo tala taʻitasi. Faapei o lea:
socket.emit(‘sdk:getOperationsCommissionResult_’ + accountId, { aitema: data?.items, inProgress: Boolean(nextCursor), });
O le ata e faʻalauiloa o loʻo iinei: https://github.com/pskucherov/tcsstat/tree/step3 https://github.com/pskucherov/tcsstat/compare/step2…step3 Faʻaauau. Manaia ua e faitau i lenei laina!
Fa’atusatusaga ma fa’aulufalega o fa’amatalaga o tu’inanauga
Fa’alagolago po’o ai e mana’omia a fa’amatalaga. O le mea lea, ou te vave taʻu atu ia te oe nuances autu o le ae feagai.
Galulue ma tau
O tagata uma e galulue i mea tau tupe latou te iloa o fefaʻatauaiga o tupe e tatau ona faʻatinoina i numera atoa. Ona o le le saʻo o tau pe a maeʻa le numera decimal ma le faʻaputuina mea sese ma se numera tele o gaioiga. O le mafuaaga lena o lo’o tu’uina atu ai tau uma i le fa’asologa o TupeValue
fanua | ituaiga | Fa’amatalaga |
---|---|---|
tupe | manoa | String ISO currency code |
iunite | int64 | Ole vaega ole numera, e mafai ona avea ma numera le lelei |
nano | int32 | Vaega vaevae o le aofaʻi, e mafai ona avea ma numera le lelei |
Matou te faʻavasegaina eseese, ona aumai lea i le tau o le tau:
quotation.units + quotation.nano / 1e9
O le tau o konekarate i le lumana’i
O le tau o le lumanaʻi o loʻo tuʻuina atu i togi, pe a iai sau tupe i le lumanaʻi, e tatau ona e iloa le fua faatatau. Ma o le mea moni o le tau i togi ma le laasaga tau. A e faʻatatauina le tupe mama mai fefaʻatauaiga, e mafai ona fana, aua. pe afai e te fuafuaina le aofaʻi atoa e ala i le faʻateleina o le tau i le aofaʻi. O iinei e tatau ona e fa’aeteete. Mo le taimi nei, o le a tatou vaʻai pe faʻafefea. E faʻatatau i tupe i le lumanaʻi, i isi nofoaga e lelei mea uma i lenei mea.
OTC maketi
O lenei maketi e tele naua mea faʻapitoa, o lea seʻi o tatou suʻesuʻeina faʻagaioiga i luga eseese A e amata faʻatasi gaioiga, e foliga mai e te manaʻomia le aumaia o le figi / ticker i le foliga tutusa ina ia fetaui lelei ma le meafaigaluega. A e amata faʻamaopoopoina lenei mea ma le lipoti faʻasalalau, o le a faʻaalia o le tradeID o le fefaʻatauaʻiga tutusa o loʻo i ai tusi i le amataga i fefaʻatauaiga ma latou te le oi totonu o le lipoti o fefaʻatauaiga. O le mea lea, e le mafai ona faatusatusaina … ahem-ehem … e ala i le faatusatusa! Na ou fa’atusaina le taimi o fefa’ataua’iga, fa’ailoga ma fa’afetaui le tasi tradeId o lo’o iai i le isi. Sa’o, ou te le iloa. Po’o ai lava e feagai ma lenei mea ma o ai e popole i ai, sau i le mataupu pe amata se mea fou.
Gaioiina o le matematika i meafaigaluega
E le mafai, e aunoa ma le va’ai, ona fa’atino galuega fa’a-matematika ma le lisi atoa. Ina ia le faʻaopopoina le mafanafana i le vaivai, matou te siakiina i taimi uma le tupe ma le faʻagasologa pe afai matou te mautinoa o le tupe e fetaui, ma o togi e liua i le tupe manaʻomia. Fa’aauupegaina i le poto e uiga i le galue i numera o faletupe, o le a matou fa’atatauina le komisi na fa’aalu i fa’amatalaga ta’itasi. Pei o lenei: https://github.com/pskucherov/tcsstat/tree/step4 https://github.com/pskucherov/tcsstat/compare/step3…step4
Microservice ua sauni!
https://github.com/pskucherov/tcsstat I le avea ai o se meaaoga, e mafai ona e siaki pe o galue le tautua i se fesoʻotaʻiga faʻagesegese, pe a motusia fesoʻotaʻiga, pe a motusia le Initaneti, pe a faʻaletonu poʻo le muta o tapulaa i le vaega a le tagata faʻatau.
Fa’ai’uga ma fuafuaga mo le lumana’i
- A’oa’o e uiga i galuega fa’avae ma galulue fa’atasi ma le Invest API
- Taimi fa’aalu ~ 10 itula
- Tulaga faigata ~ junior+ / maualalo ogatotonu
Afai e te faʻaauau pea ona faʻaleleia le microservice, atonu e te iʻu i se mea faʻapenei
https://opexbot.info
O la’u atina’e lea, mo i latou e paie e malamalama, tamo’e ma fa’amoemoe i latou lava. Ou te fuafua e faʻaopoopo auʻiliʻiliga iina i le talosaga a tagata faʻaoga. Afai e te fiafia i le tusiga, ona e lesitala lea i laʻu auala telegram .
Полезная статья. Не могу представить, сколько усилий автора потребовалось, чтобы все описать. Благодарю.