Izinto ezikhuthaza ukuthuthukiswa kwensizakalo yezibalo ze-Tinkoff Investments kube:
- i-athikili ngo-Habré “Okushiwo yi-Tinkoff Investments”
- ukuhlaziywa kwezifiso zabasebenzisi benkundla
- indatshana emayelana nokubalwa kwamakhomishini .
- Kuzoxoxwa ngani?
- Ukuthuthukisa isevisi yezibalo isinyathelo nesinyathelo:
- Ukuxhumeka ku-Tinkoff Invest API
- Ukudweba idatha kusuka ku-Tinkoff Invest API kusiphequluli
- Ukuthola imibiko ye-brokerage kanye nokuthengiselana
- I-GetBrokerReport
- Indlela yokuthola idethi, kucatshangelwa ukususa kusukela osukwini lwamanje
- Bika isicelo sokukhiqiza
- Umphumela:
- I-GetDividendsForeignIssuer
- GetOperationsByCursor
- Ukubalwa nokuphuma kolwazi lwentshisekelo
- Ukusebenza ngamanani
- Izindleko zezinkontileka zesikhathi esizayo
- Imakethe ye-OTC
- Imisebenzi yezibalo kumathuluzi
- I-Microservice isilungile!
- Iziphetho nezinhlelo zekusasa
- https://opexbot.info
Kuzoxoxwa ngani?
- Ingxenye esetshenzisiwe kuphela mayelana nentuthuko.
- Ulwazi lwangempela nolwazi, olubaluleke kakhulu ekusebenzeni ngamathuluzi ezezimali.
- Uhlolojikelele lwezinkinga okumele kusetshenzwe kuzo
Ngakho-ke, ngifuna ukubala izibalo zokuhweba futhi ngikwenze ngendlela elula.
Ukuthuthukisa isevisi yezibalo isinyathelo nesinyathelo:
- Ukuxhumeka ku-Tinkoff Invest API
- Ukudweba idatha kusuka ku-Tinkoff Invest API kusiphequluli
- Ukuthola imibiko ye-brokerage kanye nokuthengiselana
- Ukubalwa nokuphuma kolwazi lwentshisekelo
- Iziphetho nezinhlelo zekusasa
Ukuxhumeka ku-Tinkoff Invest API
Ukuze uxhume ku-API, ungathatha noma iyiphi i-sdk kumadokhumenti okuthi https://github.com/Tinkoff/investAPI#sdk . Noma iphakheji ye-npm ` tinkoff-sdk-grpc-js` . Kubalulekile ukuthi iphakheji ibuyekezelwe enguqulweni yakamuva ngabathuthukisi. Faka
npm i tinkoff-sdk-grpc-js
Iyahlola
const { createSdk } = need(‘tinkoff-sdk-grpc-js’); // Ithokheni engatholakala njengale const TOKEN = ‘YOURAPI’; // Igama lohlelo lokusebenza ongatholakala ngalo kumalogi we-TCS. const appName = ‘tcsstat’; const sdk = createSdk(TOKEN, appName); (async () => { console.log(await sdk.users.getAccounts()); })();
Umphumela: uhlu lwama-akhawunti akho luzoboniswa kukhonsoli. Ngokwesibonelo, ake sihlaziye ama-nuances:
- Ohlwini lwama-akhawunti kukhona “ibhange lokutshala izimali”, ongeke ukwazi ukusebenza nalo usebenzisa i-API
- Sicela uqaphele ukuthi amasimu angena ngekamela, kuyilapho emibhalweni lezi zindawo zethulwe ngaphansi_kwesilinganiso.
- Kuzoba kanje yonke indawo, ngakho awukwazi nje ukuthatha futhi ukopishe inkambu kumadokhumenti.
Iwusizo:
- Ungathola le khodi egatsheni lephrojekthi
https://github.com/pskucherov/tcsstat/tree/step1 https://github.com/pskucherov/tcsstat/compare/step1
Ukudweba idatha kusuka ku-Tinkoff Invest API kusiphequluli
Ngithathe okulandelayo.js kanye ne-socket.io. Lesi akusona isincomo esinamandla, khetha ngokubona kwakho.
npx create-next-app@latest npm i socket.io socket.io-client
Ngokushesha siqhubekela esinyathelweni sobungani next+socket+investapi, futhi sibone isigaba Esiwusizo salesi sinyathelo ukuze uthole yonke imininingwane. Ngizochaza imininingwane:
- Ohlangothini lwe-nodejs (server), kukhona ifayela lamakhasi/api/investapi.js. Yilapho sakha khona iseva ye-socket.io futhi sixhume ku-investapi.
- Ohlangothini lwesiphequluli (iklayenti), sixhuma kuseva ngesokhethi futhi sicele idatha ye-akhawunti kumthengisi.
- Sithola idatha evela kumdayisi osesiphakelini, bese siyithumela kuklayenti. Uma zamukelwe kuklayenti, ziyavezwa esipheqululini.
Umphumela: kukhonsoli yesiphequluli singabona ulwazi mayelana nama-akhawunti. Okusho ukuthi, esinyathelweni sokugcina, sibone ulwazi mayelana nama-akhawunti kukhonsoli yeseva (ama-nodejs), esinyathelweni samanje, sidlulisele lolu lwazi kuklayenti (isiphequluli).
Manje ake sikwenze ukuze ukwazi ukukhetha i-akhawunti kusuka kusiphequluli, futhi uma kungekho ithokheni, iphutha lithunyelwa ku-console. Umsebenzi ulula futhi akukho okusha, ngakho nginikeza izixhumanisi zokuzibophezela kuphela
- https://github.com/pskucherov/tcsstat/commit/7e1ac57061e5e971588479015b06d8814d6609a9
- https://github.com/pskucherov/tcsstat/commit/b28ac973a57494f5232589b4cb6b9fb13b8af759
Iwusizo:
- Indlela yokwenza abangane ngokulandelayo kanye nesokhethi kuchazwe ngokuningiliziwe lapha .
- Ikhodi yobungane next+socket+investapi:
https://github.com/pskucherov/tcsstat/commit/a443a4ac1bb4f0aa898f638128755fe7391ee381 Okunzima kubo okungenhla, khona-ke sihlala kulesi sigaba futhi sibhekane nekhodi. Uma unemibuzo – buza. https://github.com/pskucherov/tcsstat/tree/step2 https://github.com/pskucherov/tcsstat/compare/step1…step2
Ukuthola imibiko ye-brokerage kanye nokuthengiselana
Kunezindlela ezintathu zokuthola imibiko ye-brokerage kanye nokuthengiselana
Kusukela ekuqaleni kubalulekile ukwazi:
- Umbiko we-brokerage ukhiqizwa kumodi ye-T-3, i.e. ukuhweba kuboniswa lapho ngemva kokubulawa kwawo kwangempela.
- Ngokufanelekile, uma ucela lo mbiko ezinsukwini ezimbili zokugcina, uzobe usulungile ezinsukwini ezintathu.
- Ukuze senze amadili ezinsuku zokugcina, sisebenzisa indlela yokuthola imisebenzi, kodwa khumbula ukuthi i-id yabo nokuqukethwe kungase kushintshe ngemva kokwakhiwa kombiko womthengisi.
I-GetBrokerReport
Ukuze uthole umbiko we-brokerage, udinga ukuthatha i-id ye-akhawunti, idethi yokuqala nosuku lokugcina lombiko, kodwa kungabi ngaphezu kwezinsuku ezingu-31. Sithumela isicelo sokukhiqiza umbiko ku-API ngokwenza _broker_report_request , sithole impendulo ye-TaskId. Ngemva kwalokho, sisebenzisa le-taskId, sithola idatha ku- get _broker_report_response.
- Udinga ukulondoloza i-TaskID ingunaphakade njengalezi zinsuku.
- Njengoba uma ulahlekelwa yiyo, ngezinsuku eziceliwe umbiko uzofika kuqala ngokuphendula isicelo sokukhiqiza,
- Futhi-ke ngeke ifike nhlobo.
Indlela yokuthola idethi, kucatshangelwa ukususa kusukela osukwini lwamanje
const getDateSubDay = (subDay = 5, start = true) => { const date = new Date(); date.setUTCDate(date.getUTCDate() – subDay); uma (ukuqala) { date.setUTCHours(0, 0, 0, 0); } okunye { date.setUTCHours(23, 59, 59, 999); } usuku lokubuya; };
Bika isicelo sokukhiqiza
const brokerReport = await (sdk.operations.getBrokerReport)({ generateBrokerReportRequest: { accountId, from, to, }, });
Umphumela:
- Njengomphumela wokwenziwa kokuqala komyalo, sithola i-taskId.
- Umbiko uqala ukukhiqizwa ngasohlangothini lomdayisi. Uma isilungile akwaziwa, siyalinda futhi ngezikhathi ezithile sidonse i-TaskId silindele umbiko.
- Kungani? Ngoba uma umbiko ungakalungi, uphonsa iphutha. Uma umbiko ungakalungi ngasohlangothini lomdayisi, kusho ukuthi leli iphutha kukhodi yakho. Sicela ucubungule: 30058|INVALID_ARGUMENT|umsebenzi ongakaqedwa, sicela uzame futhi ngemva kwesikhathi.
Ikhodi yokulinda nokwamukela umbiko ibukeka kanje.
const timer = isikhathi esingavumelani => { buyisela Isithembiso esisha(xazulula => setTimeout(xazulula, isikhathi)); } const getBrokerResponseByTaskId = async (taskId, page = 0) => { zama { return wait (sdk.operations.getBrokerReport)({ getBrokerReportRequest: { taskId, page, }, }); } bamba (e) { console.log(‘wait’, e); isikhathi sokulinda (10000); buyisa ulinde getBrokerResponseByTaskId(taskId, page); } };
Bese kwenzeka umlingo ofanayo. Simisa umbhalo wethu, siqale futhi, asinayo i-taskId. Senza ikhodi ngesicelo se-TaskId, kodwa asisatholi i-TaskId, kodwa ngokushesha umbiko. Umlingo! Futhi konke bekuyoba kuhle uma kuhlale kunje. Kodwa ngenyanga ngeke ibe khona nhlobo idatha. Iwusizo :
- Ithiyori encane ichazwe lapha nalapha .
- Ukuhlanganisa ikhodi ndawonye, okusalungiswa kuzobukeka kanje.
https://github.com/pskucherov/tcsstat/tree/step3.1 https://github.com/pskucherov/tcsstat/compare/step3.1
- Uma othile ehlangabezana nalokhu, wamukelekile odabeni . Ngemva kokulungisa lo mlingo, uzolahlekelwa amandla futhi uzohluka ngandlela-thile. Kepha okwamanje (03/21/2023) isebenza kanjalo nje.
I-GetDividendsForeignIssuer
Omunye angase acabange ukuthi indlela iyafana neyangaphambili futhi ungasebenzisa indlela eyodwa lapho ushintsha kuphela igama lemisebenzi. Kodwa abazange baqagele! Ukuqamba lapho kuhluke kakhulu ezindleleni nasolwazini olubuyisiwe. Futhi isibalo samakhasi siqala ku-0, bese sisuka ku-1. Ukuze ungadideki kukho konke lokhu, kulula ukubhala izindlela ezimbili ezihlukene. Okuyinqaba, ngoba umqondo womsebenzi uyafana. Ngakhafula isikhathi eside lapho ngizama ukwenza indlela eyodwa futhi kwakukhona ikhodi encane. Ngeke kube nezibonelo lapha.
GetOperationsByCursor
Engikuthandayo kwabathathu. Nakuba kungeyona enembile kakhulu, kodwa eyanele kakhulu. Senza isicelo kusukela ekuqaleni kokudala i-akhawunti kuze kube yidethi enkulu esingenzeka (ukuvala i-akhawunti noma ekhona manje). Sithola impendulo, sithathe ikhesa futhi sicele kabusha inqobo nje uma kunedatha. Futhi ikhodi imfushane kakhulu kunezibonelo ezingenhla.
const timer = isikhathi esingavumelani => { buyisela Isithembiso esisha(xazulula => setTimeout(xazulula, isikhathi)); } const getOperationsByCursor = async (sdk, accountId, from, to, cursor = ”) => { zama { const reqData = { accountId, ukusuka, ukuya, umkhawulo: 1000, state: sdk.OperationState.OPERATION_STATE_EXECUTED, withoutCommissions: false, withoutTrades: amanga, ngaphandle kobusuku obubodwa: amanga, ikhesa, }; buyisela ulinde sdk.operations.getOperationsByCursor(reqData); } bamba (e) { wait timer(60000); return wait getOperationsByCursor(sdk, accountId, from, to, cursor = ”); } };
Okusalungiswa okufanele kusetshenziswe lapha: https://github.com/pskucherov/tcsstat/tree/step3.3 https://github.com/pskucherov/tcsstat/compare/step3.3 Manje sesilungele ukwengeza imisebenzi yokwamukela ku isicelo sethu. Uma kwenziwa kahle, kuzomele uthole imibiko ye-brokerage yabo bonke ubukhona be-akhawunti. Futhi ngedatha elahlekile, lawo ma-T-3 afanayo, layisha kabusha kusukela ekusebenzeni. Kodwa lokhu kungahlukaniswa ku-athikili ehlukile. Kuma-nuances ayinhloko ozohlangana nawo ukunamathisela ukusebenza kanye nombiko we-brokerage.
- Uma namuhla uthole umbiko we-brokerage kanye nokuthengiselana ngezinsuku ezidingekayo, faka konke ku-database, ngakho-ke azikho izinkinga.
- Uzoba nezinkinga kusasa lapho uthola ingxenye elandelayo yedatha evela embikweni kanye nemisebenzi futhi unquma ukuyivumelanisa nesizindalwazi esikhona.
- Ama-nuances amaningi mayelana nokungafani noma ukushintsha i-id ngemva kokucubungula
- Bese kuthi emakethe ye-OTC, ama-id awafani nhlobo.
- Kanye nama-nuances wamathuluzi okuvumelanisa, angaphinde ahambisane, ngenxa yezimpawu ze-API. Kodwa leyo ngenye indaba.
Masingeze ukuthola ulwazi mayelana nokusebenza kuhlelo lwethu lokusebenza. Umbuzo omkhulu uzoba lapho idatha izocutshungulwa futhi igcinwe khona.
- Uma uzenzela wena, uzosebenzisa idatha efanayo kumadivayisi ahlukene. Bese udinga ukucubungula nokugcina idatha kuseva.
- Uma unedatha eminingi ehlukene esetshenziswa abasebenzisi abaningi abahlukene, kuzomele unqume ukuthi yini ebaluleke kakhulu: ijubane labasebenzisi noma ukonga insimbi ohlangothini lwakho. Noma ubani ongakwazi ukukhokhela inani elingenamkhawulo lehadiwe ubala yonke into ekuseva yakhe futhi ayenze isheshe kakhulu kubasebenzisi, ilondoloza izinsiza zomsebenzisi, njengebhethri nethrafikhi, okubaluleke kakhulu kumafoni.
Ngokulandelayo, ukubala esipheqululini akusona isixazululo esingcono kakhulu ngokwesimiso. Ngakho-ke, yini engabizi, siyibheka kuseva yethu. Okusele sikushiyela iklayenti. Ngifuna ngempela ukuthatha futhi ngibale ikhomishana kuseva. Kodwa lapha kufika i-nuance ebizwa ngokuthi “ukusebenzelana”. Ake sithi unezinkulungwane zemisebenzi futhi kuthatha imizuzu emihlanu ukuyithola. Umsebenzisi uzobe enani ngalesi sikhathi? Isipina? Intuthuko? I-Infa mayelana nokuthi kulayishwe malini? Kuhle ukusebenzisa “ukulinda okusebenzayo” lapho umsebenzisi osenqubeni esengabona okuthile. Nawu umphumela:
- Ikhasi liyalayisha
- Wonke ama-invoyisi ayacelwa
- Ngemuva kwalokho, konke ukuthengiselana ngamakhomishini okwenziwayo okwenziwe kucelwa kuwo wonke ama-akhawunti. Njengoba idatha itholwa, inikezwa kusiphequluli.
Ukuze singahlungi idatha emicimbini isikhathi ngasinye, sidonsa umcimbi wethu ku-akhawunti ngayinye. Kanje:
socket.emit(‘sdk:getOperationsCommissionResult_’ + accountId, { items: data?.items, inProgress: Boolean(nextCursor), });
Okusalungiswa okuzokwethulwa kulapha: https://github.com/pskucherov/tcsstat/tree/step3 https://github.com/pskucherov/tcsstat/compare/step2…step3 Moving on. Kuhle ukuthi ufunde lo mugqa!
Ukubalwa nokuphuma kolwazi lwentshisekelo
Kuya ngokuthi ubani odinga luphi ulwazi. Ngakho-ke, ngokushesha ngikutshela ama-nuances ayinhloko ozohlangana nawo.
Ukusebenza ngamanani
Wonke umuntu osebenza ngezezimali uyazi ukuthi ukuthengiselana ngemali kufanele kwenziwe kuphela ngezinombolo eziphelele. Ngenxa yokunemba kwamanani ngemva kwephoyinti ledesimali kanye nephutha lokuqongelela ngenani elikhulu lemisebenzi. Yingakho wonke amanani ethulwa ngendlela elandelayo ye – MoneyValue
inkambu | uhlobo | Incazelo |
---|---|---|
imali | umucu | Ikhodi yemali ye-ISO yeyunithi yezinhlamvu |
amayunithi | int64 | Ingxenye ephelele yesamba, ingaba inombolo enegethivu |
nano | int32 | Ingxenye enani eliyingxenyana, ingaba inombolo enegethivu |
Siwacubungula ngokwehlukana, bese siwaletha enanini lentengo:
quotation.amayunithi + quotation.nano / 1e9
Izindleko zezinkontileka zesikhathi esizayo
Intengo yekusasa yethulwa ngamaphoyinti, uma unekusasa lohlobo lwemali, udinga ukwazi izinga. Futhi-ke intengo ngamaphoyinti kanye nesinyathelo samanani. Uma ubala inzuzo ekuthengiseni, lokhu kungadubula, ngoba. uma ubala inani eliphelele ngokuphindaphinda inani ngenani. Lapha udinga ukuqaphela. Okwamanje, sizobona ukuthi kuhamba kanjani. Lokhu kusebenza ekusaseni lwemali, kwezinye izindawo yonke into ilungile ngalokhu.
Imakethe ye-OTC
Le makethe inezinto eziningi ezingavamile, ngakho-ke ake sifunde ukusebenza kuyo ngokwehlukana.Uma uqala ukuvumelanisa ukusebenza, kuzovela ukuthi udinga ukuletha i-figi / ithikha ngendlela efanayo ukuze ufanise ithuluzi ngendlela efanele. Uma uqala ukuvumelanisa lokhu nombiko we-brokerage, kuzovela ukuthi i-tradeID yomsebenzi ofanayo inezinhlamvu ekuqaleni kokuthengiselana futhi azikho embikweni womthengisi. Ngakho-ke, azinakuqhathaniswa … ahem-ahem … ngokuqhathanisa! Ngifanise isikhathi sokuhweba, ithikha kanye nokufanisa leyo tradeId eyodwa equkethwe kwenye. Kulungile, angazi. Noma ubani ohlangabezana nalokhu futhi ubani onendaba nakho, woza odabeni noma uqale entsha.
Imisebenzi yezibalo kumathuluzi
Akwenzeki, ngaphandle kokubheka, ukwenza imisebenzi yezibalo ngalo lonke uhlu. Ukuze singangezi ukufudumala kokuthambile, sihlala sihlola imali futhi sicubungula kuphela uma siqiniseka ukuthi imali iyahambisana, futhi amaphuzu aguqulwa abe yimali oyifunayo. Sihlome ngolwazi mayelana nokusebenza ngezinombolo zasebhange, sizobala ikhomishini esetshenziswe ku-akhawunti ngayinye. Njengalokhu: https://github.com/pskucherov/tcsstat/tree/step4 https://github.com/pskucherov/tcsstat/compare/step3…step4
I-Microservice isilungile!
https://github.com/pskucherov/tcsstat Njengomsebenzi wesikole, ungabheka ukuthi isevisi isebenza yini ngokuxhumeka okuhamba kancane, lapho uxhumano luphukile, lapho i-intanethi inqanyuliwe, lapho amaphutha noma imikhawulo ephelelwe yisikhathi engxenyeni yomthengisi.
Iziphetho nezinhlelo zekusasa
- Ufunde mayelana nokusebenza okuyisisekelo nokusebenza ne-Invest API
- Isikhathi esichithwe ~ amahora ayi-10
- Izinga lobunzima ~ junior+ / low middle
Uma uqhubeka nokucwenga i-microservice, ungagcina usunento efana nale
https://opexbot.info
Lokhu kuyintuthuko yami, kulabo abavilapha kakhulu ukuqonda, ukugijima nokubala bodwa. Ngihlela ukungeza izibalo lapho ngesicelo sabasebenzisi. Uma usithandile lesi sihloko, bese ubhalisela isiteshi sami se-telegram .
Полезная статья. Не могу представить, сколько усилий автора потребовалось, чтобы все описать. Благодарю.