Litlhahiso tsa nts’etsopele ea ts’ebeletso ea lipalo-palo bakeng sa Tinkoff Investments e ne e le:
- sengoloa se buang ka Habré “Seo Tinkoff Investments e sa se buang”
- tlhahlobo ea litakatso tsa basebelisi ba sethaleng
- sehlooho se mabapi le ho baloa ha likomishene .
- Ho tla tšohloa eng?
- Ho theha ts’ebeletso ea lipalo-palo mohato ka mohato:
- Khokahano ho Tinkoff Invest API
- Ho hula lintlha ho tsoa ho Tinkoff Invest API ho sebatli
- Ho fumana litlaleho tsa brokerage le litšebelisano
- GetBrokerReport
- Mokhoa oa ho fumana letsatsi, ho nahanoa ka ho tlosa ho tloha letsatsing la hona joale
- Tlaleho ea kopo ea tlhahiso
- Sephetho:
- GetDividendsForeignIssuer
- GetOperationsByCursor
- Palo le tlhahiso ea litaba tse khahlang
- Ho sebetsa ka litheko
- Litsenyehelo tsa likonteraka tsa bokamoso
- OTC marakeng
- Ts’ebetso ea lipalo ho lisebelisoa
- Microservice e lokile!
- Liqeto le merero ea bokamoso
- https://opexbot.info
Ho tla tšohloa eng?
- Ke karolo e sebelisitsoeng feela mabapi le nts’etsopele.
- Tsebo ea sebele le phihlelo, tse bohlokoa haholo ho sebetsa le lisebelisoa tsa lichelete.
- Kakaretso ea litaba tse lokelang ho sebetsoa
Kahoo, ke batla ho bala lipalo-palo tsa khoebo le ho e etsa ka tsela e bonolo.
Ho theha ts’ebeletso ea lipalo-palo mohato ka mohato:
- Khokahano ho Tinkoff Invest API
- Ho hula lintlha ho tsoa ho Tinkoff Invest API ho sebatli
- Ho fumana litlaleho tsa brokerage le litšebelisano
- Palo le tlhahiso ea litaba tse khahlang
- Liqeto le merero ea bokamoso
Khokahano ho Tinkoff Invest API
Ho hokahanya le API, o ka nka sdk leha e le efe ho tsoa litokomaneng https://github.com/Tinkoff/investAPI#sdk . Kapa sephutheloana sa npm ` tinkoff-sdk-grpc-js `. Ho bohlokoa hore sephutheloana se nchafatsoe ho mofuta oa morao-rao ke bahlahisi. Kenya
npm ke tinkoff-sdk-grpc-js
Ho hlahloba
const { createSdk } = hloka(‘tinkoff-sdk-grpc-js’); // Letšoao le ka fumanoang joalo ka const TOKEN = ‘YOURAPI’; // Lebitso la kopo eo u ka fumanoang ka eona ho li-logs tsa TCS. const appName = ‘tcsstat’; const sdk = createSdk(TOKEN, appName); (async () => { console.log(await sdk.users.getAccounts()); })();
Sephetho: lethathamo la li-account tsa hau le tla hlahisoa ka har’a console. Ka mohlala, a re hlahlobeng li-nuances:
- Lethathamong la li-account ho na le “Banka ea Matsete”, eo u ke keng ua sebetsa le eona u sebelisa API
- Ka kopo hlokomela hore masimo a tla ka camelCase, ha litokomaneng tsena masimo ana a hlahisoa ka under_score.
- Ho tla ba joalo hohle, kahoo u ke ke ua nka le ho kopitsa tšimo ho tsoa litokomaneng.
E na le thuso:
- U ka fumana khoutu ena lekaleng la morero
https://github.com/pskucherov/tcsstat/tree/step1 https://github.com/pskucherov/tcsstat/compare/step1
Ho hula lintlha ho tsoa ho Tinkoff Invest API ho sebatli
Ke nkile tse latelang.js le socket.io. Sena ha se khothaletso e matla, khetha ka boikhethelo ba hau.
npx create-next-app@latest npm ke socket.io socket.io-client
Hang-hang re fetela mohatong oa setsoalle o latelang+socket+investapi, ‘me u bone karolo e Molemo ea mohato ona bakeng sa lintlha tsohle. Ke tla hlalosa lintlha:
- Ka lehlakoreng la nodejs (server), ho na le faele ea maqephe/api/investapi.js. Mona ke moo re thehang seva sa socket.io ebe re hokela ho investapi.
- Ka lehlakoreng la sebatli (moreki), re hokahanya le seva ka sokete ebe re kopa data ea akhaonto ho tsoa ho morekisi.
- Re fumana data ho tsoa ho morekisi ho seva, ebe re e romella ho moreki. Ha li amoheloa ho sebatli, li hlahisoa ho sebatli.
Sephetho: ho sebatli console re ka bona tlhahisoleseling mabapi le li-account. Ke hore, mohato oa ho qetela, re bone tlhahisoleseding e mabapi le li-account ho console ea seva (nodejs), mohato oa hona joale, re fetisitse tlhahisoleseding ena ho mofani (sebatli).
Joale a re e etseng e le hore u ka khetha ak’haonte ho tsoa ho sebatli, ‘me haeba ho se na letšoao, phoso e romelloa ho console. Mosebetsi o bonolo ebile ha ho letho le lecha, kahoo ke fana ka lihokelo tsa boitlamo feela
- https://github.com/pskucherov/tcsstat/commit/7e1ac57061e5e971588479015b06d8814d6609a9
- https://github.com/pskucherov/tcsstat/commit/b28ac973a57494f5232589b4cb6b9fb13b8af759
E na le thuso:
- Mokhoa oa ho etsa metsoalle e latelang le socket e hlalositsoe ka ho qaqileng mona .
- Khoutu ea setsoalle e latelang+socket+investapi:
https://github.com/pskucherov/tcsstat/commit/a443a4ac1bb4f0aa898f638128755fe7391ee381 Ho bao tse ka holimo li leng thata, joale re lula sethaleng sena mme re sebetsana le khoutu. Haeba u na le lipotso – botsa. https://github.com/pskucherov/tcsstat/tree/step2 https://github.com/pskucherov/tcsstat/compare/step1…step2
Ho fumana litlaleho tsa brokerage le litšebelisano
Ho na le mekhoa e meraro ea ho fumana litlaleho tsa barekisi le litšebelisano
Ho tloha qalong ho bohlokoa ho tseba:
- Tlaleho ea ho rekisa e hlahisoa ka mokhoa oa T-3, i.e. trades li bonts’oa moo ka mor’a ts’ebetso ea tsona ea sebele.
- Ka hona, haeba u kopa tlaleho ena matsatsing a mabeli a ho qetela, e tla be e lokile ka mor’a matsatsi a mararo.
- Ho fumana transaction bakeng sa matsatsi a ho qetela, re sebelisa mokhoa oa ho amohela transactions, empa hopola hore id le litaba tsa bona li ka fetoha kamora hore tlaleho ea broker e hlahisoe.
GetBrokerReport
Ho fumana tlaleho ea brokerage, o hloka ho nka id ea akhaonto, letsatsi la ho qala le letsatsi la ho qetela la tlaleho, empa eseng ho feta matsatsi a 31. Re romela kopo ea ho hlahisa tlaleho ho API ka generate _broker_report_request , fumana taskId ka karabo. Kamora moo, re sebelisa taskId ena, re fumana data ho tsoa ho fumana _broker_report_response.
- U hloka ho boloka TaskID ka ho sa feleng bakeng sa matsatsi ana.
- Kaha ha u ka lahleheloa ke eona, joale bakeng sa matsatsi a kōpiloeng tlaleho e tla qala ka ho arabela kopo ea moloko,
- Mme ebe e ke ke ya tla ho hang.
Mokhoa oa ho fumana letsatsi, ho nahanoa ka ho tlosa ho tloha letsatsing la hona joale
const getDateSubDay = (subDay = 5, qala = nnete) => { const date = Letsatsi le lecha (); date.setUTCDate(date.getUTCDate() – subDay); haeba (qala) { date.setUTCHours(0, 0, 0, 0); } tse ling { date.setUTCHours(23, 59, 59, 999); } letsatsi la ho khutla; };
Tlaleho ea kopo ea tlhahiso
const brokerReport = emetse (sdk.operations.getBrokerReport)({ generateBrokerReportRequest: { accountId, from, to, }, });
Sephetho:
- Ka lebaka la ts’ebetso ea pele ea taelo, re fumana taskId.
- Tlaleho e qala ho hlahisoa ka lehlakoreng la broker. Ha e se e lokile ha e tsejoe, rea ema ebe nako le nako re hula taskId ka tebello ea tlaleho.
- Hobaneng? Hobane haeba tlaleho e sa itokisetsa, e lahlela phoso. Haeba tlaleho e so lokele ka lehlakoreng la broker, joale sena ke phoso khoutu ea hau. Ka kopo, sebetsa: 30058|INVALID_ARGUMENT|mosebetsi ha o so phethehe, ka kopo leka hape kamoso
Khoutu ea ho emela le ho amohela tlaleho e shebahala tjena.
const timer = async time => { khutlisa Tšepiso e ncha(resolve => setTimeout(rarolla, nako)); } const getBrokerResponseByTaskId = async (taskId, page = 0) => { leka { khutlela u emetse (sdk.operations.getBrokerReport)({ getBrokerReportRequest: { taskId, page, }, }); } tšoasa (e) { console.log(‘wait’, e); leta nako (10000); khutla u emetse getBrokerResponseByTaskId(taskId, leqephe); } };
Joale ho etsahala boselamose bo tšoanang. Re emisa sengoloa sa rona, re se qale hape, ha re na taskId. Re kenya khoutu ka kopo ea taskId, empa ha re sa fumana taskId, empa hang-hang re tlaleha. Boselamose! ‘Me ntho e’ ngoe le e ‘ngoe e ne e tla loka haeba e ne e lula e le tjena. Empa ka khoeli ho ke ke ha e-ba le data ho hang. E na le thuso :
https://github.com/pskucherov/tcsstat/tree/step3.1 https://github.com/pskucherov/tcsstat/compare/step3.1
- Haeba motho a kopana le sena, o amohelehile tabeng ena . Ka mor’a hore ba lokise boselamose bona, bo tla lahleheloa ke matla ‘me bo fapane ka tsela e itseng. Empa hajoale (03/21/2023) e sebetsa joalo feela.
GetDividendsForeignIssuer
Motho e mong a ka ‘na a nahana hore mokhoa ona o tšoana le o fetileng mme o ka sebelisa mokhoa o le mong oo ka oona o fetolang lebitso la ts’ebetso feela. Empa ha baa ka ba hakanya! Ho reha lebitso moo ho fapane haholo ka mekhoa le tlhahisoleseling e khutlisitsoeng. ‘Me palo ea maqephe e qala ho tloha ho 0, ebe ho tloha ho 1. E le hore u se ke ua ferekanngoa ho sena sohle, ho bonolo ho ngola mekhoa e ‘meli e fapaneng. E leng ntho e makatsang, hobane monahano oa mosebetsi o tšoana. Ke ile ka tšoela mathe nako e telele ha ke leka ho etsa mokhoa o le mong mme ho ne ho e-na le khoutu e fokolang. Ho ke ke ha ba le mehlala mona.
GetOperationsByCursor
Ntho eo ke e ratang ho tse tharo. Le hoja e se e nepahetseng ka ho fetisisa, empa e lekaneng ka ho fetisisa. Re etsa kopo ho tloha qalong ea ho theha ak’haonte ho fihlela ka nako eo ho ka khonehang (ho koala ak’haonte kapa ea hajoale). Re fumana karabo, re nka sekhechana ebe re kopa hape ha feela data e ntse e le teng. ‘Me khoutu e khuts’oane ho feta mehlala e ka holimo.
const timer = async time => { khutlisa Tšepiso e ncha(resolve => setTimeout(rarolla, nako)); } const getOperationsByCursor = async (sdk, accountId, ho tloha, ho, cursor = ”) => { leka { const reqData = { accountId, ho tloha, ho, ho isa moeli: 1000, state: sdk.OperationState.OPERATION_STATE_EXECUTED, withoutCommissions: false, withoutTrades: bohata, ntle leOvernights: bohata, cursor, }; kgutla o emetse sdk.operations.getOperationsByCursor(reqData); } tšoasa (e) { wait timer(60000); return await getOperationsByCursor(sdk, accountId, from, to, cursor = ”); } };
Moralo o lokelang ho etsoa o mona: https://github.com/pskucherov/tcsstat/tree/step3.3 https://github.com/pskucherov/tcsstat/compare/step3.3 Joale re se re itokiselitse ho eketsa ts’ebetso ea ho amohela ho kopo ea rona. Haeba e entsoe ka nepo, joale o hloka ho fumana litlaleho tsa brokerage bakeng sa boteng bohle ba akhaonto. ‘Me bakeng sa lintlha tse sieo, li-T-3 tse tšoanang, li kenya hape ho tsoa lits’ebetsong. Empa sena se ka aroloa ka sengoloa se arohaneng. Har’a li-nuances tsa mantlha tseo u tla kopana le tsona ke ho ts’oara ts’ebetso le tlaleho ea barekisi.
- Haeba kajeno u fumane tlaleho ea brokerage le litšebelisano bakeng sa matsatsi a hlokahalang, li behe tsohle ho database, joale ha ho na mathata.
- U tla ba le mathata hosane ha u fumana karolo e latelang ea data ho tsoa tlalehong le ts’ebetsong ‘me u nka qeto ea ho li hokahanya le database e teng.
- Ho na le li-nuances tse ngata mabapi le ho se lumellane kapa ho fetola id kamora ho sebetsa
- Ebe bakeng sa ‘maraka oa OTC, li-id ha li lumellane ho hang.
- Hape le li-nuances tsa lisebelisoa tsa synchronizing, tse sa lumellaneng hape, ka lebaka la likarolo tse ikhethang tsa API. Empa eo ke pale e nngwe.
Ha re kenyelleng ho fumana leseli mabapi le ts’ebetso ts’ebelisong ea rona. Potso ea mantlha e tla ba moo data e tla sebetsoa le ho bolokoa teng.
- Haeba u iketsetsa eona, u tla sebelisa data e tšoanang ho lisebelisoa tse fapaneng. Ebe o hloka ho sebetsa le ho boloka data ho seva.
- Haeba u na le lintlha tse ngata tse fapaneng tse sebelisoang ke basebelisi ba bangata ba fapaneng, joale u lokela ho etsa qeto ea hore na ke eng ea bohlokoa haholo: lebelo la basebelisi kapa ho boloka tšepe ka lehlakoreng la hau. Mang kapa mang ea ka khonang ho reka thepa e ngata e sa lekanyetsoang o bala ntho e ‘ngoe le e’ ngoe ho seva sa hae ‘me o etsa hore e be lebelo le leholo bakeng sa basebelisi, ho boloka lisebelisoa tsa mosebedisi, tse kang betri le sephethephethe, e leng sa bohlokoa haholo ho lifono.
Ka lehlakoreng le leng, ho bala ho sebatli ha se tharollo e nepahetseng ka ho fetesisa. Ka hona, ke eng e sa theko e boima, re e nka ho seva sa rona. Re tlohela tse ling ho moreki. Ke hlile ke batla ho nka le ho bala khomishene ho seva. Empa mona ho tla nuance e bitsoang “interactivity”. Ha re re u na le liopereishene tse likete ‘me ho nka metsotso e mehlano ho li amohela. Mosebelisi o tla ba le eng ka nako ee? Spinner? Tsoelo-pele? Infa mabapi le hore na e kentsoe bokae? Ho loketse ho sebelisa “ho leta ka mafolofolo” ha mosebelisi ea ts’ebetsong a se a ntse a bona ho hong. Sephetho ke sena :
- Ho kenya leqephe
- Li-invoice tsohle lia koptjoa
- Ka mor’a moo, litšebelisano tsohle tse nang le li-commissions bakeng sa litšebelisano tse entsoeng li kopuoa bakeng sa litlaleho tsohle. Ha data e amoheloa, e fanoa ho sebatli.
E le hore re se ke ra sefa datha liketsahalong nako le nako, re hula ketsahalo ea rona bakeng sa ak’haonte ka ‘ngoe. Rata sena:
socket.emit(‘sdk:getOperationsCommissionResult_’ + accountId, { lintho: data?.items, inProgress: Boolean(nextCursor), });
Moralo oa ho qala o mona: https://github.com/pskucherov/tcsstat/tree/step3 https://github.com/pskucherov/tcsstat/compare/step2…step3 Moving on. Ho monate hore ebe u balile mola ona!
Palo le tlhahiso ea litaba tse khahlang
Ho itšetlehile ka hore na ke mang ea hlokang boitsebiso bofe. Ka hona, hang-hang ke u joetsa li-nuances tsa mantlha tseo u tla kopana le tsona.
Ho sebetsa ka litheko
E mong le e mong ea sebetsang ka lichelete oa tseba hore litšebelisano tsa chelete li lokela ho etsoa feela ka linomoro tse feletseng. Ka lebaka la ho se nepahale ha boleng ka mor’a ntlha ea decimal le phoso e ntseng e eketseha ka palo e kholo ea ts’ebetso. Ke ka lebaka leo litheko tsohle li hlahisoang ka mokhoa o latelang oa MoneyValue
lebala | mofuta | Tlhaloso |
---|---|---|
chelete | khoele | Khoele ea chelete ea ISO |
diyuniti | int64 | Karolo e felletseng ea kakaretso, e ka ba nomoro e mpe |
nano | int32 | Karolo ea fractional ea chelete, e ka ba palo e mpe |
Re li sebetsa ka thoko, ebe re li tlisa boleng ba theko:
qotso.liyuniti + quotation.nano / 1e9
Litsenyehelo tsa likonteraka tsa bokamoso
Theko ea bokamoso e hlahisoa ka lintlha, ha u e-na le bokamoso ba chelete, u lokela ho tseba tekanyo. ‘Me ehlile theko ka lintlha le mohato oa theko. Ha u bala phaello ho tsoa litšebelisanong, sena se ka thunya, hobane. haeba u bala kakaretso ea chelete ka ho atisa theko ka bongata. Mona u lokela ho ba hlokolosi. Hajoale, re tla bona hore na e tsamaea joang. Sena se sebetsa ho bokamoso ba lichelete, libakeng tse ling tsohle li lokile ka sena.
OTC marakeng
‘Maraka ona o na le lintho tse ngata tse ikhethang, ka hona , a re ke re ithuteng ts’ebetso ho eona ka thoko. Ha o qala ho lumellana le sena le tlaleho ea ho rekisa, ho tla hlaha hore tradeID ea transaction e tšoanang e na le mangolo qalong ea litšebelisano ‘me ha li tlalehong ea likoloto. Ka hona, li ke ke tsa bapisoa … ahem-ahem … ka papiso! Ke bapisa nako ea khoebo, ticker le ho bapisa hore tradeId e teng ho e ‘ngoe. Ho lokile, ha ke tsebe. Mang kapa mang ea kopanang le sena le ea e tsotellang, tla tabeng kapa qala e ncha.
Ts’ebetso ea lipalo ho lisebelisoa
Ha ho khonehe, ntle le ho sheba, ho etsa ts’ebetso ea lipalo ka lenane lohle. E le hore re se ke ra eketsa mofuthu ho bonolo, re lula re hlahloba chelete le ts’ebetso feela haeba re na le bonnete ba hore chelete e lumellana, ‘me lintlha li fetoleloa ho chelete e lakatsehang. Re hlometse ka tsebo ea ho sebetsa ka linomoro tsa banka, re tla bala komisi e sebelisitsoeng ho e ‘ngoe le e’ ngoe ea li-account. Joalo ka sena: https://github.com/pskucherov/tcsstat/tree/step4 https://github.com/pskucherov/tcsstat/compare/step3…step4
Microservice e lokile!
https://github.com/pskucherov/tcsstat Joaloka mosebetsi oa sekolo o etsetsoang hae, o ka hlahloba hore na tšebeletso e sebetsa ka khokahanyo e liehang, ha likhokahano li robehile, ha Inthanete e khaotsoe, ha liphoso kapa meeli e felile ka lehlakoreng la broker.
Liqeto le merero ea bokamoso
- O ithutile ka lits’ebetso tsa mantlha le ho sebetsa le Invest API
- Nako e sebelisitsoeng ~ lihora tse 10
- Boemo ba boima ~ junior+ / tlase bohareng
Haeba u tsoela pele ho hloekisa microservice, u ka qetella u e-na le ntho e kang ena
https://opexbot.info
Ena ke tsoelo-pele ea ka, bakeng sa ba botsoa haholo ho utloisisa, ho matha le ho itšepa ka bobona. Ke rera ho eketsa analytics moo ka kopo ea basebelisi. Haeba u ratile sengoloa, joale ingolise ho mocha oa ka oa thelekramo .
Полезная статья. Не могу представить, сколько усилий автора потребовалось, чтобы все описать. Благодарю.